Spaces:
Sleeping
Sleeping
Fix: let HF Spaces manage demo launch
Browse files
app.py
CHANGED
|
@@ -2,57 +2,25 @@
|
|
| 2 |
Hugging Face Spaces 入口文件
|
| 3 |
"""
|
| 4 |
import sys
|
| 5 |
-
import logging
|
| 6 |
-
import traceback
|
| 7 |
|
| 8 |
-
|
| 9 |
-
logger = logging.getLogger("spaces")
|
| 10 |
-
|
| 11 |
-
# --------------------------------------------------
|
| 12 |
-
# 补丁 1: pydub 依赖已移除的 audioop 模块 (Python 3.13)
|
| 13 |
-
# --------------------------------------------------
|
| 14 |
try:
|
| 15 |
import audioop_lts as audioop
|
| 16 |
sys.modules["pyaudioop"] = audioop
|
| 17 |
-
logger.info("✅ audioop patch applied")
|
| 18 |
except ImportError:
|
| 19 |
pass
|
| 20 |
|
| 21 |
-
# -
|
| 22 |
-
# 补丁 2: gradio[oauth] 依赖已移除的 HfFolder (huggingface-hub>=0.25)
|
| 23 |
-
# --------------------------------------------------
|
| 24 |
try:
|
| 25 |
import huggingface_hub
|
| 26 |
-
|
| 27 |
if not hasattr(huggingface_hub, "HfFolder"):
|
| 28 |
from huggingface_hub import HfApi, get_token
|
| 29 |
-
|
| 30 |
-
class HfFolderCompat:
|
| 31 |
-
@staticmethod
|
| 32 |
-
def get_token():
|
| 33 |
-
return get_token()
|
| 34 |
@staticmethod
|
| 35 |
-
def
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
os.environ.pop("HF_TOKEN", None)
|
| 41 |
-
|
| 42 |
-
huggingface_hub.HfFolder = HfFolderCompat
|
| 43 |
-
sys.modules["huggingface_hub"].HfFolder = HfFolderCompat
|
| 44 |
-
logger.info("✅ HfFolder patch applied")
|
| 45 |
-
except Exception as e:
|
| 46 |
-
logger.warning(f"HfFolder patch failed: {e}")
|
| 47 |
|
| 48 |
-
|
| 49 |
-
# 启动 Gradio
|
| 50 |
-
# --------------------------------------------------
|
| 51 |
-
try:
|
| 52 |
-
from webui import demo
|
| 53 |
-
logger.info("✅ Gradio demo loaded, launching...")
|
| 54 |
-
demo.launch(server_name="0.0.0.0", server_port=7860)
|
| 55 |
-
except Exception as e:
|
| 56 |
-
logger.error(f"❌ Failed to start: {e}")
|
| 57 |
-
traceback.print_exc()
|
| 58 |
-
sys.exit(1)
|
|
|
|
| 2 |
Hugging Face Spaces 入口文件
|
| 3 |
"""
|
| 4 |
import sys
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
# 补丁 1: audioop (Python 3.13)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
try:
|
| 8 |
import audioop_lts as audioop
|
| 9 |
sys.modules["pyaudioop"] = audioop
|
|
|
|
| 10 |
except ImportError:
|
| 11 |
pass
|
| 12 |
|
| 13 |
+
# 补丁 2: HfFolder (huggingface-hub>=0.25)
|
|
|
|
|
|
|
| 14 |
try:
|
| 15 |
import huggingface_hub
|
|
|
|
| 16 |
if not hasattr(huggingface_hub, "HfFolder"):
|
| 17 |
from huggingface_hub import HfApi, get_token
|
| 18 |
+
class _HfFolder:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
@staticmethod
|
| 20 |
+
def get_token(): return get_token()
|
| 21 |
+
huggingface_hub.HfFolder = _HfFolder
|
| 22 |
+
sys.modules["huggingface_hub"].HfFolder = _HfFolder
|
| 23 |
+
except Exception:
|
| 24 |
+
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
+
from webui import demo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|