Gyaneshere commited on
Commit
4776a78
·
verified ·
1 Parent(s): 5a7959f

created app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+
3
+ model_id = "Gyaneshere/whisper-small-dv" # update with your model id
4
+ pipe = pipeline("automatic-speech-recognition", model=model_id)
5
+
6
+ def transcribe_speech(filepath):
7
+ output = pipe(
8
+ filepath,
9
+ max_new_tokens=256,
10
+ generate_kwargs={
11
+ "task": "transcribe",
12
+ "language": "sinhalese",
13
+ }, # update with the language you've fine-tuned on
14
+ chunk_length_s=30,
15
+ batch_size=8,
16
+ )
17
+ return output["text"]
18
+
19
+ import gradio as gr
20
+
21
+ demo = gr.Blocks()
22
+
23
+ mic_transcribe = gr.Interface(
24
+ fn=transcribe_speech,
25
+ inputs=gr.Audio(sources="microphone", type="filepath"),
26
+ outputs=gr.components.Textbox(),
27
+ )
28
+
29
+ file_transcribe = gr.Interface(
30
+ fn=transcribe_speech,
31
+ inputs=gr.Audio(sources="upload", type="filepath"),
32
+ outputs=gr.components.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)