Update app.py
Browse files
app.py
CHANGED
|
@@ -6,21 +6,29 @@ client = InferenceClient(provider="novita", api_key=os.environ["HF_TOKEN"])
|
|
| 6 |
models = ["deepseek-ai/DeepSeek-V3.1","zai-org/GLM-4.5","Qwen/Qwen3-Coder-480B-A35B-Instruct", "Qwen/Qwen3-Coder-480B-A35B-Instruct-FP8","deepseek-ai/DeepSeek-R1","deepseek-ai/DeepSeek-R1-0528","Qwen/Qwen3-Next-80B-A3B-Thinking"]
|
| 7 |
|
| 8 |
def respond(message, history, model):
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
| 10 |
model=model,
|
| 11 |
-
messages=[{"role": "user", "content": message}]
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
| 16 |
|
| 17 |
with gr.Blocks() as demo:
|
| 18 |
gr.Markdown("## AI")
|
| 19 |
chatbot = gr.Chatbot(height=400)
|
| 20 |
msg = gr.Textbox(label="Ask me smth")
|
| 21 |
model_dd = gr.Dropdown(models, label="Model", value=models[0])
|
| 22 |
-
|
|
|
|
|
|
|
| 23 |
msg.submit(respond, [msg, chatbot, model_dd], [msg, chatbot])
|
|
|
|
| 24 |
clear.click(lambda: None, None, chatbot, queue=False)
|
| 25 |
|
| 26 |
-
demo.launch()
|
|
|
|
| 6 |
models = ["deepseek-ai/DeepSeek-V3.1","zai-org/GLM-4.5","Qwen/Qwen3-Coder-480B-A35B-Instruct", "Qwen/Qwen3-Coder-480B-A35B-Instruct-FP8","deepseek-ai/DeepSeek-R1","deepseek-ai/DeepSeek-R1-0528","Qwen/Qwen3-Next-80B-A3B-Thinking"]
|
| 7 |
|
| 8 |
def respond(message, history, model):
|
| 9 |
+
history.append((message, ""))
|
| 10 |
+
yield "", history
|
| 11 |
+
full_reply = ""
|
| 12 |
+
for chunk in client.chat.completions.create(
|
| 13 |
model=model,
|
| 14 |
+
messages=[{"role": "user", "content": message}],
|
| 15 |
+
stream=True
|
| 16 |
+
):
|
| 17 |
+
if hasattr(chunk.choices[0].delta, 'content') and chunk.choices[0].delta.content:
|
| 18 |
+
full_reply += chunk.choices[0].delta.content
|
| 19 |
+
history[-1] = (message, full_reply)
|
| 20 |
+
yield "", history
|
| 21 |
|
| 22 |
with gr.Blocks() as demo:
|
| 23 |
gr.Markdown("## AI")
|
| 24 |
chatbot = gr.Chatbot(height=400)
|
| 25 |
msg = gr.Textbox(label="Ask me smth")
|
| 26 |
model_dd = gr.Dropdown(models, label="Model", value=models[0])
|
| 27 |
+
with gr.Row():
|
| 28 |
+
submit_btn = gr.Button("Send")
|
| 29 |
+
clear = gr.Button("Clear")
|
| 30 |
msg.submit(respond, [msg, chatbot, model_dd], [msg, chatbot])
|
| 31 |
+
submit_btn.click(respond, [msg, chatbot, model_dd], [msg, chatbot])
|
| 32 |
clear.click(lambda: None, None, chatbot, queue=False)
|
| 33 |
|
| 34 |
+
demo.queue().launch()
|