Ratnesh-dev commited on
Commit
ad744d6
·
1 Parent(s): 453e996

Add Whisper-Large-V3-Turbo Demo

Browse files
Files changed (3) hide show
  1. app.py +46 -8
  2. packages.txt +1 -0
  3. requirements.txt +2 -0
app.py CHANGED
@@ -1,14 +1,52 @@
1
- import gradio as gr
2
  import spaces
3
  import torch
4
 
5
- zero = torch.Tensor([0]).cuda()
6
- print(zero.device) # <-- 'cpu' 🤔
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
  @spaces.GPU
9
- def greet(n):
10
- print(zero.device) # <-- 'cuda:0' 🤗
11
- return f"Hello {zero + n} Tensor"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
- demo = gr.Interface(fn=greet, inputs=gr.Number(), outputs=gr.Text())
14
- demo.launch()
 
 
1
  import spaces
2
  import torch
3
 
4
+ import gradio as gr
5
+ from transformers import pipeline
6
+
7
+
8
+ MODEL_NAME = "openai/whisper-large-v3-turbo"
9
+ BATCH_SIZE = 8
10
+ FILE_LIMIT_MB = 1000
11
+
12
+ device = 0 if torch.cuda.is_available() else "cpu"
13
+
14
+ pipe = pipeline(
15
+ task="automatic-speech-recognition",
16
+ model=MODEL_NAME,
17
+ chunk_length_s=30,
18
+ device=device,
19
+ )
20
+
21
 
22
  @spaces.GPU
23
+ def transcribe(inputs, task):
24
+ if inputs is None:
25
+ raise gr.Error("No audio file submitted! Please upload or record an audio file before submitting your request.")
26
+
27
+ text = pipe(inputs, batch_size=BATCH_SIZE, generate_kwargs={"task": task}, return_timestamps=True)["text"]
28
+ return text
29
+
30
+
31
+ demo = gr.Blocks(theme=gr.themes.Ocean())
32
+
33
+
34
+ with demo:
35
+ gr.Interface(
36
+ fn=transcribe,
37
+ inputs=[
38
+ gr.Audio(sources="upload", type="filepath", label="Audio file"),
39
+ gr.Radio(["transcribe", "translate"], label="Task", value="transcribe"),
40
+ ],
41
+ outputs="text",
42
+ title="Whisper Large V3: Transcribe Audio",
43
+ description=(
44
+ "Transcribe long-form microphone or audio inputs with the click of a button! Demo uses the"
45
+ f" checkpoint [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to transcribe audio files"
46
+ " of arbitrary length."
47
+ ),
48
+ allow_flagging="never",
49
+ )
50
+
51
 
52
+ demo.queue().launch(ssr_mode=False)
 
packages.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ ffmpeg
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ transformers
2
+