Spaces:
Sleeping
Sleeping
Sanjeeth
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,9 @@
|
|
| 1 |
-
|
| 2 |
import gradio as gr
|
| 3 |
from transformers import pipeline
|
| 4 |
|
| 5 |
# Initialize the translation pipeline with T5-base model
|
| 6 |
translator = pipeline("translation", model="google-t5/t5-base")
|
| 7 |
|
| 8 |
-
print('final')
|
| 9 |
|
| 10 |
# Define available languages
|
| 11 |
AVAILABLE_LANGUAGES = ["French", "German", "Romanian"]
|
|
@@ -50,28 +48,30 @@ def run_tests():
|
|
| 50 |
|
| 51 |
return "\n".join(results)
|
| 52 |
|
| 53 |
-
#
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
gr.
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
|
|
|
|
|
|
| 75 |
|
| 76 |
-
# Launch the app
|
| 77 |
-
iface.launch()
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
# Initialize the translation pipeline with T5-base model
|
| 5 |
translator = pipeline("translation", model="google-t5/t5-base")
|
| 6 |
|
|
|
|
| 7 |
|
| 8 |
# Define available languages
|
| 9 |
AVAILABLE_LANGUAGES = ["French", "German", "Romanian"]
|
|
|
|
| 48 |
|
| 49 |
return "\n".join(results)
|
| 50 |
|
| 51 |
+
# Guard to prevent the Gradio app from running during imports (like testing)
|
| 52 |
+
if __name__ == "__main__":
|
| 53 |
+
# Create Gradio interface
|
| 54 |
+
with gr.Blocks() as iface:
|
| 55 |
+
gr.Markdown("# Speech Translation using T5-base")
|
| 56 |
+
gr.Markdown("Translate English text to French, German, or Romanian using the T5-base model.")
|
| 57 |
+
|
| 58 |
+
with gr.Row():
|
| 59 |
+
input_text = gr.Textbox(label="Enter English text", placeholder="Hi, how are you?")
|
| 60 |
+
output_text = gr.Textbox(label="Translation")
|
| 61 |
+
|
| 62 |
+
target_lang = gr.Dropdown(AVAILABLE_LANGUAGES, label="Target Language")
|
| 63 |
+
translate_btn = gr.Button("Translate")
|
| 64 |
+
|
| 65 |
+
with gr.Row():
|
| 66 |
+
show_langs_btn = gr.Button("Show Available Languages")
|
| 67 |
+
available_langs = gr.Textbox(label="Available Languages")
|
| 68 |
+
|
| 69 |
+
test_btn = gr.Button("Run Tests")
|
| 70 |
+
test_output = gr.Textbox(label="Test Results")
|
| 71 |
+
|
| 72 |
+
translate_btn.click(translate, inputs=[input_text, target_lang], outputs=output_text)
|
| 73 |
+
show_langs_btn.click(show_available_languages, inputs=None, outputs=available_langs)
|
| 74 |
+
test_btn.click(run_tests, inputs=None, outputs=test_output)
|
| 75 |
|
| 76 |
+
# Launch the app
|
| 77 |
+
iface.launch()
|