avimittal30 commited on
Commit
68e0a01
·
verified ·
1 Parent(s): 6ac665f

updated app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -9
app.py CHANGED
@@ -1,18 +1,36 @@
1
- import gradio as gr
2
- from transformers import pipeline
3
- import spaces
4
 
5
- # Load the Whisper model from Hugging Face
6
- model = pipeline("automatic-speech-recognition", model="ylacombe/whisper-large-v3-turbo", chunk_length_s=30, device=0)
7
- # model = pipeline("automatic-speech-recognition", model="distil-whisper/distil-large-v3", chunk_length_s=30, device=0)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
  # Function to process audio input and transcribe it
10
  @spaces.GPU
11
  def transcribe(audio):
12
  # Load and preprocess the audio
13
- transcription = model(audio,batch_size=1000, generate_kwargs={"task": "transcribe"}, return_timestamps=True)["text"]
14
- return transcription
15
-
16
 
17
  # Gradio interface
18
  interface = gr.Interface(
 
1
+ import torch
2
+ from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
3
+ # from datasets import load_dataset
4
 
5
+
6
+ device = "cuda:0" if torch.cuda.is_available() else "cpu"
7
+ torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
8
+
9
+ model_id = "distil-whisper/distil-large-v3"
10
+
11
+ model = AutoModelForSpeechSeq2Seq.from_pretrained(
12
+ model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True
13
+ )
14
+ model.to(device)
15
+
16
+ processor = AutoProcessor.from_pretrained(model_id)
17
+
18
+ pipe = pipeline(
19
+ "automatic-speech-recognition",
20
+ model=model,
21
+ tokenizer=processor.tokenizer,
22
+ feature_extractor=processor.feature_extractor,
23
+ max_new_tokens=128,
24
+ torch_dtype=torch_dtype,
25
+ device=device,
26
+ )
27
 
28
  # Function to process audio input and transcribe it
29
  @spaces.GPU
30
  def transcribe(audio):
31
  # Load and preprocess the audio
32
+ result = pipe(sample)
33
+ return result["text"]
 
34
 
35
  # Gradio interface
36
  interface = gr.Interface(