pratikshahp commited on
Commit
5683e58
Β·
verified Β·
1 Parent(s): 6d9069f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -0
app.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ translator = pipeline("translation_en_to_hi", model="Helsinki-NLP/opus-mt-en-hi")
5
+
6
+ @gr.Interface(
7
+ fn=lambda text: translator(text, max_length=400)[0]["translation_text"],
8
+ inputs=gr.Textbox(),
9
+ outputs=gr.Textbox()
10
+ )
11
+ def translate_text(text):
12
+ if not text.strip():
13
+ return "⚠️ Please provide input text."
14
+ return translator(text, max_length=400)[0]["translation_text"]
15
+
16
+ iface = gr.Interface(fn=translate_text, inputs="text", outputs="text")
17
+ iface.queue()
18
+ iface.launch()