BjarneBepaData commited on
Commit
ea6da0f
1 Parent(s): dd7cd5f

Added whisper as a model, time to turn on the GPUs

Browse files
Files changed (3) hide show
  1. Dockerfile +8 -1
  2. app/whisper.py +35 -0
  3. requirements.txt +2 -3
Dockerfile CHANGED
@@ -1,5 +1,12 @@
1
  #
2
- FROM python:3.9
 
 
 
 
 
 
 
3
 
4
  #
5
  WORKDIR /code
 
1
  #
2
+ FROM nvidia/cuda:12.4.1-runtime-ubuntu22.04
3
+
4
+ # Install python and pip
5
+ RUN apt-get update && apt-get install -y python3 python3-pip
6
+
7
+ # The commands as another prerequisite
8
+ RUN pip install --upgrade pip
9
+ RUN pip install --upgrade git+https://github.com/huggingface/transformers.git accelerate datasets[audio]
10
 
11
  #
12
  WORKDIR /code
app/whisper.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
3
+
4
+ device = "cuda:0" if torch.cuda.is_available() else "cpu"
5
+ torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
6
+
7
+ model_id = "openai/whisper-large-v3"
8
+
9
+ model = AutoModelForSpeechSeq2Seq.from_pretrained(
10
+ model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True
11
+ )
12
+ model.to(device)
13
+
14
+ processor = AutoProcessor.from_pretrained(model_id)
15
+
16
+ pipe = pipeline(
17
+ "automatic-speech-recognition",
18
+ model=model,
19
+ tokenizer=processor.tokenizer,
20
+ feature_extractor=processor.feature_extractor,
21
+ max_new_tokens=128,
22
+ chunk_length_s=30,
23
+ batch_size=16,
24
+ return_timestamps=True,
25
+ torch_dtype=torch_dtype,
26
+ device=device,
27
+ )
28
+
29
+ def speech_to_text(path_to_file: str) -> str:
30
+ """
31
+ Given the path to the .wav file, it returns the transcription.
32
+ """
33
+ result = pipe(path_to_file)
34
+
35
+ return result["text"]
requirements.txt CHANGED
@@ -1,6 +1,5 @@
1
  # Add the other requirements here
2
  fastapi
3
  uvicorn
4
- elevenlabs
5
- mistralai
6
- streamlit
 
1
  # Add the other requirements here
2
  fastapi
3
  uvicorn
4
+ torch
5
+ transformers