Update app.py
Browse files
app.py
CHANGED
|
@@ -30,18 +30,26 @@ chat_session = model.start_chat(history=[])
|
|
| 30 |
|
| 31 |
def respond(user_input, history):
|
| 32 |
response = chat_session.send_message(user_input)
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
with gr.Blocks() as demo:
|
| 39 |
-
gr.Markdown("<div style='font-size: 30px; font-weight: bold;'>
|
| 40 |
chatbot = gr.Chatbot(label="채팅창")
|
| 41 |
msg = gr.Textbox(label="입력")
|
| 42 |
clear = gr.Button("초기화")
|
| 43 |
|
| 44 |
-
msg.submit(respond, [msg, chatbot], [msg, chatbot]
|
| 45 |
clear.click(lambda: [], None, chatbot, queue=False)
|
| 46 |
|
| 47 |
-
demo.launch()
|
|
|
|
| 30 |
|
| 31 |
def respond(user_input, history):
|
| 32 |
response = chat_session.send_message(user_input)
|
| 33 |
+
text = response.text
|
| 34 |
+
history.append((user_input, ""))
|
| 35 |
+
|
| 36 |
+
# 타이핑 효과 구현
|
| 37 |
+
for i in range(1, len(text) + 1):
|
| 38 |
+
history[-1] = (user_input, text[:i])
|
| 39 |
+
time.sleep(0.5) # 타이핑 속도 조절
|
| 40 |
+
yield "", history # 입력창을 비우고 history 업데이트
|
| 41 |
+
|
| 42 |
+
# 전체 응답을 반환
|
| 43 |
+
history[-1] = (user_input, text)
|
| 44 |
+
yield "", history
|
| 45 |
|
| 46 |
with gr.Blocks() as demo:
|
| 47 |
+
gr.Markdown("<div style='font-size: 30px; font-weight: bold;'>gemini chatbot</div>")
|
| 48 |
chatbot = gr.Chatbot(label="채팅창")
|
| 49 |
msg = gr.Textbox(label="입력")
|
| 50 |
clear = gr.Button("초기화")
|
| 51 |
|
| 52 |
+
msg.submit(respond, [msg, chatbot], [msg, chatbot])
|
| 53 |
clear.click(lambda: [], None, chatbot, queue=False)
|
| 54 |
|
| 55 |
+
demo.launch()
|