Yermek68 commited on
Commit
3f976bd
·
verified ·
1 Parent(s): c5f1e55

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py CHANGED
@@ -2,6 +2,32 @@ from fastapi import FastAPI
2
  import gradio as gr
3
  from core.agent import generate_response
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  app = FastAPI(title="Eroha AgentAPI v3.1 (Guru Edition)")
6
 
7
  def chat_interface(user_input):
 
2
  import gradio as gr
3
  from core.agent import generate_response
4
 
5
+ import os
6
+ import requests
7
+
8
+ def check_hf_token():
9
+ token = os.getenv("HF_TOKEN")
10
+ if not token:
11
+ print("❌ HF_TOKEN не найден. Добавь его в Secrets.")
12
+ return "❌ Токен не найден"
13
+
14
+ headers = {"Authorization": f"Bearer {token}"}
15
+ try:
16
+ response = requests.get("https://huggingface.co/api/whoami-v2", headers=headers, timeout=10)
17
+ if response.status_code == 200:
18
+ user = response.json().get("name", "неизвестный пользователь")
19
+ print(f"✅ Hugging Face API доступен. Авторизован как: {user}")
20
+ return f"✅ API доступен ({user})"
21
+ else:
22
+ print(f"⚠️ Токен отклонён. Код {response.status_code}")
23
+ return f"⚠️ Ошибка токена ({response.status_code})"
24
+ except Exception as e:
25
+ print(f"❌ Ошибка подключения к Hugging Face API: {e}")
26
+ return f"❌ Ошибка: {e}"
27
+
28
+ # выполнить проверку при запуске приложения
29
+ status_message = check_hf_token()
30
+
31
  app = FastAPI(title="Eroha AgentAPI v3.1 (Guru Edition)")
32
 
33
  def chat_interface(user_input):