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

updata1 main.py

Browse files
Files changed (1) hide show
  1. app.py +21 -30
app.py CHANGED
@@ -1,41 +1,32 @@
1
  import gradio as gr
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):
9
- headers = {
10
- "Authorization": f"Bearer {HF_API_KEY}",
11
- "Content-Type": "application/json",
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)
 
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()