Spaces:
Sleeping
Sleeping
updata1 main.py
Browse files
app.py
CHANGED
|
@@ -1,41 +1,32 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
-
import os
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
|
|
|
| 7 |
|
| 8 |
def ask_model(prompt):
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 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="
|
| 36 |
-
outputs=
|
| 37 |
title="Flutter AI Proxy",
|
| 38 |
-
description="Flutter uygulaman buraya istek atacak, model yanıt dönecek."
|
| 39 |
)
|
| 40 |
|
| 41 |
-
iface.launch(
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
|
|
|
| 3 |
|
| 4 |
+
HF_API_URL = "https://router.huggingface.co/hf-inference"
|
| 5 |
+
MODEL_ID = "meta-llama/Llama-3.2-1B-Instruct"
|
| 6 |
+
HEADERS = {"Authorization": "Bearer hf_your_token_here"}
|
| 7 |
|
| 8 |
def ask_model(prompt):
|
| 9 |
+
response = requests.post(
|
| 10 |
+
HF_API_URL,
|
| 11 |
+
headers=HEADERS,
|
| 12 |
+
json={
|
| 13 |
+
"model": MODEL_ID,
|
| 14 |
+
"inputs": prompt,
|
| 15 |
+
"parameters": {"max_new_tokens": 200},
|
| 16 |
+
},
|
| 17 |
+
)
|
| 18 |
+
if response.status_code == 200:
|
| 19 |
+
result = response.json()
|
| 20 |
+
return result[0]["generated_text"]
|
| 21 |
+
else:
|
| 22 |
+
return f"Error {response.status_code}: {response.text}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
iface = gr.Interface(
|
| 25 |
fn=ask_model,
|
| 26 |
+
inputs=gr.Textbox(label="prompt"),
|
| 27 |
+
outputs="text",
|
| 28 |
title="Flutter AI Proxy",
|
| 29 |
+
description="Flutter uygulaman buraya istek atacak, model yanıt dönecek."
|
| 30 |
)
|
| 31 |
|
| 32 |
+
iface.launch()
|