Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import requests | |
| import os | |
| # Token environment variable olarak alınır (Settings > Variables'da tanımlandı) | |
| HF_API_KEY = os.getenv("HF_API_KEY") | |
| def ask_model(prompt): | |
| headers = {"Authorization": f"Bearer {HF_API_KEY}"} | |
| data = {"inputs": prompt} | |
| response = requests.post( | |
| "https://router.huggingface.co/hf-inference/mistralai/Mistral-7B-Instruct-v0.2", | |
| headers=headers, | |
| json=data | |
| ) | |
| if response.status_code == 200: | |
| result = response.json() | |
| if isinstance(result, list) and len(result) > 0 and "generated_text" in result[0]: | |
| return result[0]["generated_text"] | |
| else: | |
| return str(result) | |
| else: | |
| return f"Error: {response.status_code} - {response.text}" | |
| # Gradio arayüzü | |
| iface = gr.Interface( | |
| fn=ask_model, | |
| inputs="text", | |
| outputs="text", | |
| title="Flutter AI Proxy", | |
| description="Flutter uygulaman buraya istek atacak, model yanıt dönecek." | |
| ) | |
| iface.launch() | |