kbarnard Claude Sonnet 5 commited on
Commit
10dfca6
·
1 Parent(s): ba52bae

Modernize: pin CPU torch, download weights from model repo

Browse files

Preventive fix for the same failure mode hitting other spaces in this
org: unpinned ultralytics/torch pulls full CUDA wheels on cpu-basic
hardware. Pin CPU-only torch/torchvision and a stable ultralytics
version, redirect framework caches to /tmp, and load the model from
the FathomNet/megalodon-2023-yolov8 model repo via huggingface_hub
instead of bundling the weight file. Bump gradio to 6.9.0.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

Files changed (4) hide show
  1. README.md +1 -1
  2. app.py +16 -2
  3. best.pt +0 -3
  4. requirements.txt +5 -1
README.md CHANGED
@@ -4,7 +4,7 @@ emoji: 🦈
4
  colorFrom: green
5
  colorTo: blue
6
  sdk: gradio
7
- sdk_version: 4.36.1
8
  app_file: app.py
9
  pinned: true
10
  license: cc-by-4.0
 
4
  colorFrom: green
5
  colorTo: blue
6
  sdk: gradio
7
+ sdk_version: 6.9.0
8
  app_file: app.py
9
  pinned: true
10
  license: cc-by-4.0
app.py CHANGED
@@ -1,9 +1,23 @@
 
 
 
 
 
 
 
 
 
 
1
  import glob
2
  import gradio as gr
 
3
  from ultralytics import YOLO
4
 
5
- model_path = "best.pt"
6
- model = YOLO(model_path)
 
 
 
7
 
8
 
9
  PREDICT_KWARGS = {
 
1
+ import os
2
+
3
+ # Keep framework caches on ephemeral scratch space rather than the Space's
4
+ # persistent disk, to avoid exceeding the storage quota:
5
+ # https://discuss.huggingface.co/t/how-to-fix-workload-evicted-storage-limit-exceeded-50g-error-in-huggingface-spaces/169258
6
+ os.environ.setdefault("TORCH_HOME", "/tmp/torch_cache")
7
+ os.environ.setdefault("HUB_DIR", "/tmp/torch_hub")
8
+ os.environ.setdefault("HF_HOME", "/tmp/hf_home")
9
+ os.environ.setdefault("TMPDIR", "/tmp")
10
+
11
  import glob
12
  import gradio as gr
13
+ from huggingface_hub import hf_hub_download
14
  from ultralytics import YOLO
15
 
16
+ MODEL_PATH = hf_hub_download(
17
+ repo_id="FathomNet/megalodon-2023-yolov8",
18
+ filename="mbari-megalodon-yolov8x.pt",
19
+ )
20
+ model = YOLO(MODEL_PATH)
21
 
22
 
23
  PREDICT_KWARGS = {
best.pt DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:24fe6d9808fdd44b64d2fbfc23bbe6455520eb7b392d3664c92cbcdf88a09196
3
- size 136714110
 
 
 
 
requirements.txt CHANGED
@@ -1 +1,5 @@
1
- ultralytics==8.0.158
 
 
 
 
 
1
+ --extra-index-url https://download.pytorch.org/whl/cpu
2
+ torch==2.14.0
3
+ torchvision==0.29.0
4
+ ultralytics==8.3.108
5
+ huggingface_hub