Update app.py
Browse files
app.py
CHANGED
@@ -54,23 +54,29 @@ def get_client():
|
|
54 |
# Try multiple token sources for Spaces
|
55 |
api_token = None
|
56 |
|
57 |
-
# Method 1:
|
58 |
api_token = os.getenv("HF_API_TOKEN")
|
|
|
|
|
59 |
|
60 |
-
# Method 2:
|
61 |
if not api_token:
|
62 |
-
api_token = os.getenv("
|
|
|
|
|
63 |
|
64 |
# Method 3: Hugging Face CLI token (if logged in)
|
65 |
if not api_token:
|
66 |
try:
|
67 |
from huggingface_hub import get_token
|
68 |
api_token = get_token()
|
|
|
|
|
69 |
except:
|
70 |
pass
|
71 |
|
72 |
if not api_token:
|
73 |
-
logger.warning("β οΈ No HF token found.
|
74 |
return None
|
75 |
|
76 |
try:
|
@@ -98,7 +104,7 @@ CLIENT = get_client()
|
|
98 |
def safe_call(func_name: str, func, *args, **kwargs):
|
99 |
"""Spaces-optimized safe API calls."""
|
100 |
if not CLIENT:
|
101 |
-
return "β API client not available. Please check if HF_TOKEN is set in Spaces secrets."
|
102 |
|
103 |
try:
|
104 |
logger.info(f"π {func_name}...")
|
@@ -449,7 +455,7 @@ with gr.Blocks(title="π AI Research Hub", theme=gr.themes.Soft(), css=custom_
|
|
449 |
else:
|
450 |
gr.HTML("""
|
451 |
<div class="status-indicator status-error">
|
452 |
-
β <strong>Status:</strong> Please set HF_TOKEN in Spaces settings
|
453 |
</div>
|
454 |
""")
|
455 |
|
@@ -613,7 +619,7 @@ with gr.Blocks(title="π AI Research Hub", theme=gr.themes.Soft(), css=custom_
|
|
613 |
|
614 |
**To use this Space:**
|
615 |
1. Go to **Settings** β **Repository secrets**
|
616 |
-
2. Add **HF_TOKEN** with your Hugging Face token
|
617 |
3. Get your token at: [https://huggingface.co/settings/tokens](https://huggingface.co/settings/tokens)
|
618 |
|
619 |
**Features:**
|
|
|
54 |
# Try multiple token sources for Spaces
|
55 |
api_token = None
|
56 |
|
57 |
+
# Method 1: Check HF_API_TOKEN (your current setup)
|
58 |
api_token = os.getenv("HF_API_TOKEN")
|
59 |
+
if api_token:
|
60 |
+
logger.info("β
Found HF_API_TOKEN")
|
61 |
|
62 |
+
# Method 2: Fallback to HF_TOKEN
|
63 |
if not api_token:
|
64 |
+
api_token = os.getenv("HF_TOKEN")
|
65 |
+
if api_token:
|
66 |
+
logger.info("β
Found HF_TOKEN")
|
67 |
|
68 |
# Method 3: Hugging Face CLI token (if logged in)
|
69 |
if not api_token:
|
70 |
try:
|
71 |
from huggingface_hub import get_token
|
72 |
api_token = get_token()
|
73 |
+
if api_token:
|
74 |
+
logger.info("β
Found CLI token")
|
75 |
except:
|
76 |
pass
|
77 |
|
78 |
if not api_token:
|
79 |
+
logger.warning("β οΈ No HF token found. Please set HF_API_TOKEN or HF_TOKEN in Spaces secrets.")
|
80 |
return None
|
81 |
|
82 |
try:
|
|
|
104 |
def safe_call(func_name: str, func, *args, **kwargs):
|
105 |
"""Spaces-optimized safe API calls."""
|
106 |
if not CLIENT:
|
107 |
+
return "β API client not available. Please check if HF_API_TOKEN or HF_TOKEN is set in Spaces secrets."
|
108 |
|
109 |
try:
|
110 |
logger.info(f"π {func_name}...")
|
|
|
455 |
else:
|
456 |
gr.HTML("""
|
457 |
<div class="status-indicator status-error">
|
458 |
+
β <strong>Status:</strong> Please set HF_API_TOKEN or HF_TOKEN in Spaces settings
|
459 |
</div>
|
460 |
""")
|
461 |
|
|
|
619 |
|
620 |
**To use this Space:**
|
621 |
1. Go to **Settings** β **Repository secrets**
|
622 |
+
2. Add **HF_API_TOKEN** (or **HF_TOKEN**) with your Hugging Face token
|
623 |
3. Get your token at: [https://huggingface.co/settings/tokens](https://huggingface.co/settings/tokens)
|
624 |
|
625 |
**Features:**
|