26ali commited on
Commit
2b516d3
·
verified ·
1 Parent(s): df4be7c

final working version

Browse files
Files changed (1) hide show
  1. app.py +18 -14
app.py CHANGED
@@ -2,7 +2,7 @@ import gradio as gr
2
  import requests
3
  import os
4
 
5
- # Hugging Face token (Settings → Variables → New Variable → Key: HF_API_KEY)
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 endpoint artık sadece bu kullanılacak
16
  API_URL = "https://router.huggingface.co/hf-inference/models/mistralai/Mistral-7B-Instruct-v0.2"
17
 
18
- response = requests.post(API_URL, headers=headers, json=data)
 
19
 
20
- if response.status_code == 200:
21
- output = response.json()
22
- if isinstance(output, list) and "generated_text" in output[0]:
23
- return output[0]["generated_text"]
 
 
 
24
  else:
25
- return str(output)
26
- else:
27
- return f"Error: {response.status_code} - {response.text}"
28
 
29
  iface = gr.Interface(
30
  fn=ask_model,
31
- inputs="text",
32
- outputs="text",
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)