Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,7 +13,7 @@ def chat_with_model(user_message, history):
|
|
| 13 |
if history is None:
|
| 14 |
history = []
|
| 15 |
|
| 16 |
-
#
|
| 17 |
messages = [{"role": "system", "content": "You are a helpful assistant."}]
|
| 18 |
for human, bot in history:
|
| 19 |
messages.append({"role": "user", "content": human})
|
|
@@ -26,27 +26,25 @@ def chat_with_model(user_message, history):
|
|
| 26 |
model="openai/gpt-oss-20b:nebius",
|
| 27 |
messages=messages
|
| 28 |
)
|
| 29 |
-
|
| 30 |
reply = completion.choices[0].message["content"]
|
| 31 |
|
| 32 |
-
#
|
| 33 |
history.append((user_message, reply))
|
| 34 |
-
|
| 35 |
-
return history, history
|
| 36 |
|
| 37 |
except Exception as e:
|
| 38 |
-
|
| 39 |
-
history
|
| 40 |
-
return history, history
|
| 41 |
|
| 42 |
|
| 43 |
with gr.Blocks() as demo:
|
| 44 |
gr.Markdown("# 🤖 Chat with HuggingFace Router (OpenAI Compatible)")
|
| 45 |
-
|
| 46 |
chatbot = gr.Chatbot(height=500)
|
| 47 |
-
text_input = gr.Textbox(label="
|
| 48 |
-
|
| 49 |
-
text_input.submit(chat_with_model, [text_input, chatbot],
|
| 50 |
text_input.submit(lambda: "", None, text_input)
|
| 51 |
|
| 52 |
-
demo.launch()
|
|
|
|
| 13 |
if history is None:
|
| 14 |
history = []
|
| 15 |
|
| 16 |
+
# prepare messages for the API
|
| 17 |
messages = [{"role": "system", "content": "You are a helpful assistant."}]
|
| 18 |
for human, bot in history:
|
| 19 |
messages.append({"role": "user", "content": human})
|
|
|
|
| 26 |
model="openai/gpt-oss-20b:nebius",
|
| 27 |
messages=messages
|
| 28 |
)
|
| 29 |
+
|
| 30 |
reply = completion.choices[0].message["content"]
|
| 31 |
|
| 32 |
+
# MUST be appended as tuple
|
| 33 |
history.append((user_message, reply))
|
| 34 |
+
return history
|
|
|
|
| 35 |
|
| 36 |
except Exception as e:
|
| 37 |
+
history.append((user_message, f"Error: {str(e)}"))
|
| 38 |
+
return history
|
|
|
|
| 39 |
|
| 40 |
|
| 41 |
with gr.Blocks() as demo:
|
| 42 |
gr.Markdown("# 🤖 Chat with HuggingFace Router (OpenAI Compatible)")
|
| 43 |
+
|
| 44 |
chatbot = gr.Chatbot(height=500)
|
| 45 |
+
text_input = gr.Textbox(label="Your message")
|
| 46 |
+
|
| 47 |
+
text_input.submit(chat_with_model, [text_input, chatbot], chatbot)
|
| 48 |
text_input.submit(lambda: "", None, text_input)
|
| 49 |
|
| 50 |
+
demo.queue(concurrency_count=1, status_update_rate=0).launch() # still safe
|