Simmonstt commited on
Commit
17541bf
·
verified ·
1 Parent(s): d320d1e

Add GPU support via spaces module

Browse files
Files changed (2) hide show
  1. app.py +17 -1
  2. requirements.txt +6 -6
app.py CHANGED
@@ -42,6 +42,21 @@ except Exception as e:
42
  print(f"Error importing gradio: {e}")
43
  GRADIO_AVAILABLE = False
44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
 
46
  # =============================================================================
47
  # 配置
@@ -196,8 +211,9 @@ def update_sample_gallery(task: str, combo: str):
196
  return images[0][0], f"Sample: {sample_info['subject_id']} | Label: {sample_info.get('diag_group', 'N/A')}"
197
 
198
 
 
199
  def run_inference(task: str, combo: str):
200
- """执行推理"""
201
  engine = get_inference_engine()
202
 
203
  if not engine:
 
42
  print(f"Error importing gradio: {e}")
43
  GRADIO_AVAILABLE = False
44
 
45
+ # HuggingFace Spaces GPU 支持
46
+ try:
47
+ import spaces
48
+ GPU_AVAILABLE = True
49
+ print("GPU support enabled via spaces module")
50
+ except ImportError:
51
+ GPU_AVAILABLE = False
52
+ print("spaces module not available (CPU mode)")
53
+ # 创建假的装饰器
54
+ class FakeSpaces:
55
+ @staticmethod
56
+ def GPU(func):
57
+ return func
58
+ spaces = FakeSpaces()
59
+
60
 
61
  # =============================================================================
62
  # 配置
 
211
  return images[0][0], f"Sample: {sample_info['subject_id']} | Label: {sample_info.get('diag_group', 'N/A')}"
212
 
213
 
214
+ @spaces.GPU
215
  def run_inference(task: str, combo: str):
216
+ """执行推理 (GPU accelerated)"""
217
  engine = get_inference_engine()
218
 
219
  if not engine:
requirements.txt CHANGED
@@ -1,16 +1,16 @@
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
13
 
 
 
 
14
  # Medical imaging
15
  nibabel>=4.0.0
16
  torchio>=0.18.95
 
1
+ # Brainanytime Hugging Face Space Requirements
2
  #
3
+ # IMPORTANT: Gradio and huggingface-hub are pre-installed by Hugging Face
4
+ # Do NOT include them here to avoid version conflicts
 
 
 
5
 
6
  # Core dependencies
7
  torch>=2.0.0
8
  torchvision>=0.15.0
9
  numpy>=1.24.0
10
 
11
+ # HuggingFace Spaces GPU support
12
+ spaces>=0.30.0
13
+
14
  # Medical imaging
15
  nibabel>=4.0.0
16
  torchio>=0.18.95