Spaces:
Sleeping
Sleeping
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -5,6 +5,29 @@ Dual-mode inference:
|
|
| 5 |
- Fallback: OpenAI API (user provides their own key)
|
| 6 |
"""
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
import json
|
| 9 |
import logging
|
| 10 |
import os
|
|
|
|
| 5 |
- Fallback: OpenAI API (user provides their own key)
|
| 6 |
"""
|
| 7 |
|
| 8 |
+
# ββ HfFolder compatibility shim ββββββββββββββββββββββββββββββββββββββββββ
|
| 9 |
+
# Gradio's oauth.py imports HfFolder from huggingface_hub, but HfFolder was
|
| 10 |
+
# removed in huggingface_hub >= 0.24. This shim must run BEFORE importing
|
| 11 |
+
# Gradio so the import chain doesn't break.
|
| 12 |
+
try:
|
| 13 |
+
from huggingface_hub import HfFolder # noqa: F401
|
| 14 |
+
except ImportError:
|
| 15 |
+
import huggingface_hub
|
| 16 |
+
|
| 17 |
+
class _HfFolder:
|
| 18 |
+
"""Minimal shim for the removed HfFolder class."""
|
| 19 |
+
|
| 20 |
+
@classmethod
|
| 21 |
+
def get_token(cls):
|
| 22 |
+
return huggingface_hub.get_token()
|
| 23 |
+
|
| 24 |
+
@classmethod
|
| 25 |
+
def save_token(cls, token):
|
| 26 |
+
huggingface_hub.login(token=token)
|
| 27 |
+
|
| 28 |
+
huggingface_hub.HfFolder = _HfFolder
|
| 29 |
+
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 30 |
+
|
| 31 |
import json
|
| 32 |
import logging
|
| 33 |
import os
|