Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,9 @@
|
|
| 2 |
# Active models: AST x3 and PaSST (AudioSet-527); optional CLAP and Silero VAD.
|
| 3 |
# This intentionally does not use the separate DCASE 2024 CRNN app/checkpoint.
|
| 4 |
|
|
|
|
|
|
|
|
|
|
| 5 |
import os
|
| 6 |
import sys
|
| 7 |
import glob
|
|
@@ -18,6 +21,7 @@ import matplotlib.pyplot as plt
|
|
| 18 |
import gradio as gr
|
| 19 |
|
| 20 |
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
|
| 21 |
MAX_SEC = int(os.getenv("MAX_SEC", "60"))
|
| 22 |
MAX_CELLS = int(os.getenv("MAX_CELLS", "1500"))
|
| 23 |
|
|
@@ -97,9 +101,9 @@ try:
|
|
| 97 |
def clap_logits(batch48, prompts):
|
| 98 |
kw = dict(text=prompts, return_tensors="pt", padding=True)
|
| 99 |
try:
|
| 100 |
-
inp = clap_proc(audio=list(batch48), **kw)
|
| 101 |
except TypeError:
|
| 102 |
-
inp = clap_proc(audios=list(batch48), **kw)
|
| 103 |
inp = {k: v.to(DEVICE) for k, v in inp.items()}
|
| 104 |
return clap_model(**inp).logits_per_audio.float().cpu().numpy() # scaled audio-text similarity (B, K)
|
| 105 |
|
|
@@ -384,6 +388,7 @@ def tag_windows(wavs, win_s, hop_s, dur):
|
|
| 384 |
return {f: np.mean(v, 0) for f, v in fam.items()}
|
| 385 |
|
| 386 |
|
|
|
|
| 387 |
def detect(audio_path, sens=0.0, win_s=2.0, hop_s=0.25, min_votes=2, use_vad=True, denoise=False,
|
| 388 |
discover=True, extra=""):
|
| 389 |
if audio_path is None:
|
|
|
|
| 2 |
# Active models: AST x3 and PaSST (AudioSet-527); optional CLAP and Silero VAD.
|
| 3 |
# This intentionally does not use the separate DCASE 2024 CRNN app/checkpoint.
|
| 4 |
|
| 5 |
+
# Required by Hugging Face ZeroGPU. Keep this before importing torch.
|
| 6 |
+
import spaces
|
| 7 |
+
|
| 8 |
import os
|
| 9 |
import sys
|
| 10 |
import glob
|
|
|
|
| 21 |
import gradio as gr
|
| 22 |
|
| 23 |
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
| 24 |
+
print(f"ZeroGPU-aware inference device: {DEVICE}")
|
| 25 |
MAX_SEC = int(os.getenv("MAX_SEC", "60"))
|
| 26 |
MAX_CELLS = int(os.getenv("MAX_CELLS", "1500"))
|
| 27 |
|
|
|
|
| 101 |
def clap_logits(batch48, prompts):
|
| 102 |
kw = dict(text=prompts, return_tensors="pt", padding=True)
|
| 103 |
try:
|
| 104 |
+
inp = clap_proc(audio=list(batch48), sampling_rate=48000, **kw) # recent transformers
|
| 105 |
except TypeError:
|
| 106 |
+
inp = clap_proc(audios=list(batch48), sampling_rate=48000, **kw) # compatibility fallback
|
| 107 |
inp = {k: v.to(DEVICE) for k, v in inp.items()}
|
| 108 |
return clap_model(**inp).logits_per_audio.float().cpu().numpy() # scaled audio-text similarity (B, K)
|
| 109 |
|
|
|
|
| 388 |
return {f: np.mean(v, 0) for f, v in fam.items()}
|
| 389 |
|
| 390 |
|
| 391 |
+
@spaces.GPU(duration=120)
|
| 392 |
def detect(audio_path, sens=0.0, win_s=2.0, hop_s=0.25, min_votes=2, use_vad=True, denoise=False,
|
| 393 |
discover=True, extra=""):
|
| 394 |
if audio_path is None:
|