update UI
Browse files
app.py
CHANGED
@@ -119,40 +119,39 @@ with gr.Blocks(title="Nepali-English Translator") as demo:
|
|
119 |
gr.Markdown("# Nepali-English Translation Service")
|
120 |
gr.Markdown("Translate between Nepali and English, transcribe audio, and convert text to speech.")
|
121 |
|
122 |
-
with gr.
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
choices=["Auto-detect", "en", "ne"],
|
133 |
-
value="Auto-detect",
|
134 |
-
label="Source Language"
|
135 |
-
)
|
136 |
-
target_lang = gr.Dropdown(
|
137 |
-
choices=["Auto-select", "en", "ne"],
|
138 |
-
value="Auto-select",
|
139 |
-
label="Target Language"
|
140 |
-
)
|
141 |
-
translate_button = gr.Button("Translate")
|
142 |
-
translation_output = gr.Textbox(label="Translation Output", lines=5)
|
143 |
-
tts_button = gr.Button("Convert to Speech")
|
144 |
-
audio_output = gr.Audio(label="Audio Output")
|
145 |
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
156 |
|
157 |
# Define event handlers
|
158 |
def process_translation(text, model, src_lang, tgt_lang):
|
@@ -171,9 +170,15 @@ with gr.Blocks(title="Nepali-English Translator") as demo:
|
|
171 |
return transcribe_audio(audio_path, language)
|
172 |
|
173 |
# Connect the components
|
|
|
|
|
|
|
|
|
|
|
|
|
174 |
translate_button.click(
|
175 |
process_translation,
|
176 |
-
inputs=[
|
177 |
outputs=translation_output
|
178 |
)
|
179 |
|
@@ -182,12 +187,6 @@ with gr.Blocks(title="Nepali-English Translator") as demo:
|
|
182 |
inputs=translation_output,
|
183 |
outputs=audio_output
|
184 |
)
|
185 |
-
|
186 |
-
transcribe_button.click(
|
187 |
-
process_transcription,
|
188 |
-
inputs=[audio_input, asr_language],
|
189 |
-
outputs=transcription_output
|
190 |
-
)
|
191 |
|
192 |
# Launch the app
|
193 |
if __name__ == "__main__":
|
|
|
119 |
gr.Markdown("# Nepali-English Translation Service")
|
120 |
gr.Markdown("Translate between Nepali and English, transcribe audio, and convert text to speech.")
|
121 |
|
122 |
+
with gr.Column():
|
123 |
+
gr.Markdown("### Speech to Text")
|
124 |
+
audio_input = gr.Audio(label="Upload or Record Audio", type="filepath")
|
125 |
+
asr_language = gr.Radio(
|
126 |
+
choices=["eng", "npi"],
|
127 |
+
value="npi",
|
128 |
+
label="Speech Language"
|
129 |
+
)
|
130 |
+
transcribe_button = gr.Button("Transcribe")
|
131 |
+
transcription_output = gr.Textbox(label="Transcription Output", lines=3)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
|
133 |
+
gr.Markdown("### Text Translation")
|
134 |
+
model_choice = gr.Dropdown(
|
135 |
+
choices=["XTransformer", "M2M100"],
|
136 |
+
value="M2M100",
|
137 |
+
label="Translation Model"
|
138 |
+
)
|
139 |
+
source_lang = gr.Dropdown(
|
140 |
+
choices=["Auto-detect", "en", "ne"],
|
141 |
+
value="Auto-detect",
|
142 |
+
label="Source Language"
|
143 |
+
)
|
144 |
+
target_lang = gr.Dropdown(
|
145 |
+
choices=["Auto-select", "en", "ne"],
|
146 |
+
value="Auto-select",
|
147 |
+
label="Target Language"
|
148 |
+
)
|
149 |
+
translate_button = gr.Button("Translate")
|
150 |
+
translation_output = gr.Textbox(label="Translation Output", lines=5)
|
151 |
+
|
152 |
+
gr.Markdown("### Text to Speech")
|
153 |
+
tts_button = gr.Button("Convert to Speech")
|
154 |
+
audio_output = gr.Audio(label="Audio Output")
|
155 |
|
156 |
# Define event handlers
|
157 |
def process_translation(text, model, src_lang, tgt_lang):
|
|
|
170 |
return transcribe_audio(audio_path, language)
|
171 |
|
172 |
# Connect the components
|
173 |
+
transcribe_button.click(
|
174 |
+
process_transcription,
|
175 |
+
inputs=[audio_input, asr_language],
|
176 |
+
outputs=transcription_output
|
177 |
+
)
|
178 |
+
|
179 |
translate_button.click(
|
180 |
process_translation,
|
181 |
+
inputs=[transcription_output, model_choice, source_lang, target_lang],
|
182 |
outputs=translation_output
|
183 |
)
|
184 |
|
|
|
187 |
inputs=translation_output,
|
188 |
outputs=audio_output
|
189 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
190 |
|
191 |
# Launch the app
|
192 |
if __name__ == "__main__":
|