SungBeom commited on
Commit
6869a07
โ€ข
1 Parent(s): d5950f1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -11
app.py CHANGED
@@ -270,17 +270,19 @@ with gr.Blocks(css='#chatbot .overflow-y-auto{height:750px}') as demo:
270
 
271
  chatbot = gr.Chatbot()
272
  msg = gr.Textbox(label='User input')
273
- init_examples = [["์ด๋ฒˆ ์ฃผ์— ์นœ๊ตฌ๋“ค๊ณผ ๋ชจ์ž„์ด ์žˆ๋Š”๋ฐ, ํ›Œ๋ฅญํ•œ ์™€์ธ ํ•œ ๋ณ‘์„ ์ถ”์ฒœํ•ด์ค„๋ž˜?"], ["์ž…๋ฌธ์ž์—๊ฒŒ ์ข‹์€ ์™€์ธ์„ ์ถ”์ฒœํ•ด์ค„๋ž˜?"], ["๋ณด๋ฅด๋„์™€ ๋ถ€๋ฅด๊ณ ๋‰ด ์™€์ธ์˜ ์ฐจ์ด์ ์€ ๋ญ์•ผ?"]]
274
- user_response_examples = gr.Dataset(samples=init_examples, components=[msg])
275
  stage_history = gr.Textbox(value="stage history: ", interactive=False, label='stage history')
276
  submit_btn = gr.Button("์ „์†ก")
277
- clear_btn = gr.ClearButton([msg, chatbot, stage_history, ])
278
  stage_info = gr.Textbox(value=stage_description, interactive=False, label='stage description')
279
 
280
- def load_example(example):
281
- return example[0]
 
282
 
283
- def answer(user_response, chat_history, stage_history, user_response_examples):
 
284
  chat_history = chat_history or []
285
  stage_history = stage_history or ""
286
  pre_conversation_history = ""
@@ -288,7 +290,7 @@ with gr.Blocks(css='#chatbot .overflow-y-auto{height:750px}') as demo:
288
  pre_conversation_history += f"User: {chat[0]} <END_OF_TURN>\n"
289
  pre_conversation_history += f"์ด์šฐ์„ : {chat[1]} <END_OF_TURN>\n"
290
  conversation_history = pre_conversation_history + f"User: {user_response} <END_OF_TURN>\n"
291
- stage_number = stage_analyzer_chain.run({'conversation_history': conversation_history, 'stage_history': stage_history})
292
  stage_number = stage_number[-1]
293
  stage_history += stage_number if stage_history == "stage history: " else ", " + stage_number
294
  response = agent_executor.run({'input':user_response, 'conversation_history': pre_conversation_history, 'stage_number': stage_number})
@@ -298,15 +300,18 @@ with gr.Blocks(css='#chatbot .overflow-y-auto{height:750px}') as demo:
298
  user_response_examples = []
299
  for user_response_example in user_response_chain.run({'conversation_history': conversation_history}).split('|'):
300
  user_response_examples.append([user_response_example])
 
301
 
302
- return "", chat_history, stage_history, gr.Dataset.update(samples=user_response_examples)
303
 
304
  def clear(user_response_examples):
305
- return gr.Dataset.update(samples=init_examples)
 
 
306
 
307
  clear_btn.click(fn=clear, inputs=[user_response_examples], outputs=[user_response_examples])
308
  user_response_examples.click(load_example, inputs=[user_response_examples], outputs=[msg])
309
- submit_btn.click(answer, [msg, chatbot, stage_history, user_response_examples], [msg, chatbot, stage_history, user_response_examples])
310
- msg.submit(answer, [msg, chatbot, stage_history, user_response_examples], [msg, chatbot, stage_history, user_response_examples])
311
 
312
  demo.launch()
 
270
 
271
  chatbot = gr.Chatbot()
272
  msg = gr.Textbox(label='User input')
