Spaces:
Running on Zero
Running on Zero
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -10,12 +10,19 @@ import spaces # <-- CRITICAL: Required for Hugging Face ZeroGPU
|
|
| 10 |
# Setup paths and dependencies
|
| 11 |
if not os.path.exists("DESED_task"):
|
| 12 |
os.system("git clone https://github.com/DCASE-REPO/DESED_task.git")
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
try:
|
| 16 |
from local.module import SEDTask4
|
| 17 |
except ImportError as e:
|
| 18 |
-
print("Import Error:", e)
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
# Download missing BEATs model if it isn't in the Space
|
| 21 |
beats_path = "BEATs_iter3_plus_AS2M.pt"
|
|
@@ -55,7 +62,7 @@ def process_audio(audio_file):
|
|
| 55 |
return "Error: Model failed to load during startup. Check the 'Logs' tab for details."
|
| 56 |
|
| 57 |
try:
|
| 58 |
-
#
|
| 59 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 60 |
model.to(device)
|
| 61 |
|
|
|
|
| 10 |
# Setup paths and dependencies
|
| 11 |
if not os.path.exists("DESED_task"):
|
| 12 |
os.system("git clone https://github.com/DCASE-REPO/DESED_task.git")
|
| 13 |
+
|
| 14 |
+
# FIX: Use insert(0, ...) instead of append() to prevent name collisions
|
| 15 |
+
# with any existing system packages named 'local'
|
| 16 |
+
recipe_dir = os.path.abspath("DESED_task/recipes/dcase2024_task4_baseline")
|
| 17 |
+
sys.path.insert(0, recipe_dir)
|
| 18 |
|
| 19 |
try:
|
| 20 |
from local.module import SEDTask4
|
| 21 |
except ImportError as e:
|
| 22 |
+
print("CRITICAL Import Error:", e)
|
| 23 |
+
# Ultimate fallback if absolute path resolution behaves differently in Docker
|
| 24 |
+
sys.path.insert(0, "/home/user/app/DESED_task/recipes/dcase2024_task4_baseline")
|
| 25 |
+
from local.module import SEDTask4
|
| 26 |
|
| 27 |
# Download missing BEATs model if it isn't in the Space
|
| 28 |
beats_path = "BEATs_iter3_plus_AS2M.pt"
|
|
|
|
| 62 |
return "Error: Model failed to load during startup. Check the 'Logs' tab for details."
|
| 63 |
|
| 64 |
try:
|
| 65 |
+
# Move model to GPU inside the decorated function
|
| 66 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 67 |
model.to(device)
|
| 68 |
|