wifix199 commited on
Commit
849aaf7
·
verified ·
1 Parent(s): 6116057

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -8
app.py CHANGED
@@ -1,10 +1,36 @@
 
 
 
 
1
  import gradio as gr
2
 
3
- with gr.Blocks(fill_height=True) as demo:
4
- with gr.Sidebar():
5
- gr.Markdown("# Inference Provider")
6
- gr.Markdown("This Space showcases the Qwen/QwQ-32B model, served by the fireworks-ai API. Sign in with your Hugging Face account to use this API.")
7
- button = gr.LoginButton("Sign in")
8
- gr.load("models/Qwen/QwQ-32B", accept_token=button, provider="fireworks-ai")
9
-
10
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 2) The actual app
2
+ import os
3
+ from getpass import getpass
4
+ from openai import OpenAI
5
  import gradio as gr
6
 
7
+ # ——— Configure your OpenRouter key ———
8
+ if "OPENROUTER_API_KEY" not in os.environ or not os.environ["OPENROUTER_API_KEY"]:
9
+ os.environ["OPENROUTER_API_KEY"] = getpass("🔑 Enter your OpenRouter API key: ")
10
+
11
+ client = OpenAI(
12
+ base_url="https://openrouter.ai/api/v1",
13
+ api_key=os.environ["OPENROUTER_API_KEY"],
14
+ )
15
+
16
+ def openrouter_chat(user_message, history):
17
+ """Send user_message to mistralai/devstral-small:free and append to history."""
18
+ # build the messages list
19
+ msgs = [{"role": "user", "content": user_message}]
20
+ # call the model
21
+ resp = client.chat.completions.create(
22
+ model="mistralai/devstral-small:free",
23
+ messages=msgs,
24
+ # you can tweak max_tokens, temperature, etc. here
25
+ )
26
+ bot_reply = resp.choices[0].message.content
27
+ history = history or []
28
+ history.append((user_message, bot_reply))
29
+ return history, ""
30
+
31
+ with gr.Blocks() as demo:
32
+ gr.Markdown("## 🦜🔗 Gradio + OpenRouter Chat with Devstral-Small")
33
+ chatbot = gr.Chatbot(label="Chat")
34
+ msg_in = gr.Textbox(placeholder="Type your question here…", label="You")
35
+ msg_in.submit(openrouter_chat, inputs=[msg_in, chatbot], outputs=[chatbot, msg_in])
36
+ demo.launch()