Spaces:
Running on Zero
Running on Zero
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -18,12 +18,13 @@ if hf_token:
|
|
| 18 |
# every call into a GPU function burns quota. So call this exactly ONCE at boot
|
| 19 |
# with the smallest budget (1s), and keep all real generation on CPU below
|
| 20 |
# (NOT decorated). That way quota is only touched here, never per request.
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
| 27 |
|
| 28 |
|
| 29 |
# Model cache
|
|
@@ -43,11 +44,17 @@ def load_model(model_name):
|
|
| 43 |
return MODEL_CACHE[model_name]
|
| 44 |
|
| 45 |
|
| 46 |
-
# Pre-warm both models
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
|
| 53 |
def generate_audio(prompt, duration, steps, cfg_scale, seed, model_name):
|
|
|
|
| 18 |
# every call into a GPU function burns quota. So call this exactly ONCE at boot
|
| 19 |
# with the smallest budget (1s), and keep all real generation on CPU below
|
| 20 |
# (NOT decorated). That way quota is only touched here, never per request.
|
| 21 |
+
try:
|
| 22 |
+
@spaces.GPU(duration=1)
|
| 23 |
+
def _gpu_startup_touch():
|
| 24 |
+
return "ok"
|
| 25 |
+
_gpu_startup_touch()
|
| 26 |
+
except Exception as e:
|
| 27 |
+
print(f"Warning: ZeroGPU touch failed (running CPU-only): {e}")
|
| 28 |
|
| 29 |
|
| 30 |
# Model cache
|
|
|
|
| 44 |
return MODEL_CACHE[model_name]
|
| 45 |
|
| 46 |
|
| 47 |
+
# Pre-warm both models in background so the first user request is fast
|
| 48 |
+
# but the Gradio server starts immediately without waiting for downloads
|
| 49 |
+
import threading
|
| 50 |
+
|
| 51 |
+
def _prewarm():
|
| 52 |
+
print("Pre-warming models...")
|
| 53 |
+
for _name in ["small-music", "small-sfx"]:
|
| 54 |
+
load_model(_name)
|
| 55 |
+
print("All models ready!")
|
| 56 |
+
|
| 57 |
+
threading.Thread(target=_prewarm, daemon=True).start()
|
| 58 |
|
| 59 |
|
| 60 |
def generate_audio(prompt, duration, steps, cfg_scale, seed, model_name):
|