Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
|
274 |
-
user_response_examples = gr.Dataset(samples=
|
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(
|
281 |
-
|
|
|
282 |
|
283 |
-
def answer(user_response, chat_history, stage_history
|
|
|
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=
|
303 |
|
304 |
def clear(user_response_examples):
|
305 |
-
|
|
|
|
|
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
|
310 |
-
msg.submit(answer, [msg, chatbot, stage_history
|
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()
|