Shangkhonil commited on
Commit
f02240a
·
verified ·
1 Parent(s): 94ea8a4

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -0
app.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Initialize the translation pipeline with source (en) and target (de) languages
5
+ pipe = pipeline("translation_en_to_de", model="google-t5/t5-small")
6
+
7
+ # Define a translation function
8
+ def translate(text):
9
+ return pipe(text)[0]['translation_text']
10
+
11
+ # Set up the Gradio interface with updated components
12
+ app = gr.Interface(
13
+ fn=translate, # Function for translation
14
+ inputs=gr.Textbox(lines=2, placeholder="Enter text to translate"), # Updated input field
15
+ outputs=gr.Textbox(), # Updated output field
16
+ title="Text Translator", # Title of the app
17
+ description="Enter text to translate from English to German using Google T5 small model."
18
+ )
19
+
20
+ # Launch the app
21
+ if __name__ == "__main__":
22
+ app.launch()