john221113 commited on
Commit
39e7de4
·
1 Parent(s): 9080c96

Fix PANNs checkpoint download

Browse files
Files changed (1) hide show
  1. api.py +11 -7
api.py CHANGED
@@ -5,21 +5,25 @@ Snare Scout API - Minimal Gradio
5
  import os
6
  import sys
7
  import gradio as gr
8
- import numpy as np
9
 
10
  sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
11
 
12
- # Download PANNs checkpoint if missing
13
- PANNS_PATH = "/root/panns_data/Cnn14_mAP=0.431.pth"
14
- if not os.path.exists(PANNS_PATH):
 
 
 
 
 
15
  import urllib.request
16
- os.makedirs("/root/panns_data", exist_ok=True)
17
- print("📥 Downloading PANNs checkpoint...")
18
  urllib.request.urlretrieve(
19
  "https://zenodo.org/record/3987831/files/Cnn14_mAP%3D0.431.pth?download=1",
20
- PANNS_PATH
21
  )
22
  print("✅ PANNs checkpoint ready!")
 
 
23
 
24
  DB_PATH = "library/snare_scout.sqlite"
25
  if not os.path.exists(DB_PATH):
 
5
  import os
6
  import sys
7
  import gradio as gr
 
8
 
9
  sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
10
 
11
+ # Set PANNs path BEFORE importing anything else
12
+ os.environ["PANNS_MODELS_PATH"] = "/root/panns_data"
13
+ PANNS_CHECKPOINT = "/root/panns_data/Cnn14_mAP=0.431.pth"
14
+
15
+ os.makedirs("/root/panns_data", exist_ok=True)
16
+
17
+ if not os.path.exists(PANNS_CHECKPOINT):
18
+ print("📥 Downloading PANNs checkpoint (~320MB)...")
19
  import urllib.request
 
 
20
  urllib.request.urlretrieve(
21
  "https://zenodo.org/record/3987831/files/Cnn14_mAP%3D0.431.pth?download=1",
22
+ PANNS_CHECKPOINT
23
  )
24
  print("✅ PANNs checkpoint ready!")
25
+ else:
26
+ print(f"✅ PANNs checkpoint exists: {os.path.getsize(PANNS_CHECKPOINT)} bytes")
27
 
28
  DB_PATH = "library/snare_scout.sqlite"
29
  if not os.path.exists(DB_PATH):