dmaniloff commited on
Commit
89cc85a
·
verified ·
1 Parent(s): dcac4f2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -4
app.py CHANGED
@@ -1,7 +1,41 @@
 
 
 
 
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
 
 
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- demo.launch()
 
1
+ import os
2
+ import tempfile
3
+
4
+ import torch
5
  import gradio as gr
6
+ from transformers import pipeline
7
+
8
+
9
+ MODEL_NAME = "openai/whisper-large-v3"
10
+ BATCH_SIZE = 8
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
+ def transcribe(inputs, task="transcribe"):
23
+ if inputs is None:
24
+ raise gr.Error("No audio file submitted!")
25
+
26
+ output = pipe(
27
+ inputs,
28
+ batch_size=BATCH_SIZE,
29
+ generate_kwargs={"task": task},
30
+ return_timestamps=True
31
+ )
32
+ return output["text"]
33
 
34
+ demo = gr.Interface(
35
+ fn=transcribe,
36
+ inputs=["audio"],
37
+ outputs="text",
38
+ title="Transcribe Audio to Text", # Give our demo a title
39
+ )
40
 
41
+ demo.launch()