File size: 3,256 Bytes
c32697e 26f365f c32697e 25ad790 b70ba64 c32697e 26f365f c32697e 437c02a dcd3020 c32697e 83d5183 c32697e 9713d52 b1da8e3 9713d52 c32697e 9713d52 c32697e 25ad790 c32697e 25ad790 c743c6d 25ad790 14a0b3e c32697e 9713d52 3757521 9713d52 c32697e 9713d52 c32697e 29b5120 1571261 29b5120 1571261 24f7854 c32697e 9713d52 087b372 9713d52 c32697e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
import gradio as gr
from backend.text_to_tgt import src_txt_to_eng_translator, formatted_languages
from backend.audio_to_tgt import src_audio_to_eng_translator
from backend.image_to_tgt import src_image_to_eng_translator, language_dict
# from backend.video_to_tgt import src_video_to_eng_translator
heading_txt = "Text-to-English"
description_txt = '''Enter text in any language, and get the translation in English.'''
language_list = formatted_languages.keys()
txt_interface = gr.Interface(
fn=src_txt_to_eng_translator,
inputs=[
gr.Textbox(label="Text Input"),
gr.Dropdown(choices=language_list, label="Select Target Language", interactive=True)
],
outputs=[
gr.Textbox(label="Translation"),
gr.Textbox(label="Source Language")
],
title=heading_txt,
description=description_txt,
examples=[
["Bonjour, comment ça va ?", "Hindi"],
["Привет, как дела?", "English"],
["Hola, ¿cómo estás?", "Odia (Oriya)"],
["你好,你怎么样", "English"],
["Guten Tag! Wie geht's dir?", "English"]
]
)
heading_image = "Image-to-English"
description_image = "Upload an image to extract text and translate it to English. Make sure to choose language in 'Select Language'"
sorted_languages = sorted(language_dict.keys())
image_interface = gr.Interface(
fn=src_image_to_eng_translator,
inputs=[
gr.Image(label="Upload an Image", type="filepath"),
gr.Dropdown(choices=sorted_languages,
label="Select Language",
# default='English'
)
],
outputs=[
gr.Textbox(label="Image Text"),
gr.Textbox(label="Translated Text")
],
title="Image Text Extractor and Translator",
description=description_image,
examples=[
["examples/images/hindi_image_sample.jpg", "Hindi"],
["examples/images/odia_sample_image.png", "Odia"],
["examples/images/russian_sample_image.png", "Russian"]
]
)
heading_audio = "Audio-to-English"
description_audio = "Upload an audio file to extract text and translate it to English. Takes too much time without GPU."
audio_interface = gr.Interface(
fn=src_audio_to_eng_translator,
inputs=[
gr.Audio(
label="Upload an Audio file",
type="filepath"
),
gr.Dropdown(
choices=["turbo", "base", "tiny", "small", "medium", "large"],
label="Select Whisper Model size",
),
gr.Dropdown(
choices=language_list,
label="Select Target Language",
interactive=True
)
],
outputs=[gr.Textbox(label="Original text"),
gr.Textbox(label="Translated text"),
gr.Textbox(label="Original Language")],
title=heading_audio,
description=description_audio,
examples=[
["examples/audios/russian_sample_audio.mp3", "turbo", "English"]
]
)
combined_interface = gr.TabbedInterface(
[txt_interface, image_interface, audio_interface],
['Text-to-English', 'Image-to-English', 'Audio-to-English']
)
combined_interface.launch() |