Spaces:
Runtime error
Runtime error
Pranjal12345
commited on
Commit
•
b4cbbe2
1
Parent(s):
e6606c8
dasdas
Browse files- Dockerfile +28 -0
- main.py +53 -0
- requirements.txt +7 -0
Dockerfile
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Use the official Python 3.9 image
|
2 |
+
FROM python:3.10
|
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 |
+
|
14 |
+
# Set up a new user named "user" with user ID 1000
|
15 |
+
RUN useradd -m -u 1000 user
|
16 |
+
# Switch to the "user" user
|
17 |
+
USER user
|
18 |
+
# Set home to the user's home directory
|
19 |
+
ENV HOME=/home/user \
|
20 |
+
PATH=/home/user/.local/bin:$PATH
|
21 |
+
|
22 |
+
# Set the working directory to the user's home directory
|
23 |
+
WORKDIR $HOME/app
|
24 |
+
|
25 |
+
# Copy the current directory contents into the container at $HOME/app setting the owner to the user
|
26 |
+
COPY --chown=user . $HOME/app
|
27 |
+
|
28 |
+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
main.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#uvicorn app:app --host 0.0.0.0 --port 8000 --reload
|
2 |
+
|
3 |
+
# from fastapi import FastAPI
|
4 |
+
# from transformers import pipeline
|
5 |
+
|
6 |
+
# pipe = pipeline("automatic-speech-recognition", model="Pranjal12345/whisper-small-ne-pranjal")
|
7 |
+
|
8 |
+
# audio_path = "/home/pranjal/Downloads/chinese_audio.mp3"
|
9 |
+
|
10 |
+
# with open("/home/pranjal/Downloads/chinese_audio.mp3", "rb") as audio_file:
|
11 |
+
# audio_data = audio_file.read()
|
12 |
+
|
13 |
+
# app = FastAPI()
|
14 |
+
|
15 |
+
# @app.get("/")
|
16 |
+
# def hello():
|
17 |
+
# output = pipe(input)
|
18 |
+
# return {"Output": output}
|
19 |
+
|
20 |
+
|
21 |
+
|
22 |
+
|
23 |
+
|
24 |
+
|
25 |
+
from fastapi import FastAPI
|
26 |
+
from transformers import WhisperProcessor, WhisperForConditionalGeneration
|
27 |
+
import librosa
|
28 |
+
|
29 |
+
app = FastAPI()
|
30 |
+
|
31 |
+
# Load model and processor
|
32 |
+
processor = WhisperProcessor.from_pretrained("openai/whisper-small")
|
33 |
+
model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-small")
|
34 |
+
model.config.forced_decoder_ids = None
|
35 |
+
|
36 |
+
# Path to your audio file
|
37 |
+
audio_file_path = "/home/pranjal/Downloads/output.mp3"
|
38 |
+
|
39 |
+
# Read the audio file
|
40 |
+
audio_data, _ = librosa.load(audio_file_path, sr=16000)
|
41 |
+
|
42 |
+
@app.get("/")
|
43 |
+
def transcribe_audio():
|
44 |
+
# Process the audio data using the Whisper processor
|
45 |
+
input_features = processor(audio_data.tolist(), return_tensors="pt").input_features
|
46 |
+
|
47 |
+
# Generate transcription
|
48 |
+
predicted_ids = model.generate(input_features)
|
49 |
+
transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)
|
50 |
+
|
51 |
+
return {"transcription": transcription[0]}
|
52 |
+
|
53 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
librosa
|
2 |
+
soundfile
|
3 |
+
datasets
|
4 |
+
fastapi
|
5 |
+
uvicorn
|
6 |
+
transformers
|
7 |
+
Torch
|