Update app.py
Browse files
app.py
CHANGED
|
@@ -35,16 +35,23 @@ def start_new_chat_session():
|
|
| 35 |
# 초기 세션 시작
|
| 36 |
start_new_chat_session()
|
| 37 |
|
| 38 |
-
def respond(
|
|
|
|
| 39 |
global chat_session
|
| 40 |
-
history.append((user_input, ""))
|
| 41 |
-
yield "", history
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
def clear_chat(chatbot):
|
| 50 |
start_new_chat_session()
|
|
@@ -52,14 +59,14 @@ def clear_chat(chatbot):
|
|
| 52 |
return []
|
| 53 |
|
| 54 |
with gr.Blocks() as demo:
|
| 55 |
-
gr.Markdown("
|
| 56 |
-
gr.Markdown("언어 치료에 대한 고민을 상담해줍니다.")
|
|
|
|
| 57 |
chatbot = gr.Chatbot(label="채팅창")
|
| 58 |
-
|
| 59 |
-
|
| 60 |
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
clear.click(clear_chat, outputs=[chatbot], queue=False)
|
| 64 |
|
| 65 |
demo.launch()
|
|
|
|
| 35 |
# 초기 세션 시작
|
| 36 |
start_new_chat_session()
|
| 37 |
|
| 38 |
+
def respond(message, chat_history):
|
| 39 |
+
"""사용자 입력에 응답하고 채팅 기록을 업데이트합니다."""
|
| 40 |
global chat_session
|
|
|
|
|
|
|
| 41 |
|
| 42 |
+
if chat_session is None:
|
| 43 |
+
start_new_chat_session()
|
| 44 |
|
| 45 |
+
chat_history.append((message, ""))
|
| 46 |
+
|
| 47 |
+
# 스트리밍 방식으로 응답 생성
|
| 48 |
+
response = chat_session.send_message(message, stream=True)
|
| 49 |
+
full_response = ""
|
| 50 |
+
for chunk in response:
|
| 51 |
+
full_response += chunk.text
|
| 52 |
+
chat_history[-1] = (message, full_response)
|
| 53 |
+
yield chat_history, # Gradio 업데이트
|
| 54 |
+
yield chat_history # 최종 업데이트
|
| 55 |
|
| 56 |
def clear_chat(chatbot):
|
| 57 |
start_new_chat_session()
|
|
|
|
| 59 |
return []
|
| 60 |
|
| 61 |
with gr.Blocks() as demo:
|
| 62 |
+
gr.Markdown("# 언어치료 전문가")
|
| 63 |
+
gr.Markdown("언어 치료에 대한 고민을 상담해줍니다.")
|
| 64 |
+
|
| 65 |
chatbot = gr.Chatbot(label="채팅창")
|
| 66 |
+
message = gr.Textbox(label="입력")
|
| 67 |
+
clear_button = gr.Button("초기화")
|
| 68 |
|
| 69 |
+
message.submit(respond, [message, chatbot], [chatbot]) # chatbot 만 업데이트
|
| 70 |
+
clear_button.click(clear_chat, outputs=[chatbot])
|
|
|
|
| 71 |
|
| 72 |
demo.launch()
|