Spaces:
Sleeping
Sleeping
Commit
·
f8e3c2f
1
Parent(s):
0faa266
Add application file
Browse files- Dockerfile +29 -7
- main.py +33 -5
- models/models will be saved here.txt +0 -0
- outputs/outputs are saved here.txt +0 -0
- outputs/translations/outputs for translation are saved here.txt +0 -0
- requirements.txt +14 -0
Dockerfile
CHANGED
|
@@ -1,13 +1,35 @@
|
|
| 1 |
-
FROM
|
| 2 |
|
| 3 |
-
RUN
|
| 4 |
-
|
| 5 |
-
|
|
|
|
| 6 |
|
| 7 |
-
WORKDIR /
|
| 8 |
|
| 9 |
-
COPY
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
COPY --chown=user . /app
|
| 13 |
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
| 1 |
+
FROM debian:bookworm-slim AS builder
|
| 2 |
|
| 3 |
+
RUN apt-get update && \
|
| 4 |
+
apt-get install -y curl git python3 python3-pip python3-venv && \
|
| 5 |
+
rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/* && \
|
| 6 |
+
mkdir -p /Whisper-WebUI
|
| 7 |
|
| 8 |
+
WORKDIR /Whisper-WebUI
|
| 9 |
|
| 10 |
+
COPY requirements.txt .
|
| 11 |
+
|
| 12 |
+
RUN python3 -m venv venv && \
|
| 13 |
+
. venv/bin/activate && \
|
| 14 |
+
pip install --no-cache-dir -r requirements.txt
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
FROM debian:bookworm-slim AS runtime
|
| 18 |
+
|
| 19 |
+
RUN apt-get update && \
|
| 20 |
+
apt-get install -y curl ffmpeg python3 && \
|
| 21 |
+
rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*
|
| 22 |
+
|
| 23 |
+
WORKDIR /Whisper-WebUI
|
| 24 |
+
|
| 25 |
+
COPY . .
|
| 26 |
+
COPY --from=builder /Whisper-WebUI/venv /Whisper-WebUI/venv
|
| 27 |
+
|
| 28 |
+
VOLUME [ "/Whisper-WebUI/models" ]
|
| 29 |
+
VOLUME [ "/Whisper-WebUI/outputs" ]
|
| 30 |
+
|
| 31 |
+
ENV PATH="/Whisper-WebUI/venv/bin:$PATH"
|
| 32 |
+
ENV LD_LIBRARY_PATH=/Whisper-WebUI/venv/lib64/python3.11/site-packages/nvidia/cublas/lib:/Whisper-WebUI/venv/lib64/python3.11/site-packages/nvidia/cudnn/lib
|
| 33 |
|
| 34 |
COPY --chown=user . /app
|
| 35 |
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
main.py
CHANGED
|
@@ -1,10 +1,38 @@
|
|
| 1 |
-
from fastapi import FastAPI
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
app = FastAPI()
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
"""
|
| 8 |
-
|
| 9 |
"""
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, File, UploadFile
|
| 2 |
+
from fastapi.responses import FileResponse
|
| 3 |
+
import os
|
| 4 |
+
import shutil
|
| 5 |
+
from modules.whisper.whisper_factory import WhisperFactory
|
| 6 |
|
| 7 |
app = FastAPI()
|
| 8 |
|
| 9 |
+
# Initialize Whisper inference engine
|
| 10 |
+
whisper_inf = WhisperFactory.create_whisper_inference(
|
| 11 |
+
whisper_type="faster-whisper",
|
| 12 |
+
whisper_model_dir=os.path.join("models", "Whisper"),
|
| 13 |
+
faster_whisper_model_dir=os.path.join("models", "Whisper", "faster-whisper"),
|
| 14 |
+
insanely_fast_whisper_model_dir=os.path.join("models", "Whisper", "insanely-fast-whisper"),
|
| 15 |
+
output_dir=os.path.join("outputs"),
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
@app.post("/upload-video/")
|
| 19 |
+
async def upload_video(file: UploadFile = File(...)):
|
| 20 |
"""
|
| 21 |
+
Upload a video file and get the generated SRT file as a response.
|
| 22 |
"""
|
| 23 |
+
# Save the uploaded video file temporarily
|
| 24 |
+
input_video_path = os.path.join("temp", file.filename)
|
| 25 |
+
os.makedirs("temp", exist_ok=True)
|
| 26 |
+
|
| 27 |
+
with open(input_video_path, "wb") as buffer:
|
| 28 |
+
shutil.copyfileobj(file.file, buffer)
|
| 29 |
+
|
| 30 |
+
# Generate the subtitle file
|
| 31 |
+
output_srt_path = whisper_inf.transcribe_file(
|
| 32 |
+
input_video_path,
|
| 33 |
+
file_format="SRT",
|
| 34 |
+
add_timestamp=True
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
# Return the SRT file as a response
|
| 38 |
+
return FileResponse(path=output_srt_path, filename=os.path.basename(output_srt_path))
|
models/models will be saved here.txt
ADDED
|
File without changes
|
outputs/outputs are saved here.txt
ADDED
|
File without changes
|
outputs/translations/outputs for translation are saved here.txt
ADDED
|
File without changes
|
requirements.txt
CHANGED
|
@@ -1,2 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
fastapi
|
| 2 |
uvicorn
|
|
|
|
| 1 |
+
# Remove the --extra-index-url line below if you're not using Nvidia GPU.
|
| 2 |
+
# If you're using it, update url to your CUDA version (CUDA 12.1 is minimum requirement):
|
| 3 |
+
# For CUDA 12.1, use : https://download.pytorch.org/whl/cu121
|
| 4 |
+
# For CUDA 12.4, use : https://download.pytorch.org/whl/cu124
|
| 5 |
+
--extra-index-url https://download.pytorch.org/whl/cu124
|
| 6 |
+
|
| 7 |
+
torch
|
| 8 |
+
git+https://github.com/jhj0517/jhj0517-whisper.git
|
| 9 |
+
faster-whisper==1.0.3
|
| 10 |
+
transformers==4.42.3
|
| 11 |
+
gradio==4.29.0
|
| 12 |
+
pytubefix
|
| 13 |
+
pyannote.audio==3.3.1
|
| 14 |
+
|
| 15 |
fastapi
|
| 16 |
uvicorn
|