ll7098ll commited on
Commit
f74a421
·
verified ·
1 Parent(s): a5b25b8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -13
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import os
 
2
  import google.generativeai as genai
3
  import gradio as gr
4
- import time
5
 
6
  genai.configure(api_key=os.environ["GEMINI_API_KEY"])
7
 
@@ -29,23 +29,22 @@ model = genai.GenerativeModel(
29
 
30
  chat_session = model.start_chat(history=[])
31
 
 
32
  def respond(user_input, history):
33
- response = chat_session.send_message(user_input)
34
- text = response.text
35
- history.append((user_input, ""))
36
 
37
- # 타이핑 효과 구현
38
- for i in range(1, len(text) + 1):
39
- history[-1] = (user_input, text[:i])
 
 
 
40
  time.sleep(0.05) # 타이핑 속도 조절
41
- yield "", history # 입력창을 비우고 history 업데이트
42
-
43
- # 전체 응답을 반환
44
- history[-1] = (user_input, text)
45
- yield "", history
46
 
47
  with gr.Blocks() as demo:
48
- gr.Markdown("<div style='font-size: 30px; font-weight: bold;'>gemini chatbot</div>")
49
  chatbot = gr.Chatbot(label="채팅창")
50
  msg = gr.Textbox(label="입력")
51
  clear = gr.Button("초기화")
 
1
  import os
2
+ import time
3
  import google.generativeai as genai
4
  import gradio as gr
 
5
 
6
  genai.configure(api_key=os.environ["GEMINI_API_KEY"])
7
 
 
29
 
30
  chat_session = model.start_chat(history=[])
31
 
32
+
33
  def respond(user_input, history):
34
+ history.append((user_input, "")) # 빈 답변으로 시작
35
+ yield "", history
 
36
 
37
+ response = chat_session.send_message(user_input)
38
+ full_response = ""
39
+ for chunk in response.text.split():
40
+ full_response += chunk + " "
41
+ history[-1] = (user_input, full_response)
42
+ yield "", history
43
  time.sleep(0.05) # 타이핑 속도 조절
44
+
 
 
 
 
45
 
46
  with gr.Blocks() as demo:
47
+ gr.Markdown("<div style='font-size: 30px; font-weight: bold;'>AI 선생님</div>")
48
  chatbot = gr.Chatbot(label="채팅창")
49
  msg = gr.Textbox(label="입력")
50
  clear = gr.Button("초기화")