Download app.py from nanodk12/Ruby-api: direct link, hf CLI and curl.
- Browser
- Download file 792 Bytes
-
https://huggingface.co/spaces/nanodk12/Ruby-api/resolve/main/app.py
- Command line
-
hf download hf://spaces/nanodk12/Ruby-api/app.py
-
curl -L -o app.py https://huggingface.co/spaces/nanodk12/Ruby-api/resolve/main/app.py
792 Bytes
| import gradio as gr | |
| import requests | |
| # Replace with your actual API endpoint (if using a different service) | |
| API_URL = "https://api.deepseek.com/v1/chat/completions" # Example (not me) | |
| API_KEY = "your-api-key" # Replace with your key | |
| def ask_ruby(question): | |
| headers = { | |
| "Authorization": f"Bearer {API_KEY}", | |
| "Content-Type": "application/json" | |
| } | |
| data = { | |
| "messages": [{"role": "user", "content": question}] | |
| } | |
| response = requests.post(API_URL, headers=headers, json=data) | |
| return response.json()["choices"][0]["message"]["content"] | |
| # Gradio UI (optional, but useful for testing) | |
| demo = gr.Interface( | |
| fn=ask_ruby, | |
| inputs=gr.Textbox(lines=2, placeholder="Ask Ruby anything..."), | |
| outputs="text", | |
| title="Ruby AI API" | |
| ) | |
| demo.launch() |