Spaces:
Sleeping
Sleeping
final working version
Browse files
app.py
CHANGED
|
@@ -2,7 +2,7 @@ import gradio as gr
|
|
| 2 |
import requests
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
# Hugging Face
|
| 6 |
HF_API_KEY = os.getenv("HF_API_KEY")
|
| 7 |
|
| 8 |
def ask_model(prompt):
|
|
@@ -12,26 +12,30 @@ def ask_model(prompt):
|
|
| 12 |
}
|
| 13 |
data = {"inputs": prompt}
|
| 14 |
|
| 15 |
-
# ✅ Yeni
|
| 16 |
API_URL = "https://router.huggingface.co/hf-inference/models/mistralai/Mistral-7B-Instruct-v0.2"
|
| 17 |
|
| 18 |
-
|
|
|
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
| 24 |
else:
|
| 25 |
-
return
|
| 26 |
-
|
| 27 |
-
return f"
|
| 28 |
|
| 29 |
iface = gr.Interface(
|
| 30 |
fn=ask_model,
|
| 31 |
-
inputs="
|
| 32 |
-
outputs="
|
| 33 |
title="Flutter AI Proxy",
|
| 34 |
-
description="Flutter uygulaman buraya istek atacak, model yanıt dönecek."
|
| 35 |
)
|
| 36 |
|
| 37 |
-
iface.launch()
|
|
|
|
| 2 |
import requests
|
| 3 |
import os
|
| 4 |
|
| 5 |
+
# Hugging Face API anahtarını Settings → Variables → HF_API_KEY olarak eklemelisin.
|
| 6 |
HF_API_KEY = os.getenv("HF_API_KEY")
|
| 7 |
|
| 8 |
def ask_model(prompt):
|
|
|
|
| 12 |
}
|
| 13 |
data = {"inputs": prompt}
|
| 14 |
|
| 15 |
+
# ✅ Yeni Hugging Face yönlendirme sistemi
|
| 16 |
API_URL = "https://router.huggingface.co/hf-inference/models/mistralai/Mistral-7B-Instruct-v0.2"
|
| 17 |
|
| 18 |
+
try:
|
| 19 |
+
response = requests.post(API_URL, headers=headers, json=data, timeout=60)
|
| 20 |
|
| 21 |
+
if response.status_code == 200:
|
| 22 |
+
output = response.json()
|
| 23 |
+
# Bazı modeller farklı yapıda dönebilir
|
| 24 |
+
if isinstance(output, list) and "generated_text" in output[0]:
|
| 25 |
+
return output[0]["generated_text"]
|
| 26 |
+
else:
|
| 27 |
+
return str(output)
|
| 28 |
else:
|
| 29 |
+
return f"Error: {response.status_code} - {response.text}"
|
| 30 |
+
except Exception as e:
|
| 31 |
+
return f"Hata oluştu: {str(e)}"
|
| 32 |
|
| 33 |
iface = gr.Interface(
|
| 34 |
fn=ask_model,
|
| 35 |
+
inputs=gr.Textbox(label="Prompt"),
|
| 36 |
+
outputs=gr.Textbox(label="Yanıt"),
|
| 37 |
title="Flutter AI Proxy",
|
| 38 |
+
description="Flutter uygulaman buraya istek atacak, model yanıt dönecek.",
|
| 39 |
)
|
| 40 |
|
| 41 |
+
iface.launch(share=True)
|