ll7098ll commited on
Commit
217a78d
·
verified ·
1 Parent(s): 3fce2c2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -19
app.py CHANGED
@@ -4,6 +4,7 @@ import gradio as gr
4
 
5
  genai.configure(api_key=os.environ["GEMINI_API_KEY"])
6
 
 
7
  generation_config = {
8
  "temperature": 1,
9
  "top_p": 0.95,
@@ -27,23 +28,18 @@ model = genai.GenerativeModel(
27
 
28
  chat_session = model.start_chat(history=[])
29
 
30
- def chatbot(message, history):
31
- """
32
- 챗봇과의 대화를 처리하는 함수
33
- """
34
- global chat_session
35
-
36
- # 새로운 메시지가 입력되면 챗봇에 전달
37
- response = chat_session.send(message)
38
- history.append((message, response))
39
- return history, response
40
-
41
- iface = gr.ChatInterface(
42
- fn=chatbot,
43
- title="학습 챗봇",
44
- description="학습 목표를 입력하고 챗봇과 대화해보세요!",
45
- theme="compact",
46
- )
47
 
48
- # 실행
49
- iface.launch(share=True)
 
4
 
5
  genai.configure(api_key=os.environ["GEMINI_API_KEY"])
6
 
7
+ # 모델 설정
8
  generation_config = {
9
  "temperature": 1,
10
  "top_p": 0.95,
 
28
 
29
  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
+ return "", history
35
+
36
+ with gr.Blocks() as demo:
37
+ gr.Markdown("<div style='font-size: 30px; font-weight: bold;'>gemini chatbot</div>")
38
+ chatbot = gr.Chatbot(label="채팅창")
39
+ msg = gr.Textbox(label="입력")
40
+ clear = gr.Button("초기화")
41
+
42
+ msg.submit(respond, [msg, chatbot], [msg, chatbot])
43
+ clear.click(lambda: [], None, chatbot, queue=False)
 
 
 
 
44
 
45
+ demo.launch()