273
+ samples = [["์ด๋ฒˆ ์ฃผ์— ์นœ๊ตฌ๋“ค๊ณผ ๋ชจ์ž„์ด ์žˆ๋Š”๋ฐ, ํ›Œ๋ฅญํ•œ ์™€์ธ ํ•œ ๋ณ‘์„ ์ถ”์ฒœํ•ด์ค„๋ž˜?"], ["์ž…๋ฌธ์ž์—๊ฒŒ ์ข‹์€ ์™€์ธ์„ ์ถ”์ฒœํ•ด์ค„๋ž˜?"], ["๋ณด๋ฅด๋„์™€ ๋ถ€๋ฅด๊ณ ๋‰ด ์™€์ธ์˜ ์ฐจ์ด์ ์€ ๋ญ์•ผ?"]]
274
+ user_response_examples = gr.Dataset(samples=samples, components=[msg], type="index")
275
  stage_history = gr.Textbox(value="stage history: ", interactive=False, label='stage history')
276
  submit_btn = gr.Button("์ „์†ก")
277
+ clear_btn = gr.ClearButton([msg, chatbot, stage_history])
278
  stage_info = gr.Textbox(value=stage_description, interactive=False, label='stage description')
279
 
280
+ def load_example(example_id):
281
+ global samples
282
+ return samples[example_id][0]
283
 
284
+ def answer(user_response, chat_history, stage_history):
285
+ global samples
286
  chat_history = chat_history or []
287
  stage_history = stage_history or ""
288
  pre_conversation_history = ""
 
290
  pre_conversation_history += f"User: {chat[0]} <END_OF_TURN>\n"
291
  pre_conversation_history += f"์ด์šฐ์„ : {chat[1]} <END_OF_TURN>\n"
292
  conversation_history = pre_conversation_history + f"User: {user_response} <END_OF_TURN>\n"
293
+ stage_number = stage_analyzer_chain.run({'conversation_history': conversation_history, 'stage_history': stage_history[1:]})
294
  stage_number = stage_number[-1]
295
  stage_history += stage_number if stage_history == "stage history: " else ", " + stage_number
296
  response = agent_executor.run({'input':user_response, 'conversation_history': pre_conversation_history, 'stage_number': stage_number})
 
300
  user_response_examples = []
301
  for user_response_example in user_response_chain.run({'conversation_history': conversation_history}).split('|'):
302
  user_response_examples.append([user_response_example])
303
+ samples = user_response_examples
304
 
305
+ return "", chat_history, stage_history, gr.Dataset.update(samples=samples)
306
 
307
  def clear(user_response_examples):
308
+ global samples
309
+ samples = [["์ด๋ฒˆ ์ฃผ์— ์นœ๊ตฌ๋“ค๊ณผ ๋ชจ์ž„์ด ์žˆ๋Š”๋ฐ, ํ›Œ๋ฅญํ•œ ์™€์ธ ํ•œ ๋ณ‘์„ ์ถ”์ฒœํ•ด์ค„๋ž˜?"], ["์ž…๋ฌธ์ž์—๊ฒŒ ์ข‹์€ ์™€์ธ์„ ์ถ”์ฒœํ•ด์ค„๋ž˜?"], ["๋ณด๋ฅด๋„์™€ ๋ถ€๋ฅด๊ณ ๋‰ด ์™€์ธ์˜ ์ฐจ์ด์ ์€ ๋ญ์•ผ?"]]
310
+ return gr.Dataset.update(samples=samples)
311
 
312
  clear_btn.click(fn=clear, inputs=[user_response_examples], outputs=[user_response_examples])
313
  user_response_examples.click(load_example, inputs=[user_response_examples], outputs=[msg])
314
+ submit_btn.click(answer, [msg, chatbot, stage_history], [msg, chatbot, stage_history, user_response_examples])
315
+ msg.submit(answer, [msg, chatbot, stage_history], [msg, chatbot, stage_history, user_response_examples])
316
 
317
  demo.launch()