Spaces:
Runtime error
Runtime error
Commit
·
3e8e10c
1
Parent(s):
f8ce589
Fix: Optimize build to prevent OOM - download model at runtime instead of build time
Browse files- Dockerfile +2 -2
- app.py +25 -0
- requirements.txt +0 -2
Dockerfile
CHANGED
|
@@ -18,8 +18,8 @@ RUN pip install --no-cache-dir -r requirements.txt
|
|
| 18 |
# Copia el código de la aplicación
|
| 19 |
COPY . .
|
| 20 |
|
| 21 |
-
#
|
| 22 |
-
|
| 23 |
|
| 24 |
EXPOSE 7860
|
| 25 |
|
|
|
|
| 18 |
# Copia el código de la aplicación
|
| 19 |
COPY . .
|
| 20 |
|
| 21 |
+
# NO descargar el modelo aquí - se descarga en runtime
|
| 22 |
+
# Esto evita problemas de memoria durante el build
|
| 23 |
|
| 24 |
EXPOSE 7860
|
| 25 |
|
app.py
CHANGED
|
@@ -21,12 +21,37 @@ async def startup_event():
|
|
| 21 |
logger.info("Starting up... initializing model.")
|
| 22 |
loop = asyncio.get_event_loop()
|
| 23 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
await loop.run_in_executor(None, server_wrapper.init_model)
|
| 25 |
logger.info("Model initialized successfully.")
|
| 26 |
except Exception as e:
|
| 27 |
logger.error(f"Error during model initialization: {e}")
|
| 28 |
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
@app.post("/api/reset")
|
| 31 |
async def api_reset():
|
| 32 |
try:
|
|
|
|
| 21 |
logger.info("Starting up... initializing model.")
|
| 22 |
loop = asyncio.get_event_loop()
|
| 23 |
try:
|
| 24 |
+
# First, ensure model is downloaded
|
| 25 |
+
logger.info("Downloading Whisper model if not already present...")
|
| 26 |
+
await loop.run_in_executor(None, _ensure_model_downloaded)
|
| 27 |
+
logger.info("Model ready.")
|
| 28 |
+
|
| 29 |
+
# Initialize the ASR model
|
| 30 |
await loop.run_in_executor(None, server_wrapper.init_model)
|
| 31 |
logger.info("Model initialized successfully.")
|
| 32 |
except Exception as e:
|
| 33 |
logger.error(f"Error during model initialization: {e}")
|
| 34 |
|
| 35 |
|
| 36 |
+
def _ensure_model_downloaded():
|
| 37 |
+
"""Ensure the Whisper model is downloaded."""
|
| 38 |
+
import os
|
| 39 |
+
model_dir = os.path.expanduser('~/.cache/whisper')
|
| 40 |
+
model_path = os.path.join(model_dir, 'large-v3.pt')
|
| 41 |
+
|
| 42 |
+
if not os.path.exists(model_path):
|
| 43 |
+
try:
|
| 44 |
+
logger.info(f"Downloading Whisper large-v3 model to {model_path}...")
|
| 45 |
+
import whisper
|
| 46 |
+
whisper.load_model('large-v3')
|
| 47 |
+
logger.info("Model downloaded successfully.")
|
| 48 |
+
except Exception as e:
|
| 49 |
+
logger.warning(f"Could not pre-download model: {e}")
|
| 50 |
+
logger.info("Will attempt to download on first use.")
|
| 51 |
+
else:
|
| 52 |
+
logger.info(f"Model already present at {model_path}")
|
| 53 |
+
|
| 54 |
+
|
| 55 |
@app.post("/api/reset")
|
| 56 |
async def api_reset():
|
| 57 |
try:
|
requirements.txt
CHANGED
|
@@ -5,9 +5,7 @@ soundfile>=0.12.0
|
|
| 5 |
librosa>=0.10.0
|
| 6 |
numpy>=1.24.0
|
| 7 |
torch>=2.0.0
|
| 8 |
-
transformers>=4.30.0
|
| 9 |
torchaudio>=2.0.0
|
| 10 |
tqdm
|
| 11 |
tiktoken
|
| 12 |
-
triton>=2.0.0,<3;platform_machine=="x86_64" and sys_platform=="linux" or sys_platform=="linux2"
|
| 13 |
openai-whisper>=20230314
|
|
|
|
| 5 |
librosa>=0.10.0
|
| 6 |
numpy>=1.24.0
|
| 7 |
torch>=2.0.0
|
|
|
|
| 8 |
torchaudio>=2.0.0
|
| 9 |
tqdm
|
| 10 |
tiktoken
|
|
|
|
| 11 |
openai-whisper>=20230314
|