Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -30,12 +30,11 @@ def chat_with_groq(user_message):
|
|
| 30 |
temperature=1,
|
| 31 |
max_tokens=1024,
|
| 32 |
top_p=1,
|
| 33 |
-
stream=
|
| 34 |
)
|
| 35 |
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
response += chunk.get('choices', [{}])[0].get('delta', {}).get('content', "")
|
| 39 |
return response
|
| 40 |
|
| 41 |
except Exception as e:
|
|
@@ -43,8 +42,6 @@ def chat_with_groq(user_message):
|
|
| 43 |
|
| 44 |
# 定義 Gradio 介面
|
| 45 |
def gradio_chatbot():
|
| 46 |
-
chatbot = gr.Chatbot()
|
| 47 |
-
|
| 48 |
def respond(message, history):
|
| 49 |
response = chat_with_groq(message)
|
| 50 |
history = history or []
|
|
@@ -52,12 +49,11 @@ def gradio_chatbot():
|
|
| 52 |
return history, history
|
| 53 |
|
| 54 |
with gr.Blocks() as demo:
|
| 55 |
-
|
| 56 |
-
gr.Markdown("### 成語遊戲 Chatbot")
|
| 57 |
chatbot = gr.Chatbot()
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
submit_button.click(respond, [user_input, chatbot], [chatbot, chatbot])
|
| 62 |
|
| 63 |
return demo
|
|
|
|
| 30 |
temperature=1,
|
| 31 |
max_tokens=1024,
|
| 32 |
top_p=1,
|
| 33 |
+
stream=False
|
| 34 |
)
|
| 35 |
|
| 36 |
+
# 處理非流式輸出
|
| 37 |
+
response = completion["choices"][0]["message"]["content"]
|
|
|
|
| 38 |
return response
|
| 39 |
|
| 40 |
except Exception as e:
|
|
|
|
| 42 |
|
| 43 |
# 定義 Gradio 介面
|
| 44 |
def gradio_chatbot():
|
|
|
|
|
|
|
| 45 |
def respond(message, history):
|
| 46 |
response = chat_with_groq(message)
|
| 47 |
history = history or []
|
|
|
|
| 49 |
return history, history
|
| 50 |
|
| 51 |
with gr.Blocks() as demo:
|
| 52 |
+
gr.Markdown("### 成語遊戲 Chatbot")
|
|
|
|
| 53 |
chatbot = gr.Chatbot()
|
| 54 |
+
user_input = gr.Textbox(placeholder="輸入你的訊息...")
|
| 55 |
+
submit_button = gr.Button("送出")
|
| 56 |
+
|
| 57 |
submit_button.click(respond, [user_input, chatbot], [chatbot, chatbot])
|
| 58 |
|
| 59 |
return demo
|