Spaces:
Running
Running
import gradio as gr | |
import requests | |
def chat_with_openrouter(prompt): | |
url = "https://api.openrouter.ai/v1/chat/completions" | |
headers = {"Authorization": "Bearer OpenRounter_API_KEY"} | |
data = { | |
"model": "openai/gpt-4o-mini-2024-07-18", | |
"messages": [{"role": "user", "content": prompt}], | |
"top_p:" 1, | |
"temperature:" 1, | |
"repetition_penalty:" 1, | |
"transforms": [] | |
} | |
response = requests.post(url, headers=headers, json=data) | |
return response.json().get("choices", [{}])[0].get("message", {}).get("content", "No response") | |
iface = gr.Interface( | |
fn=chat_with_openrouter, | |
inputs=gr.Textbox(lines=2, placeholder="Ask me anything"), | |
outputs="text", | |
title="Chat with OpenRouter", | |
) | |
iface.launch() | |