Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import MarianMTModel, MarianTokenizer
|
3 |
+
|
4 |
+
# Load the model and tokenizer
|
5 |
+
model_name = "Helsinki-NLP/opus-mt-en-hi"
|
6 |
+
tokenizer = MarianTokenizer.from_pretrained(model_name)
|
7 |
+
model = MarianMTModel.from_pretrained(model_name)
|
8 |
+
|
9 |
+
def translate(text):
|
10 |
+
inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True)
|
11 |
+
translated = model.generate(**inputs)
|
12 |
+
return tokenizer.decode(translated[0], skip_special_tokens=True)
|
13 |
+
|
14 |
+
# Gradio interface
|
15 |
+
iface = gr.Interface(
|
16 |
+
fn=translate,
|
17 |
+
inputs=gr.Textbox(label="Enter English Text"),
|
18 |
+
outputs=gr.Textbox(label="Hindi Translation"),
|
19 |
+
title="English to Hindi Translator",
|
20 |
+
description="Enter an English sentence, and the model will translate it into Hindi."
|
21 |
+
)
|
22 |
+
|
23 |
+
iface.launch()
|