Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load the translation pipeline from Hugging Face
|
5 |
+
translator = pipeline("translation_en_to_ur", model="Helsinki-NLP/opus-mt-en-ur")
|
6 |
+
|
7 |
+
# Define the translation function
|
8 |
+
def translate(text):
|
9 |
+
translated = translator(text)
|
10 |
+
return translated[0]['translation_text']
|
11 |
+
|
12 |
+
# Create the Gradio interface
|
13 |
+
interface = gr.Interface(
|
14 |
+
fn=translate,
|
15 |
+
inputs=gr.Textbox(label="Enter text in English"),
|
16 |
+
outputs=gr.Textbox(label="Translated text in Urdu")
|
17 |
+
)
|
18 |
+
|
19 |
+
# Launch the app
|
20 |
+
interface.launch()
|