pollitoconpapass commited on
Commit
f6632f4
·
1 Parent(s): 3cd9186

Add application file

Browse files
Files changed (5) hide show
  1. Dockerfile +18 -0
  2. app.py +28 -0
  3. docker-compose.yml +6 -0
  4. endpoint.py +20 -0
  5. requirements.txt +7 -0
Dockerfile ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ WORKDIR /app
10
+
11
+ COPY requirements.txt .
12
+ RUN pip install --no-cache-dir -r requirements.txt
13
+
14
+ COPY . .
15
+
16
+ EXPOSE 8000
17
+
18
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000", "--log-level", "debug"]
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+
5
+ pipe = pipeline(model="pollitoconpapass/whisper-small-finetuned")
6
+
7
+ def transcribe(audio):
8
+ text = pipe(audio)["text"]
9
+ return text
10
+
11
+ iface = gr.Interface(
12
+ fn=transcribe,
13
+ inputs=gr.Audio(type="filepath"),
14
+ outputs="text",
15
+ title="Whisper Small Demo - ZLTech",
16
+ description='''
17
+ Realtime demo of speech recognition fine-tuned using Whisper small model. New implementation: Quechua language.
18
+
19
+
20
+ If you want to use this as an endpoint, go to endpoint.py.
21
+
22
+ Source: https://huggingface.co/pollitoconpapass/whisper-small-finetuned
23
+
24
+
25
+ '''
26
+ )
27
+
28
+ iface.launch()
docker-compose.yml ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ version: '3.12'
2
+ services:
3
+ whisper-api-dev:
4
+ build: .
5
+ ports:
6
+ - "8000:8000"
endpoint.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import io
2
+ import uvicorn
3
+ import librosa
4
+ from transformers import pipeline
5
+ from fastapi import FastAPI, File, UploadFile
6
+
7
+
8
+ app = FastAPI()
9
+ pipe = pipeline(model="pollitoconpapass/whisper-small-finetuned")
10
+
11
+ @app.post("/transcribe-whisper")
12
+ async def transcribe(audio: UploadFile = File(...)):
13
+ contents = await audio.read()
14
+ buffer = io.BytesIO(contents)
15
+ with buffer:
16
+ audio_array, _= librosa.load(buffer, sr=16000)
17
+
18
+ text = pipe(audio_array)["text"]
19
+ return {"text": text}
20
+
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