Spaces:
Sleeping
Sleeping
Hugo Rodrigues
commited on
Commit
·
d193f9f
1
Parent(s):
8af4d3d
whisper test
Browse files- .gitignore +22 -0
- Dockerfile +27 -0
- README.md +10 -2
- main.py +47 -0
- packages.txt +1 -0
- requirements.txt +9 -0
- test5.wav +0 -0
.gitignore
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Build Artifacts
|
| 2 |
+
build/
|
| 3 |
+
|
| 4 |
+
# Core Dumps
|
| 5 |
+
core
|
| 6 |
+
|
| 7 |
+
# Byte-Compiled Modules
|
| 8 |
+
__pycache__/
|
| 9 |
+
|
| 10 |
+
# Extension Modules
|
| 11 |
+
*.so
|
| 12 |
+
|
| 13 |
+
# Packaging Artifacts
|
| 14 |
+
*.egg-info
|
| 15 |
+
*.whl
|
| 16 |
+
|
| 17 |
+
# IDEs and Tools
|
| 18 |
+
.idea/
|
| 19 |
+
.gdb_history
|
| 20 |
+
.vscode/
|
| 21 |
+
# Other
|
| 22 |
+
.DS_Store
|
Dockerfile
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use the official Python 3.9 image
|
| 2 |
+
FROM python:3.9
|
| 3 |
+
|
| 4 |
+
# Set the working directory to /code
|
| 5 |
+
WORKDIR /code
|
| 6 |
+
|
| 7 |
+
# Copy the current directory contents into the container at /code
|
| 8 |
+
COPY ./requirements.txt /code/requirements.txt
|
| 9 |
+
|
| 10 |
+
# Install requirements.txt
|
| 11 |
+
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
| 12 |
+
|
| 13 |
+
# Set up a new user named "user" with user ID 1000
|
| 14 |
+
RUN useradd -m -u 1000 user
|
| 15 |
+
# Switch to the "user" user
|
| 16 |
+
USER user
|
| 17 |
+
# Set home to the user's home directory
|
| 18 |
+
ENV HOME=/home/user \
|
| 19 |
+
PATH=/home/user/.local/bin:$PATH
|
| 20 |
+
|
| 21 |
+
# Set the working directory to the user's home directory
|
| 22 |
+
WORKDIR $HOME/app
|
| 23 |
+
|
| 24 |
+
# Copy the current directory contents into the container at $HOME/app setting the owner to the user
|
| 25 |
+
COPY --chown=user . $HOME/app
|
| 26 |
+
|
| 27 |
+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
README.md
CHANGED
|
@@ -1,11 +1,19 @@
|
|
| 1 |
---
|
| 2 |
title: Whisper
|
| 3 |
emoji: 🚀
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: docker
|
| 7 |
pinned: false
|
| 8 |
license: apache-2.0
|
| 9 |
---
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
title: Whisper
|
| 3 |
emoji: 🚀
|
| 4 |
+
colorFrom: cyan
|
| 5 |
+
colorTo: cyan
|
| 6 |
sdk: docker
|
| 7 |
pinned: false
|
| 8 |
license: apache-2.0
|
| 9 |
---
|
| 10 |
|
| 11 |
+
# Whisper
|
| 12 |
+
|
| 13 |
+
## TODO
|
| 14 |
+
|
| 15 |
+
- Provide api to use whisper
|
| 16 |
+
|
| 17 |
+
- Deploy whisper on GPU
|
| 18 |
+
|
| 19 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
main.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Union
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
from fastapi import FastAPI
|
| 4 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 5 |
+
|
| 6 |
+
from fastapi.staticfiles import StaticFiles
|
| 7 |
+
from fastapi.responses import FileResponse
|
| 8 |
+
|
| 9 |
+
import torch
|
| 10 |
+
from transformers import pipeline
|
| 11 |
+
|
| 12 |
+
app = FastAPI(docs_url="/api/docs")
|
| 13 |
+
|
| 14 |
+
app.add_middleware(
|
| 15 |
+
CORSMiddleware,
|
| 16 |
+
allow_origins=["*"],
|
| 17 |
+
allow_methods=["*"],
|
| 18 |
+
allow_headers=["*"],
|
| 19 |
+
allow_credentials=True,
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
| 23 |
+
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
|
| 24 |
+
|
| 25 |
+
BATCH_SIZE = 8
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
pipe = pipeline("automatic-speech-recognition",
|
| 29 |
+
"openai/whisper-large-v3",
|
| 30 |
+
torch_dtype=torch_dtype,
|
| 31 |
+
device=device)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
@app.get("/device")
|
| 35 |
+
def getDevice():
|
| 36 |
+
return device
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
@app.get("/transcribe")
|
| 40 |
+
def transcribe(inputs, task):
|
| 41 |
+
if inputs is None:
|
| 42 |
+
raise "No audio file submitted! Please upload or record an audio file before submitting your request."
|
| 43 |
+
|
| 44 |
+
text = pipe(inputs, batch_size=BATCH_SIZE, generate_kwargs={
|
| 45 |
+
"task": task}, return_timestamps=True)["text"]
|
| 46 |
+
|
| 47 |
+
return text
|
packages.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
ffmpeg
|
requirements.txt
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi
|
| 2 |
+
pydantic
|
| 3 |
+
typing
|
| 4 |
+
transformers
|
| 5 |
+
torch
|
| 6 |
+
requests
|
| 7 |
+
sentencepiece
|
| 8 |
+
uvicorn[standard]
|
| 9 |
+
ffmpeg
|
test5.wav
ADDED
|
Binary file (423 kB). View file
|
|
|