Spaces:
Runtime error
Runtime error
tonic
commited on
Commit
•
d886b33
1
Parent(s):
cb91f53
refactor gradio interface iface()
Browse files
app.py
CHANGED
@@ -248,75 +248,130 @@ def process_input(image=None, file=None, audio=None, text="", translateto = "Eng
|
|
248 |
|
249 |
return final_text, audio_output, top_phrases, translations, audio_outputs
|
250 |
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
255 |
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
|
268 |
-
|
269 |
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
|
321 |
-
if __name__ == "__main__":
|
322 |
-
|
|
|
248 |
|
249 |
return final_text, audio_output, top_phrases, translations, audio_outputs
|
250 |
|
251 |
+
|
252 |
+
# Define the inputs and outputs for the Gradio Interface
|
253 |
+
inputs = [
|
254 |
+
gr.inputs.Image(type="pil", label="Camera Input"),
|
255 |
+
gr.inputs.File(label="File Upload"),
|
256 |
+
gr.inputs.Audio(sources="microphone", type="filepath", label="Mic Input"),
|
257 |
+
gr.inputs.Textbox(lines=2, label="Text Input"),
|
258 |
+
gr.inputs.Dropdown(choices=choices, label="Your Native Language"),
|
259 |
+
gr.inputs.Dropdown(choices=choices, label="Language To Learn")
|
260 |
+
]
|
261 |
+
|
262 |
+
outputs = [
|
263 |
+
RichTextbox(label="Processed Text"),
|
264 |
+
gr.outputs.Audio(label="Audio Output (Native Language) 1"),
|
265 |
+
gr.outputs.Audio(label="Audio Output (Target Language) 1"),
|
266 |
+
gr.outputs.Audio(label="Audio Output (Native Language) 2"),
|
267 |
+
gr.outputs.Audio(label="Audio Output (Target Language) 2"),
|
268 |
+
gr.outputs.Audio(label="Audio Output (Native Language) 3"),
|
269 |
+
gr.outputs.Audio(label="Audio Output (Target Language) 3"),
|
270 |
+
gr.outputs.Textbox(label="Focus 1"),
|
271 |
+
gr.outputs.Textbox(label="Translated Phrases 1"),
|
272 |
+
gr.outputs.Textbox(label="Focus 2"),
|
273 |
+
gr.outputs.Textbox(label="Translated Phrases 2"),
|
274 |
+
gr.outputs.Textbox(label="Focus 3"),
|
275 |
+
gr.outputs.Textbox(label="Translated Phrases 3")
|
276 |
+
]
|
277 |
+
def update_outputs(image, file, audio, text, input_language, target_language):
|
278 |
+
final_text, top_phrases, translations, audio_outputs = process_input(
|
279 |
+
image=image, file=file, audio=audio, text=text,
|
280 |
+
translatefrom=input_language, translateto=target_language
|
281 |
+
)
|
282 |
+
|
283 |
+
processed_text_output = final_text
|
284 |
+
audio_output_native_phrases = [native for _, native in audio_outputs]
|
285 |
+
audio_output_target_phrases = [target for target, _ in audio_outputs]
|
286 |
+
|
287 |
+
longest_phrases_outputs = top_phrases[:3]
|
288 |
+
translated_phrases_outputs = translations[:3]
|
289 |
+
audio_outputs_native = audio_output_native_phrases[:3]
|
290 |
+
audio_outputs_target = audio_output_target_phrases[:3]
|
291 |
+
|
292 |
+
return (
|
293 |
+
processed_text_output,
|
294 |
+
*audio_outputs_native,
|
295 |
+
*audio_outputs_target,
|
296 |
+
*longest_phrases_outputs,
|
297 |
+
*translated_phrases_outputs
|
298 |
+
)
|
299 |
+
|
300 |
+
# Create the Gradio interface
|
301 |
+
iface = gr.Interface(fn=interface_func, inputs=inputs, outputs=outputs, title=title, description=description)
|
302 |
+
|
303 |
+
if __name__ == "__main__":
|
304 |
+
iface.launch()
|
305 |
+
|
306 |
+
# def main():
|
307 |
+
# with gr.Blocks() as demo:
|
308 |
+
# gr.Markdown(title)
|
309 |
+
# gr.Markdown(description)
|
310 |
|
311 |
+
# with gr.Row():
|
312 |
+
# input_language = gr.Dropdown(choices=choices, label="Your Native Language")
|
313 |
+
# target_language = gr.Dropdown(choices=choices, label="Language To Learn")
|
314 |
|
315 |
+
# with gr.Accordion("Talk To 🌟AyaTonic"):
|
316 |
+
# with gr.Tab("🤙🏻Audio & Text"):
|
317 |
+
# audio_input = gr.Audio(sources="microphone", type="filepath", label="Mic Input")
|
318 |
+
# text_input = gr.Textbox(lines=2, label="Text Input")
|
319 |
+
# with gr.Tab("📸Image & File"):
|
320 |
+
# image_input = gr.Image(type="pil", label="Camera Input")
|
321 |
+
# file_input = gr.File(label="File Upload")
|
322 |
|
323 |
+
# process_button = gr.Button("🌟AyaTonic")
|
324 |
|
325 |
+
# processed_text_output = RichTextbox(label="Processed Text")
|
326 |
+
# longest_phrases_1 = gr.Textbox(label="Focus")
|
327 |
+
# translated_phrases_output_1 = gr.Textbox(label="Translated Phrases")
|
328 |
+
# audio_output_native_phrase_1 = gr.Audio(label="Audio Output (Native Language)")
|
329 |
+
# audio_output_target_phrase_1 = gr.Audio(label="Audio Output (Target Language)")
|
330 |
+
# longest_phrases_2 = gr.Textbox(label="Focus")
|
331 |
+
# translated_phrases_output_2 = gr.Textbox(label="Translated Phrases")
|
332 |
+
# audio_output_native_phrase_2 = gr.Audio(label="Audio Output (Native Language)")
|
333 |
+
# audio_output_target_phrase_2 = gr.Audio(label="Audio Output (Target Language)")
|
334 |
+
# longest_phrases_3 = gr.Textbox(label="Focus")
|
335 |
+
# translated_phrases_output_3 = gr.Textbox(label="Translated Phrases")
|
336 |
+
# audio_output_native_phrase_3 = gr.Audio(label="Audio Output (Native Language)")
|
337 |
+
# audio_output_target_phrase_3 = gr.Audio(label="Audio Output (Target Language)")
|
338 |
|
339 |
+
# def update_outputs(image, file, audio, text, input_language, target_language):
|
340 |
+
# final_text, top_phrases, translations, audio_outputs = process_input(
|
341 |
+
# image=image, file=file, audio=audio, text=text,
|
342 |
+
# translatefrom=input_language, translateto=target_language
|
343 |
+
# )
|
344 |
+
|
345 |
+
# processed_text_output = final_text
|
346 |
+
# audio_output_native_phrases = [native for _, native in audio_outputs]
|
347 |
+
# audio_output_target_phrases = [target for target, _ in audio_outputs]
|
348 |
+
|
349 |
+
# longest_phrases_outputs = top_phrases[:3]
|
350 |
+
# translated_phrases_outputs = translations[:3]
|
351 |
+
# audio_outputs_native = audio_output_native_phrases[:3]
|
352 |
+
# audio_outputs_target = audio_output_target_phrases[:3]
|
353 |
+
|
354 |
+
# return (
|
355 |
+
# processed_text_output,
|
356 |
+
# *audio_outputs_native,
|
357 |
+
# *audio_outputs_target,
|
358 |
+
# *longest_phrases_outputs,
|
359 |
+
# *translated_phrases_outputs
|
360 |
+
# )
|
361 |
|
362 |
+
# process_button.click(
|
363 |
+
# fn=update_outputs,
|
364 |
+
# inputs=[image_input, file_input, audio_input, text_input, input_language, target_language],
|
365 |
+
# outputs=[
|
366 |
+
# processed_text_output,
|
367 |
+
# audio_output_native_phrase_1, audio_output_target_phrase_1,
|
368 |
+
# audio_output_native_phrase_2, audio_output_target_phrase_2,
|
369 |
+
# audio_output_native_phrase_3, audio_output_target_phrase_3,
|
370 |
+
# longest_phrases_1, translated_phrases_output_1,
|
371 |
+
# longest_phrases_2, translated_phrases_output_2,
|
372 |
+
# longest_phrases_3, translated_phrases_output_3
|
373 |
+
# ]
|
374 |
+
# )
|
375 |
|
376 |
+
# if __name__ == "__main__":
|
377 |
+
# main()
|