juangtzi commited on
Commit
47f046f
1 Parent(s): b422d27

Add application file

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