Duy-NM
commited on
Commit
·
5e825a2
1
Parent(s):
a30590e
init
Browse files- .gitignore +1 -0
- app.py +75 -0
- requirements.txt +0 -0
.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
*.pyc
|
app.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
from gradio_client import Client
|
| 5 |
+
|
| 6 |
+
link = os.environ['link']
|
| 7 |
+
client = Client(link)
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def s2t(source, mic, fi, lang):
|
| 11 |
+
if source == 'file':
|
| 12 |
+
in_file = fi
|
| 13 |
+
else:
|
| 14 |
+
in_file = mic
|
| 15 |
+
|
| 16 |
+
result = client.predict(
|
| 17 |
+
in_file, # str (filepath or URL to file) in 'inputs' Audio component
|
| 18 |
+
"transcribe", # str in 'Task' Radio component
|
| 19 |
+
True, # bool in 'Return timestamps' Checkbox component
|
| 20 |
+
api_name="/predict"
|
| 21 |
+
)
|
| 22 |
+
print(result)
|
| 23 |
+
return result
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def update_audio_ui(audio_source: str, input_audio_mic, input_audio_file):
|
| 27 |
+
mic = audio_source == "microphone"
|
| 28 |
+
# input_audio_mic.visible = mic
|
| 29 |
+
# print(type(gr.update(visible=mic, value=None)))
|
| 30 |
+
return gr.update(visible=mic, value=None), gr.update(visible=not mic, value=None)
|
| 31 |
+
|
| 32 |
+
with gr.Blocks() as demo:
|
| 33 |
+
gr.Markdown('<h1 style="text-align: center;">Speech to Text</h1>')
|
| 34 |
+
with gr.Group():
|
| 35 |
+
with gr.Row() as audio_box:
|
| 36 |
+
with gr.Column():
|
| 37 |
+
input_lang = gr.Dropdown(['auto','vi', 'ja', 'en-us', 'cn', 'ko'], label='Language?', value='auto', interactive=True)
|
| 38 |
+
audio_source = gr.Radio(
|
| 39 |
+
label="Audio source",
|
| 40 |
+
choices=["file", "microphone"],
|
| 41 |
+
value="file",
|
| 42 |
+
interactive=True
|
| 43 |
+
)
|
| 44 |
+
input_audio_mic = gr.Audio(
|
| 45 |
+
label="Input speech",
|
| 46 |
+
type="filepath",
|
| 47 |
+
sources="microphone",
|
| 48 |
+
visible=False,
|
| 49 |
+
)
|
| 50 |
+
input_audio_file = gr.Audio(
|
| 51 |
+
label="Input speech",
|
| 52 |
+
type="filepath",
|
| 53 |
+
sources="upload",
|
| 54 |
+
visible=True,
|
| 55 |
+
)
|
| 56 |
+
js = gr.JSON(label="json")
|
| 57 |
+
with gr.Row():
|
| 58 |
+
btn = gr.Button("Run")
|
| 59 |
+
btn_clean = gr.ClearButton([input_audio_mic, input_audio_file, js])
|
| 60 |
+
|
| 61 |
+
audio_source.change(
|
| 62 |
+
fn=update_audio_ui,
|
| 63 |
+
inputs=[audio_source, input_audio_mic, input_audio_file],
|
| 64 |
+
outputs=[
|
| 65 |
+
input_audio_mic,
|
| 66 |
+
input_audio_file,
|
| 67 |
+
],
|
| 68 |
+
queue=False,
|
| 69 |
+
api_name=False,
|
| 70 |
+
)
|
| 71 |
+
|
| 72 |
+
btn.click(fn=s2t, inputs=[audio_source, input_audio_mic, input_audio_file, input_lang], outputs=[js])
|
| 73 |
+
|
| 74 |
+
if __name__ == "__main__":
|
| 75 |
+
demo.launch()
|
requirements.txt
ADDED
|
File without changes
|