Spaces:
Running on Zero
Running on Zero
Fix huggingface_hub compatibility issue, upgrade Gradio SDK to 5.29.0
Browse files- README.md +1 -1
- app.py +17 -6
- requirements.txt +6 -7
README.md
CHANGED
|
@@ -4,7 +4,7 @@ emoji: 🧠
|
|
| 4 |
colorFrom: purple
|
| 5 |
colorTo: yellow
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
python_version: '3.10'
|
| 9 |
app_file: app.py
|
| 10 |
pinned: false
|
|
|
|
| 4 |
colorFrom: purple
|
| 5 |
colorTo: yellow
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 5.29.0
|
| 8 |
python_version: '3.10'
|
| 9 |
app_file: app.py
|
| 10 |
pinned: false
|
app.py
CHANGED
|
@@ -11,10 +11,8 @@ import sys
|
|
| 11 |
import json
|
| 12 |
from pathlib import Path
|
| 13 |
from typing import Dict, List, Optional, Tuple
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
import numpy as np
|
| 17 |
-
from PIL import Image
|
| 18 |
|
| 19 |
# 添加当前目录到路径(用于导入 inference_engine)
|
| 20 |
BASE_DIR = Path(__file__).parent
|
|
@@ -30,10 +28,20 @@ try:
|
|
| 30 |
format_result,
|
| 31 |
)
|
| 32 |
INFERENCE_AVAILABLE = True
|
| 33 |
-
except
|
| 34 |
print(f"Warning: Inference engine not available: {e}")
|
| 35 |
INFERENCE_AVAILABLE = False
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
# =============================================================================
|
| 39 |
# 配置
|
|
@@ -269,9 +277,12 @@ def format_prediction(result: Dict) -> str:
|
|
| 269 |
# 创建 Gradio 界面
|
| 270 |
# =============================================================================
|
| 271 |
|
| 272 |
-
def create_demo()
|
| 273 |
"""创建 Gradio Demo 界面"""
|
| 274 |
|
|
|
|
|
|
|
|
|
|
| 275 |
with gr.Blocks(
|
| 276 |
title="BrainAnytime Demo",
|
| 277 |
css="""
|
|
|
|
| 11 |
import json
|
| 12 |
from pathlib import Path
|
| 13 |
from typing import Dict, List, Optional, Tuple
|
| 14 |
+
import warnings
|
| 15 |
+
warnings.filterwarnings("ignore")
|
|
|
|
|
|
|
| 16 |
|
| 17 |
# 添加当前目录到路径(用于导入 inference_engine)
|
| 18 |
BASE_DIR = Path(__file__).parent
|
|
|
|
| 28 |
format_result,
|
| 29 |
)
|
| 30 |
INFERENCE_AVAILABLE = True
|
| 31 |
+
except Exception as e:
|
| 32 |
print(f"Warning: Inference engine not available: {e}")
|
| 33 |
INFERENCE_AVAILABLE = False
|
| 34 |
|
| 35 |
+
# 延迟导入 Gradio(避免启动时的循环导入问题)
|
| 36 |
+
try:
|
| 37 |
+
import gradio as gr
|
| 38 |
+
import numpy as np
|
| 39 |
+
from PIL import Image
|
| 40 |
+
GRADIO_AVAILABLE = True
|
| 41 |
+
except Exception as e:
|
| 42 |
+
print(f"Error importing gradio: {e}")
|
| 43 |
+
GRADIO_AVAILABLE = False
|
| 44 |
+
|
| 45 |
|
| 46 |
# =============================================================================
|
| 47 |
# 配置
|
|
|
|
| 277 |
# 创建 Gradio 界面
|
| 278 |
# =============================================================================
|
| 279 |
|
| 280 |
+
def create_demo():
|
| 281 |
"""创建 Gradio Demo 界面"""
|
| 282 |
|
| 283 |
+
if not GRADIO_AVAILABLE:
|
| 284 |
+
raise RuntimeError("Gradio is not available. Cannot create demo.")
|
| 285 |
+
|
| 286 |
with gr.Blocks(
|
| 287 |
title="BrainAnytime Demo",
|
| 288 |
css="""
|
requirements.txt
CHANGED
|
@@ -1,7 +1,12 @@
|
|
| 1 |
# BrainAnytime Hugging Face Space Requirements
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
# Core dependencies
|
| 4 |
-
# Note: Gradio is pre-installed by Hugging Face (version controlled via README.md sdk_version)
|
| 5 |
torch>=2.0.0
|
| 6 |
torchvision>=0.15.0
|
| 7 |
numpy>=1.24.0
|
|
@@ -14,9 +19,6 @@ torchio>=0.18.95
|
|
| 14 |
timm>=0.9.0
|
| 15 |
einops>=0.6.0
|
| 16 |
|
| 17 |
-
# Hugging Face Hub for model download
|
| 18 |
-
huggingface-hub>=0.16.0
|
| 19 |
-
|
| 20 |
# Data processing
|
| 21 |
pandas>=2.0.0
|
| 22 |
scikit-learn>=1.3.0
|
|
@@ -25,6 +27,3 @@ scipy>=1.10.0
|
|
| 25 |
# Visualization
|
| 26 |
matplotlib>=3.7.0
|
| 27 |
Pillow>=10.0.0
|
| 28 |
-
|
| 29 |
-
# Optional: for advanced features
|
| 30 |
-
# tensorboardX>=2.6 # Only needed if logging
|
|
|
|
| 1 |
# BrainAnytime Hugging Face Space Requirements
|
| 2 |
+
#
|
| 3 |
+
# IMPORTANT: Gradio is pre-installed by Hugging Face (version controlled via README.md sdk_version)
|
| 4 |
+
# Do NOT include gradio here to avoid version conflicts
|
| 5 |
+
#
|
| 6 |
+
# NOTE: huggingface-hub is also pre-installed, we use the Space-provided version
|
| 7 |
+
# to avoid ImportError with HfFolder
|
| 8 |
|
| 9 |
# Core dependencies
|
|
|
|
| 10 |
torch>=2.0.0
|
| 11 |
torchvision>=0.15.0
|
| 12 |
numpy>=1.24.0
|
|
|
|
| 19 |
timm>=0.9.0
|
| 20 |
einops>=0.6.0
|
| 21 |
|
|
|
|
|
|
|
|
|
|
| 22 |
# Data processing
|
| 23 |
pandas>=2.0.0
|
| 24 |
scikit-learn>=1.3.0
|
|
|
|
| 27 |
# Visualization
|
| 28 |
matplotlib>=3.7.0
|
| 29 |
Pillow>=10.0.0
|
|
|
|
|
|
|
|
|