Spaces:
Sleeping
Sleeping
Commit ·
f2128f9
1
Parent(s): d8dd7c0
fixes
Browse files
app.py
CHANGED
|
@@ -4,6 +4,9 @@ import numpy as np
|
|
| 4 |
import torch
|
| 5 |
import librosa
|
| 6 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
| 7 |
import matplotlib.pyplot as plt
|
| 8 |
|
| 9 |
from huggingface_hub import hf_hub_download
|
|
@@ -71,16 +74,16 @@ def _fig_to_rgb_array(fig):
|
|
| 71 |
|
| 72 |
@torch.inference_mode()
|
| 73 |
def get_model():
|
| 74 |
-
# Cache model as a function attribute (simple + Space-friendly)
|
| 75 |
if hasattr(get_model, "_model") and get_model._model is not None:
|
| 76 |
return get_model._model
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
|
|
|
| 84 |
|
| 85 |
|
| 86 |
def mel_to_image(mel_80_t):
|
|
@@ -128,9 +131,13 @@ def run_reconstruct(audio_path, chunk_size):
|
|
| 128 |
"""
|
| 129 |
if audio_path is None or str(audio_path).strip() == "":
|
| 130 |
return None, None, None, None
|
|
|
|
| 131 |
|
| 132 |
-
|
| 133 |
-
|
|
|
|
|
|
|
|
|
|
| 134 |
# Load input audio
|
| 135 |
x, _ = librosa.load(audio_path, sr=SAMPLE_RATE, mono=True)
|
| 136 |
|
|
@@ -202,5 +209,5 @@ with gr.Blocks() as demo:
|
|
| 202 |
)
|
| 203 |
|
| 204 |
demo.queue()
|
| 205 |
-
demo.launch(server_name="0.0.0.0", server_port=7860)
|
| 206 |
|
|
|
|
| 4 |
import torch
|
| 5 |
import librosa
|
| 6 |
import gradio as gr
|
| 7 |
+
|
| 8 |
+
import matplotlib
|
| 9 |
+
matplotlib.use("Agg")
|
| 10 |
import matplotlib.pyplot as plt
|
| 11 |
|
| 12 |
from huggingface_hub import hf_hub_download
|
|
|
|
| 74 |
|
| 75 |
@torch.inference_mode()
|
| 76 |
def get_model():
|
|
|
|
| 77 |
if hasattr(get_model, "_model") and get_model._model is not None:
|
| 78 |
return get_model._model
|
| 79 |
+
try:
|
| 80 |
+
ckpt_path = hf_hub_download(repo_id=MODEL_REPO_ID, filename=CKPT_FILENAME)
|
| 81 |
+
model = VocosVocoderModule.load_from_checkpoint(ckpt_path, map_location="cpu")
|
| 82 |
+
model.eval()
|
| 83 |
+
get_model._model = model
|
| 84 |
+
return model
|
| 85 |
+
except Exception as e:
|
| 86 |
+
raise RuntimeError(f"Model load failed: {e}")
|
| 87 |
|
| 88 |
|
| 89 |
def mel_to_image(mel_80_t):
|
|
|
|
| 131 |
"""
|
| 132 |
if audio_path is None or str(audio_path).strip() == "":
|
| 133 |
return None, None, None, None
|
| 134 |
+
|
| 135 |
|
| 136 |
+
try:
|
| 137 |
+
model = get_model()
|
| 138 |
+
except Exception as e:
|
| 139 |
+
return None, np.zeros((10,10,3), dtype=np.uint8), None, np.zeros((10,10,3), dtype=np.uint8)
|
| 140 |
+
|
| 141 |
# Load input audio
|
| 142 |
x, _ = librosa.load(audio_path, sr=SAMPLE_RATE, mono=True)
|
| 143 |
|
|
|
|
| 209 |
)
|
| 210 |
|
| 211 |
demo.queue()
|
| 212 |
+
demo.launch(server_name="0.0.0.0", server_port=int(os.environ.get("PORT", 7860)))
|
| 213 |
|