Spaces:
Sleeping
Sleeping
Auto-login with HF_TOKEN environment variable for Spaces
Browse files
app.py
CHANGED
|
@@ -13,6 +13,15 @@ import torch
|
|
| 13 |
from huggingface_hub import hf_hub_download, scan_cache_dir, login, whoami
|
| 14 |
from safetensors import safe_open
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
def hf_login(token: str):
|
| 18 |
"""Login to Hugging Face with provided token."""
|
|
@@ -382,7 +391,11 @@ with gr.Blocks(title="Hugging Face Model Weight Inspector") as demo:
|
|
| 382 |
gr.Markdown("# ๐ Hugging Face Model Weight Inspector")
|
| 383 |
|
| 384 |
# HF Login section
|
| 385 |
-
with gr.Accordion("๐ Hugging Face Login (
|
|
|
|
|
|
|
|
|
|
|
|
|
| 386 |
with gr.Row():
|
| 387 |
with gr.Column(scale=3):
|
| 388 |
hf_token_input = gr.Textbox(
|
|
|
|
| 13 |
from huggingface_hub import hf_hub_download, scan_cache_dir, login, whoami
|
| 14 |
from safetensors import safe_open
|
| 15 |
|
| 16 |
+
# Auto-login with HF_TOKEN if available (for HuggingFace Spaces)
|
| 17 |
+
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 18 |
+
if HF_TOKEN:
|
| 19 |
+
try:
|
| 20 |
+
login(token=HF_TOKEN, add_to_git_credential=False)
|
| 21 |
+
print("โ
Automatically logged in using HF_TOKEN")
|
| 22 |
+
except Exception as e:
|
| 23 |
+
print(f"โ ๏ธ Auto-login failed: {str(e)}")
|
| 24 |
+
|
| 25 |
|
| 26 |
def hf_login(token: str):
|
| 27 |
"""Login to Hugging Face with provided token."""
|
|
|
|
| 391 |
gr.Markdown("# ๐ Hugging Face Model Weight Inspector")
|
| 392 |
|
| 393 |
# HF Login section
|
| 394 |
+
with gr.Accordion("๐ Hugging Face Login (Optional - auto-login with HF_TOKEN)", open=False):
|
| 395 |
+
gr.Markdown("""
|
| 396 |
+
**Note:** This Space automatically uses the `HF_TOKEN` secret if configured.
|
| 397 |
+
Manual login below is only needed if you want to use a different token.
|
| 398 |
+
""")
|
| 399 |
with gr.Row():
|
| 400 |
with gr.Column(scale=3):
|
| 401 |
hf_token_input = gr.Textbox(
|