Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from huggingface_hub import InferenceClient
|
| 4 |
+
|
| 5 |
+
client = InferenceClient(provider="novita", api_key=os.environ["HF_TOKEN"])
|
| 6 |
+
models = ["Qwen/Qwen3-Next-80B-A3B-Instruct", "meta-llama/Llama-3.1-70B-Instruct", "mistralai/Mixtral-8x7B-Instruct-v0.1"]
|
| 7 |
+
|
| 8 |
+
def respond(message, history, model):
|
| 9 |
+
completion = client.chat.completions.create(
|
| 10 |
+
model=model,
|
| 11 |
+
messages=[{"role": "user", "content": message}]
|
| 12 |
+
)
|
| 13 |
+
reply = completion.choices[0].message.content
|
| 14 |
+
history.append((message, reply))
|
| 15 |
+
return "", history
|
| 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 |
+
clear = gr.Button("Clear")
|
| 23 |
+
msg.submit(respond, [msg, chatbot, model_dd], [msg, chatbot])
|
| 24 |
+
clear.click(lambda: None, None, chatbot, queue=False)
|
| 25 |
+
|
| 26 |
+
demo.launch()
|