Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
os.system("pip install git+https://github.com/openai/whisper.git")
|
3 |
+
import gradio as gr
|
4 |
+
import whisper
|
5 |
+
|
6 |
+
model = whisper.load_model("small")
|
7 |
+
|
8 |
+
def inference(audio):
|
9 |
+
audio = whisper.load_audio(audio)
|
10 |
+
audio = whisper.pad_or_trim(audio)
|
11 |
+
|
12 |
+
mel = whisper.log_mel_spectrogram(audio).to(model.device)
|
13 |
+
|
14 |
+
_, probs = model.detect_language(mel)
|
15 |
+
|
16 |
+
options = whisper.DecodingOptions(fp16 = False)
|
17 |
+
result = whisper.decode(model, mel, options)
|
18 |
+
|
19 |
+
print(result.text)
|
20 |
+
return result.text, gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)
|
21 |
+
|
22 |
+
|
23 |
+
with block:
|
24 |
+
with gr.Group():
|
25 |
+
with gr.Box():
|
26 |
+
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
27 |
+
audio = gr.Audio(
|
28 |
+
label="Input Audio",
|
29 |
+
show_label=False,
|
30 |
+
source="microphone",
|
31 |
+
type="filepath"
|
32 |
+
)
|
33 |
+
|
34 |
+
btn = gr.Button("Transcribe")
|
35 |
+
text = gr.Textbox(show_label=False, elem_id="result-textarea")
|
36 |
+
with gr.Group(elem_id="share-btn-container"):
|
37 |
+
community_icon = gr.HTML(community_icon_html, visible=False)
|
38 |
+
loading_icon = gr.HTML(loading_icon_html, visible=False)
|
39 |
+
share_button = gr.Button("Share to community", elem_id="share-btn", visible=False)
|
40 |
+
|
41 |
+
|
42 |
+
|
43 |
+
|
44 |
+
btn.click(inference, inputs=[audio], outputs=[text, community_icon, loading_icon, share_button])
|
45 |
+
share_button.click(None, [], [], _js=share_js)
|
46 |
+
|
47 |
+
|
48 |
+
block.launch()
|
49 |
+
|
50 |
+
|