Update app.py
Browse files
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 |
-
|
| 34 |
-
|
| 35 |
-
history.append((user_input, ""))
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
| 40 |
time.sleep(0.05) # 타이핑 속도 조절
|
| 41 |
-
|
| 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;'>
|
| 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("초기화")
|