pollitoconpapass
commited on
Commit
β’
f4c9a52
1
Parent(s):
5fa3c82
Add application file
Browse files- Dockerfile +26 -0
- README.md +1 -1
- app.py +18 -0
- docker-compose.yml +6 -0
- requirements.txt +7 -0
Dockerfile
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.12-slim
|
2 |
+
|
3 |
+
RUN apt-get update && apt-get install -y \
|
4 |
+
libsndfile1-dev \
|
5 |
+
build-essential \
|
6 |
+
libopenblas-dev \
|
7 |
+
&& rm -rf /var/lib/apt/lists/*
|
8 |
+
|
9 |
+
|
10 |
+
# Crear y configurar un usuario no root
|
11 |
+
RUN useradd -m -u 1000 user
|
12 |
+
USER user
|
13 |
+
ENV HOME=/home/user \
|
14 |
+
PATH=/home/user/.local/bin:$PATH
|
15 |
+
|
16 |
+
WORKDIR $HOME/app
|
17 |
+
|
18 |
+
ENV HF_HOME=$HOME/.cache
|
19 |
+
|
20 |
+
COPY --chown=user . $HOME/app
|
21 |
+
|
22 |
+
COPY requirements.txt .
|
23 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
24 |
+
|
25 |
+
|
26 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
---
|
2 |
title: Api Dockerized Whisper
|
3 |
-
emoji:
|
4 |
colorFrom: blue
|
5 |
colorTo: gray
|
6 |
sdk: docker
|
|
|
1 |
---
|
2 |
title: Api Dockerized Whisper
|
3 |
+
emoji: π
|
4 |
colorFrom: blue
|
5 |
colorTo: gray
|
6 |
sdk: docker
|
app.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import io
|
2 |
+
import librosa
|
3 |
+
from transformers import pipeline
|
4 |
+
from fastapi import FastAPI, File, UploadFile
|
5 |
+
|
6 |
+
|
7 |
+
app = FastAPI()
|
8 |
+
pipe = pipeline(model="pollitoconpapass/whisper-small-finetuned")
|
9 |
+
|
10 |
+
@app.post("/transcribe-whisper")
|
11 |
+
async def transcribe(audio: UploadFile = File(...)):
|
12 |
+
contents = await audio.read()
|
13 |
+
buffer = io.BytesIO(contents)
|
14 |
+
with buffer:
|
15 |
+
audio_array, _= librosa.load(buffer, sr=16000)
|
16 |
+
|
17 |
+
text = pipe(audio_array)["text"]
|
18 |
+
return {"text": text}
|
docker-compose.yml
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
version: '3.12'
|
2 |
+
services:
|
3 |
+
api-hf-whisper:
|
4 |
+
build: .
|
5 |
+
ports:
|
6 |
+
- "7860:7860"
|
requirements.txt
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
uvicorn==0.25.0
|
2 |
+
librosa==0.10.1
|
3 |
+
transformers==4.39.0
|
4 |
+
fastapi==0.108.0
|
5 |
+
soundfile==0.12.1
|
6 |
+
torch==2.3.0
|
7 |
+
python-multipart
|