Spaces:
Runtime error
Runtime error
Commit
·
7fceff6
1
Parent(s):
2bc3bc1
Fix: Update Whisper package and add error handling
Browse files- Dockerfile +5 -0
- app.py +30 -5
- requirements.txt +1 -1
Dockerfile
CHANGED
|
@@ -2,6 +2,11 @@ FROM python:3.10-slim
|
|
| 2 |
|
| 3 |
WORKDIR /code
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
COPY requirements.txt .
|
| 6 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 7 |
|
|
|
|
| 2 |
|
| 3 |
WORKDIR /code
|
| 4 |
|
| 5 |
+
# Install system dependencies
|
| 6 |
+
RUN apt-get update && apt-get install -y \
|
| 7 |
+
ffmpeg \
|
| 8 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 9 |
+
|
| 10 |
COPY requirements.txt .
|
| 11 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 12 |
|
app.py
CHANGED
|
@@ -1,16 +1,41 @@
|
|
| 1 |
-
from fastapi import FastAPI, UploadFile, File, Form
|
| 2 |
from fastapi.responses import JSONResponse
|
| 3 |
-
import whisper
|
| 4 |
import tempfile
|
| 5 |
import os
|
| 6 |
from transformers import pipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
app = FastAPI(title="TranscriptoCast AI (Demo)")
|
| 9 |
|
| 10 |
# Load models once at startup
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
@app.post("/transcribe")
|
| 16 |
async def transcribe(file: UploadFile = File(...)):
|
|
|
|
| 1 |
+
from fastapi import FastAPI, UploadFile, File, Form, HTTPException
|
| 2 |
from fastapi.responses import JSONResponse
|
| 3 |
+
import openai.whisper as whisper
|
| 4 |
import tempfile
|
| 5 |
import os
|
| 6 |
from transformers import pipeline
|
| 7 |
+
import logging
|
| 8 |
+
|
| 9 |
+
# Set up logging
|
| 10 |
+
logging.basicConfig(level=logging.INFO)
|
| 11 |
+
logger = logging.getLogger(__name__)
|
| 12 |
|
| 13 |
app = FastAPI(title="TranscriptoCast AI (Demo)")
|
| 14 |
|
| 15 |
# Load models once at startup
|
| 16 |
+
try:
|
| 17 |
+
logger.info("Loading Whisper model...")
|
| 18 |
+
whisper_model = whisper.load_model("base")
|
| 19 |
+
logger.info("Whisper model loaded successfully")
|
| 20 |
+
except Exception as e:
|
| 21 |
+
logger.error(f"Error loading Whisper model: {str(e)}")
|
| 22 |
+
raise HTTPException(status_code=500, detail="Failed to load Whisper model")
|
| 23 |
+
|
| 24 |
+
try:
|
| 25 |
+
logger.info("Loading summarization model...")
|
| 26 |
+
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 27 |
+
logger.info("Summarization model loaded successfully")
|
| 28 |
+
except Exception as e:
|
| 29 |
+
logger.error(f"Error loading summarization model: {str(e)}")
|
| 30 |
+
raise HTTPException(status_code=500, detail="Failed to load summarization model")
|
| 31 |
+
|
| 32 |
+
try:
|
| 33 |
+
logger.info("Loading translation model...")
|
| 34 |
+
translator = pipeline("translation", model="facebook/mbart-large-50-many-to-many-mmt")
|
| 35 |
+
logger.info("Translation model loaded successfully")
|
| 36 |
+
except Exception as e:
|
| 37 |
+
logger.error(f"Error loading translation model: {str(e)}")
|
| 38 |
+
raise HTTPException(status_code=500, detail="Failed to load translation model")
|
| 39 |
|
| 40 |
@app.post("/transcribe")
|
| 41 |
async def transcribe(file: UploadFile = File(...)):
|
requirements.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
fastapi
|
| 2 |
uvicorn
|
| 3 |
-
whisper
|
| 4 |
torch
|
| 5 |
transformers
|
| 6 |
pydantic
|
|
|
|
| 1 |
fastapi
|
| 2 |
uvicorn
|
| 3 |
+
openai-whisper
|
| 4 |
torch
|
| 5 |
transformers
|
| 6 |
pydantic
|