Spaces:
Running on Zero
Running on Zero
Check inputs before reserving the GPU, so a request the model cannot take spends none of the caller's allowance.
Browse files
app.py
CHANGED
|
@@ -134,15 +134,21 @@ model_card = ModelCard(
|
|
| 134 |
)
|
| 135 |
|
| 136 |
|
| 137 |
-
@spaces.GPU
|
| 138 |
-
@torch.inference_mode()
|
| 139 |
def process_fn(audio_path: str) -> str:
|
| 140 |
"""Runs the two-stage detector on an uploaded track and writes the verdict to a text file."""
|
|
|
|
|
|
|
| 141 |
if checkpoints_loading:
|
| 142 |
raise gr.Error("Model checkpoints are still downloading, please wait a moment and try again.")
|
| 143 |
if checkpoint_error:
|
| 144 |
raise gr.Error(f"Failed to download checkpoints: {checkpoint_error}")
|
| 145 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
result = inference(audio_path)
|
| 147 |
prediction = result.get("prediction", "Unknown")
|
| 148 |
confidence = result.get("confidence", "0.00")
|
|
|
|
| 134 |
)
|
| 135 |
|
| 136 |
|
|
|
|
|
|
|
| 137 |
def process_fn(audio_path: str) -> str:
|
| 138 |
"""Runs the two-stage detector on an uploaded track and writes the verdict to a text file."""
|
| 139 |
+
# Checked before the GPU is reserved, so a request that cannot run spends none of the
|
| 140 |
+
# caller's ZeroGPU allowance
|
| 141 |
if checkpoints_loading:
|
| 142 |
raise gr.Error("Model checkpoints are still downloading, please wait a moment and try again.")
|
| 143 |
if checkpoint_error:
|
| 144 |
raise gr.Error(f"Failed to download checkpoints: {checkpoint_error}")
|
| 145 |
|
| 146 |
+
return detect(audio_path)
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
@spaces.GPU
|
| 150 |
+
@torch.inference_mode()
|
| 151 |
+
def detect(audio_path: str) -> str:
|
| 152 |
result = inference(audio_path)
|
| 153 |
prediction = result.get("prediction", "Unknown")
|
| 154 |
confidence = result.get("confidence", "0.00")
|