Spaces:
Runtime error
Runtime error
app :3
Browse files
app.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from translate import Translator
|
3 |
+
|
4 |
+
def translate_text(text, source_lang, target_lang):
|
5 |
+
translator = Translator(from_lang=source_lang, to_lang=target_lang)
|
6 |
+
translation = translator.translate(text)
|
7 |
+
return translation
|
8 |
+
|
9 |
+
# List of language codes
|
10 |
+
languages = ["auto", "en", "es", "fr", "de", "zh", "ja", "ko", "ru", "it", "pt", "nl", "ar", "hi"]
|
11 |
+
|
12 |
+
with gr.Blocks() as demo:
|
13 |
+
gr.Markdown("# Text Translation")
|
14 |
+
|
15 |
+
with gr.Row():
|
16 |
+
with gr.Column():
|
17 |
+
source_lang = gr.Dropdown(label="Source Language", choices=languages, value="auto")
|
18 |
+
target_lang = gr.Dropdown(label="Target Language", choices=languages, value="en")
|
19 |
+
input_text = gr.Textbox(label="Input Text")
|
20 |
+
|
21 |
+
with gr.Column():
|
22 |
+
output_text = gr.Textbox(label="Translated Text", interactive=False)
|
23 |
+
|
24 |
+
translate_button = gr.Button("Translate")
|
25 |
+
|
26 |
+
translate_button.click(translate_text, inputs=[input_text, source_lang, target_lang], outputs=output_text)
|
27 |
+
|
28 |
+
demo.launch()
|