Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, MT5ForConditionalGeneration
|
3 |
+
|
4 |
+
# Load tokenizer and model
|
5 |
+
checkpoint = "syubraj/RomanEng2Nep-v2"
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
|
7 |
+
model = MT5ForConditionalGeneration.from_pretrained(checkpoint)
|
8 |
+
|
9 |
+
# Set max sequence length
|
10 |
+
max_seq_len = 20
|
11 |
+
|
12 |
+
# Define the translation function
|
13 |
+
def translate(text):
|
14 |
+
# Tokenize the input text with a max length of 20
|
15 |
+
inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=max_seq_len)
|
16 |
+
|
17 |
+
# Generate translation
|
18 |
+
translated = model.generate(**inputs)
|
19 |
+
|
20 |
+
# Decode the translated tokens back to text
|
21 |
+
translated_text = tokenizer.decode(translated[0], skip_special_tokens=True)
|
22 |
+
return translated_text
|
23 |
+
|
24 |
+
# Gradio interface
|
25 |
+
iface = gr.Interface(
|
26 |
+
fn=translate, # function to use for inference
|
27 |
+
inputs="text", # input type
|
28 |
+
outputs="text", # output type
|
29 |
+
title="Romanized English to Nepali Transliterator",
|
30 |
+
description="Translate Romanized English text into Nepali.",
|
31 |
+
examples=[["ahile"],["prakriti"], ["mahasagar"], ["pradarshan"],["khutkela"], ["nandan"], ["khola"]]
|
32 |
+
)
|
33 |
+
|
34 |
+
# Launch the Gradio app
|
35 |
+
iface.launch()
|