Huyen2310 commited on
Commit
417ed65
·
1 Parent(s): 9482c8f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -10
app.py CHANGED
@@ -1,18 +1,46 @@
1
- from transformers import pipeline
2
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
- pipe = pipeline(model="sanchit-gandhi/whisper-small-hi") # change to "your-username/the-name-you-picked"
5
 
6
- def transcribe(audio):
7
- text = pipe(audio)["text"]
8
- return text
9
 
10
  iface = gr.Interface(
11
- fn=transcribe,
12
- inputs=gr.Audio(source="microphone", type="filepath"),
 
 
 
13
  outputs="text",
14
- title="Whisper Small Hindi",
15
- description="Realtime demo for Hindi speech recognition using a fine-tuned Whisper small model.",
 
 
 
16
  )
17
 
18
- iface.launch()
 
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
+ import torch
4
+ import librosa
5
+ import soundfile
6
+
7
+ SAMPLE_RATE = 16000
8
+
9
+ pipe = pipeline(model="openai/whisper-small")
10
+
11
+
12
+ def transcribe(Microphone, File_Upload):
13
+ warn_output = ""
14
+ if (Microphone is not None) and (File_Upload is not None):
15
+ warn_output = "WARNING: You've uploaded an audio file and used the microphone. " \
16
+ "The recorded file from the microphone will be used and the uploaded audio will be discarded.\n"
17
+ file = Microphone
18
+
19
+ elif (Microphone is None) and (File_Upload is None):
20
+ return "ERROR: You have to either use the microphone or upload an audio file"
21
+
22
+ elif Microphone is not None:
23
+ file = Microphone
24
+ else:
25
+ file = File_Upload
26
+
27
+ text = pipe(file)["text"]
28
 
29
+ return warn_output + text
30
 
 
 
 
31
 
32
  iface = gr.Interface(
33
+ fn=transcribe,
34
+ inputs=[
35
+ gr.inputs.Audio(source="microphone", type='filepath', optional=True),
36
+ gr.inputs.Audio(source="upload", type='filepath', optional=True),
37
+ ],
38
  outputs="text",
39
+ layout="horizontal",
40
+ theme="huggingface",
41
+ title="Whisper Small",
42
+ description="Demo for multilingual speech recognition using the official OpenAI [Whisper small checkpoint](https://huggingface.co/openai/whisper-small).",
43
+ allow_flagging='never',
44
  )
45
 
46
+ iface.launch(enable_queue=True)