burraco135 commited on
Commit
b2550bd
1 Parent(s): 6a52be4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -1
app.py CHANGED
@@ -1,3 +1,41 @@
1
  import gradio as gr
2
 
3
- gr.Interface.load("models/burraco135/whisper-tiny-en").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
 
3
+ from transformers import pipeline
4
+
5
+ model_id = "burraco135/whisper-small-en"
6
+ pipe = pipeline("automatic-speech-recognition", model=model_id)
7
+
8
+ def transcribe_speech(filepath):
9
+ output = pipe(
10
+ filepath,
11
+ max_new_tokens=256,
12
+ generate_kwargs={
13
+ "task": "transcribe",
14
+ "language": "sinhalese",
15
+ }, # update with the language you've fine-tuned on
16
+ chunk_length_s=30,
17
+ batch_size=8,
18
+ )
19
+ return output["text"]
20
+
21
+ demo = gr.Blocks()
22
+
23
+ mic_transcribe = gr.Interface(
24
+ fn=transcribe_speech,
25
+ inputs=gr.Audio(source="microphone", type="filepath"),
26
+ outputs=gr.outputs.Textbox(),
27
+ )
28
+
29
+ file_transcribe = gr.Interface(
30
+ fn=transcribe_speech,
31
+ inputs=gr.Audio(source="upload", type="filepath"),
32
+ outputs=gr.outputs.Textbox(),
33
+ )
34
+
35
+ with demo:
36
+ gr.TabbedInterface(
37
+ [mic_transcribe, file_transcribe],
38
+ ["Transcribe Microphone", "Transcribe Audio File"],
39
+ )
40
+
41
+ demo.launch(debug=True)