Update app.py
Browse files
app.py
CHANGED
|
@@ -19,7 +19,8 @@ if api_key:
|
|
| 19 |
# Function to handle chat
|
| 20 |
def chat_with_deepseek(message, history):
|
| 21 |
if not client:
|
| 22 |
-
|
|
|
|
| 23 |
|
| 24 |
try:
|
| 25 |
# Convert Gradio history to OpenAI messages format
|
|
@@ -35,9 +36,11 @@ def chat_with_deepseek(message, history):
|
|
| 35 |
)
|
| 36 |
|
| 37 |
reply = completion.choices[0].message.content
|
| 38 |
-
return
|
|
|
|
| 39 |
except Exception as e:
|
| 40 |
-
|
|
|
|
| 41 |
|
| 42 |
# Gradio Chat UI
|
| 43 |
with gr.Blocks(theme="soft", css="""
|
|
@@ -85,8 +88,9 @@ with gr.Blocks(theme="soft", css="""
|
|
| 85 |
elem_id="inputbox"
|
| 86 |
)
|
| 87 |
submit_btn = gr.Button("Send", elem_id="submitbtn")
|
|
|
|
| 88 |
|
| 89 |
-
#
|
| 90 |
submit_btn.click(
|
| 91 |
fn=chat_with_deepseek,
|
| 92 |
inputs=[user_input, chatbot],
|
|
@@ -98,4 +102,8 @@ with gr.Blocks(theme="soft", css="""
|
|
| 98 |
outputs=chatbot
|
| 99 |
)
|
| 100 |
|
|
|
|
|
|
|
|
|
|
| 101 |
demo.launch()
|
|
|
|
|
|
| 19 |
# Function to handle chat
|
| 20 |
def chat_with_deepseek(message, history):
|
| 21 |
if not client:
|
| 22 |
+
history.append((message, "β HF_TOKEN not found. Please set it in 'Settings β Repository secrets'."))
|
| 23 |
+
return history
|
| 24 |
|
| 25 |
try:
|
| 26 |
# Convert Gradio history to OpenAI messages format
|
|
|
|
| 36 |
)
|
| 37 |
|
| 38 |
reply = completion.choices[0].message.content
|
| 39 |
+
history.append((message, reply)) # β
return updated history
|
| 40 |
+
return history
|
| 41 |
except Exception as e:
|
| 42 |
+
history.append((message, f"β οΈ Error: {str(e)}"))
|
| 43 |
+
return history
|
| 44 |
|
| 45 |
# Gradio Chat UI
|
| 46 |
with gr.Blocks(theme="soft", css="""
|
|
|
|
| 88 |
elem_id="inputbox"
|
| 89 |
)
|
| 90 |
submit_btn = gr.Button("Send", elem_id="submitbtn")
|
| 91 |
+
clear_btn = gr.Button("ποΈ Clear Chat")
|
| 92 |
|
| 93 |
+
# Event: Send message
|
| 94 |
submit_btn.click(
|
| 95 |
fn=chat_with_deepseek,
|
| 96 |
inputs=[user_input, chatbot],
|
|
|
|
| 102 |
outputs=chatbot
|
| 103 |
)
|
| 104 |
|
| 105 |
+
# Event: Clear history
|
| 106 |
+
clear_btn.click(lambda: [], None, chatbot, queue=False)
|
| 107 |
+
|
| 108 |
demo.launch()
|
| 109 |
+
|