datnth1709 commited on
Commit
3008991
·
1 Parent(s): 530a947

update speech2text module

Browse files
Files changed (1) hide show
  1. app.py +31 -20
app.py CHANGED
@@ -79,33 +79,44 @@ def speech2text(audio):
79
  model_checkpoint = "huynguyen208/fantastic4-finetuned-vi-to-en-PhoMT-demo"
80
  translator = pipeline("translation", model=model_checkpoint)
81
 
82
- def translate(Vietnamese):
83
  return translator(Vietnamese)[0]['translation_text']
84
 
85
  def inference(audio):
86
  vi_text = speech2text(audio)
87
- en_text = translate(vi_text)
88
  return en_text
89
 
90
 
91
  """Gradio demo"""
92
- iface1 = gr.Interface(fn=translate,
93
- inputs=["text"],
94
- outputs="text",
95
- title = 'Translate Vietnamese to English',
96
- description = 'Mini Translator')
97
- iface1.launch(inline = False)
98
 
 
 
99
 
100
- inputs = gr.inputs.Audio(label="Input Audio", type="file")
101
- outputs = gr.outputs.Textbox(label="Output Text")
102
- title = "Speech to text and translate Vietnamese to English"
103
- description = "Gradio demo for a wav2vec2-base-vietnamese-250h and Helsinki-NLP/opus-mt-vi-en"
104
- examples=[['vi_speech_01.wav'], ['vi_speech_02.wav'], ['vi_speech_03.wav']]
105
- iface2 = gr.Interface(inference,
106
- inputs,
107
- outputs,
108
- title=title,
109
- description=description,
110
- examples=examples)
111
- iface2.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
  model_checkpoint = "huynguyen208/fantastic4-finetuned-vi-to-en-PhoMT-demo"
80
  translator = pipeline("translation", model=model_checkpoint)
81
 
82
+ def translate_vi2en(Vietnamese):
83
  return translator(Vietnamese)[0]['translation_text']
84
 
85
  def inference(audio):
86
  vi_text = speech2text(audio)
87
+ en_text = translate_vi2en(vi_text)
88
  return en_text
89
 
90
 
91
  """Gradio demo"""
 
 
 
 
 
 
92
 
93
+ vi_example_text = ["Có phải bạn đang muốn tìm mua nhà ở ngoại ô thành phố Hồ Chí Minh không?",
94
+ "có phải bạn đang muốn tìm mua nhà ở ngoại ô thành phố Hồ Chí Minh không"]
95
 
96
+ vi_example_voice =[['vi_speech_01.wav'], ['vi_speech_02.wav'], ['vi_speech_03.wav']]
97
+
98
+ with gr.Blocks() as demo:
99
+ with gr.Tabs():
100
+ with gr.TabItem("Translation: Vietnamese to English"):
101
+ with gr.Row():
102
+ with gr.Column():
103
+ vietnamese = gr.Textbox(label="Vietnamese Text")
104
+ translate_to_english = gr.Button(value="Translate To English")
105
+ with gr.Column():
106
+ english = gr.Textbox(label="English Text")
107
+ translate_to_english.click(lambda text: translate_vi2en(text), inputs=vietnamese, outputs=english)
108
+ gr.Examples(examples=vi_example_text,
109
+ inputs=[vietnamese])
110
+ with gr.TabItem("Speech2text translation: Vietnamese voice to English"):
111
+ with gr.Row():
112
+ inputs = gr.inputs.Audio(label="Input Audio", type="file")
113
+ outputs = gr.outputs.Textbox(label="Output Text")
114
+ title = "Speech to text and translate Vietnamese to English"
115
+ description = "Gradio demo for a wav2vec2-base-vietnamese-250h and Helsinki-NLP/opus-mt-vi-en"
116
+ iface = gr.Interface(inference,
117
+ inputs,
118
+ outputs,
119
+ title=title,
120
+ description=description,
121
+ examples=vi_example_voice)
122
+ iface.launch()