ll7098ll commited on
Commit
1b66e80
·
verified ·
1 Parent(s): 33caf8e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -7
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
- history.append((user_input, response.text))
34
- # 답변 내용을 문자열로 받아서 한 글자씩 출력
35
- for char in response.text:
36
- yield "", history + [(user_input, response.text[:len(history[-1][1]) + 1])]
 
 
 
 
 
 
 
 
37
 
38
  with gr.Blocks() as demo:
39
- gr.Markdown("<div style='font-size: 30px; font-weight: bold;'>AI 선생님</div>")
40
  chatbot = gr.Chatbot(label="채팅창")
41
  msg = gr.Textbox(label="입력")
42
  clear = gr.Button("초기화")
43
 
44
- msg.submit(respond, [msg, chatbot], [msg, chatbot], queue=False)
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()