Jedi09 commited on
Commit
2d7cd3f
·
verified ·
1 Parent(s): c2019f4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -9
app.py CHANGED
@@ -4,6 +4,7 @@ import time
4
  import os
5
  import tempfile
6
  import requests
 
7
 
8
  # ==================== CONFIG & MODELS ====================
9
 
@@ -26,9 +27,12 @@ def call_huggingface_api(prompt, api_key):
26
  Hugging Face Serverless Inference API (Router Endpoint).
27
  OpenAI uyumlu chat/completions formatı kullanır.
28
  """
29
- if not api_key:
30
- return "⚠️ HF Token girilmedi."
31
- if not api_key.startswith("hf_"):
 
 
 
32
  return "⚠️ Token 'hf_' ile başlamalıdır."
33
 
34
  # Sırayla deneyeceğimiz modeller
@@ -44,11 +48,12 @@ def call_huggingface_api(prompt, api_key):
44
 
45
  print("=" * 50)
46
  print(f"🔗 API URL: {url}")
47
- print(f"🔑 Token: {api_key[:10]}...")
 
48
  print("=" * 50)
49
 
50
  headers = {
51
- "Authorization": f"Bearer {api_key}",
52
  "Content-Type": "application/json"
53
  }
54
 
@@ -102,7 +107,11 @@ def call_huggingface_api(prompt, api_key):
102
  print(f"⏰ [{model_id}] Zaman aşımı (90sn)")
103
  continue
104
  except Exception as e:
105
- print(f"💥 [{model_id}] İstisna: {e}")
 
 
 
 
106
  continue
107
 
108
  print("\n" + "=" * 50)
@@ -214,11 +223,16 @@ with gr.Blocks(title="Ses Deşifre Pro") as demo:
214
 
215
  gr.HTML("<h3 style='margin-top: 20px; border-bottom: 1px solid #ddd; padding-bottom: 10px;'>☁️ Hugging Face API (Özet & Çeviri)</h3>")
216
 
 
 
 
 
217
  with gr.Row():
218
  api_key_input = gr.Textbox(
219
- label="🔑 HF Token (hf_...)",
220
- placeholder="huggingface.co/settings/tokens adresinden alın",
221
- type="password"
 
222
  )
223
 
224
  with gr.Tabs():
 
4
  import os
5
  import tempfile
6
  import requests
7
+ import traceback
8
 
9
  # ==================== CONFIG & MODELS ====================
10
 
 
27
  Hugging Face Serverless Inference API (Router Endpoint).
28
  OpenAI uyumlu chat/completions formatı kullanır.
29
  """
30
+ # Önce environment variable kontrol et, yoksa UI'dan gelen değeri kullan
31
+ token = os.environ.get("HF_TOKEN") or api_key
32
+
33
+ if not token:
34
+ return "⚠️ HF Token bulunamadı. Secret olarak veya kutuya girin."
35
+ if not token.startswith("hf_"):
36
  return "⚠️ Token 'hf_' ile başlamalıdır."
37
 
38
  # Sırayla deneyeceğimiz modeller
 
48
 
49
  print("=" * 50)
50
  print(f"🔗 API URL: {url}")
51
+ secret_source = "ENV" if os.environ.get("HF_TOKEN") else "UI"
52
+ print(f"🔑 Token ({secret_source}): {token[:10]}...")
53
  print("=" * 50)
54
 
55
  headers = {
56
+ "Authorization": f"Bearer {token}",
57
  "Content-Type": "application/json"
58
  }
59
 
 
107
  print(f"⏰ [{model_id}] Zaman aşımı (90sn)")
108
  continue
109
  except Exception as e:
110
+ print(f"💥 [{model_id}] İSTİSNA DETAYI:")
111
+ print(f" Hata Tipi: {type(e).__name__}")
112
+ print(f" Mesaj: {e}")
113
+ print(" Traceback:")
114
+ traceback.print_exc()
115
  continue
116
 
117
  print("\n" + "=" * 50)
 
223
 
224
  gr.HTML("<h3 style='margin-top: 20px; border-bottom: 1px solid #ddd; padding-bottom: 10px;'>☁️ Hugging Face API (Özet & Çeviri)</h3>")
225
 
226
+ # Secret durumunu kontrol et
227
+ hf_secret_loaded = bool(os.environ.get("HF_TOKEN"))
228
+ secret_status = "✅ Secret yüklendi (HF_TOKEN)" if hf_secret_loaded else "⚠️ Secret bulunamadı, token girin"
229
+
230
  with gr.Row():
231
  api_key_input = gr.Textbox(
232
+ label="🔑 HF Token (Opsiyonel - Secret varsa gerek yok)",
233
+ placeholder=secret_status,
234
+ type="password",
235
+ value="" if hf_secret_loaded else None
236
  )
237
 
238
  with gr.Tabs():