Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
|
4 |
+
def chat_with_openrouter(prompt):
|
5 |
+
url = "https://api.openrouter.ai/v1/chat/completions"
|
6 |
+
headers = {"Authorization": "Bearer OpenRounter_API_KEY"}
|
7 |
+
data = {
|
8 |
+
"model": "openai/gpt-4o-mini-2024-07-18",
|
9 |
+
"messages": [{"role": "user", "content": prompt}],
|
10 |
+
"top_p:" 1,
|
11 |
+
"temperature:" 1,
|
12 |
+
"repetition_penalty:" 1,
|
13 |
+
"transforms": []
|
14 |
+
}
|
15 |
+
response = requests.post(url, headers=headers, json=data)
|
16 |
+
return response.json().get("choices", [{}])[0].get("message", {}).get("content", "No response")
|
17 |
+
|
18 |
+
iface = gr.Interface(
|
19 |
+
fn=chat_with_openrouter,
|
20 |
+
inputs=gr.Textbox(lines=2, placeholder="Ask me anything"),
|
21 |
+
outputs="text",
|
22 |
+
title="Chat with OpenRouter",
|
23 |
+
)
|
24 |
+
|
25 |
+
iface.launch()
|