Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -105,36 +105,31 @@ def chat_interface(message, chat_history):
|
|
105 |
return chat_history
|
106 |
|
107 |
try:
|
108 |
-
# Format the message history in the OpenAI style
|
109 |
messages = []
|
110 |
for msg in chat_history:
|
111 |
messages.append({"role": "user", "content": msg[0]})
|
112 |
if msg[1] is not None:
|
113 |
messages.append({"role": "assistant", "content": msg[1]})
|
114 |
|
115 |
-
# Add the current message
|
116 |
messages.append({"role": "user", "content": message})
|
117 |
|
118 |
-
# Get response
|
119 |
response = generate_response(messages)
|
120 |
|
121 |
-
# Update history in the new format
|
122 |
chat_history.append((message, response))
|
123 |
return chat_history
|
124 |
except Exception as e:
|
125 |
chat_history.append((message, f"Error: {str(e)}"))
|
126 |
return chat_history
|
127 |
|
128 |
-
# Create Gradio interface
|
129 |
-
demo = gr.
|
130 |
-
|
131 |
title="Qwen2.5-Coder-32B Chat",
|
132 |
description="Chat with Qwen2.5-Coder-32B model via Hugging Face Inference API",
|
133 |
-
examples=[
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
clear_btn="Clear conversation",
|
138 |
)
|
139 |
|
140 |
# Mount both FastAPI and Gradio
|
|
|
105 |
return chat_history
|
106 |
|
107 |
try:
|
|
|
108 |
messages = []
|
109 |
for msg in chat_history:
|
110 |
messages.append({"role": "user", "content": msg[0]})
|
111 |
if msg[1] is not None:
|
112 |
messages.append({"role": "assistant", "content": msg[1]})
|
113 |
|
|
|
114 |
messages.append({"role": "user", "content": message})
|
115 |
|
|
|
116 |
response = generate_response(messages)
|
117 |
|
|
|
118 |
chat_history.append((message, response))
|
119 |
return chat_history
|
120 |
except Exception as e:
|
121 |
chat_history.append((message, f"Error: {str(e)}"))
|
122 |
return chat_history
|
123 |
|
124 |
+
# Create Gradio interface
|
125 |
+
demo = gr.Chatbot(
|
126 |
+
chat_interface,
|
127 |
title="Qwen2.5-Coder-32B Chat",
|
128 |
description="Chat with Qwen2.5-Coder-32B model via Hugging Face Inference API",
|
129 |
+
examples=[
|
130 |
+
"Hello! Can you help me with coding?",
|
131 |
+
"Write a simple Python function to calculate factorial"
|
132 |
+
]
|
|
|
133 |
)
|
134 |
|
135 |
# Mount both FastAPI and Gradio
|