Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,47 +1,49 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 3 |
-
import torch
|
| 4 |
|
| 5 |
-
#
|
| 6 |
MODEL_NAME = "Sazid2/assamese-english-translator"
|
|
|
|
|
|
|
| 7 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
| 8 |
model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_NAME)
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
if not text.strip():
|
| 13 |
-
return "⚠️ Please enter
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
return
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
"- **Framework:** 🤗 Transformers (PyTorch)\n"
|
| 32 |
-
"- **Dataset:** Custom Assamese-English parallel corpus (~20k sentences)\n"
|
| 33 |
-
)
|
| 34 |
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
-
# Gradio
|
| 38 |
demo = gr.Interface(
|
| 39 |
-
fn=
|
| 40 |
-
inputs=gr.Textbox(label="Enter Assamese
|
| 41 |
-
outputs=gr.Textbox(label="Translation"),
|
| 42 |
-
title=
|
| 43 |
-
description=
|
| 44 |
-
|
| 45 |
)
|
| 46 |
|
| 47 |
if __name__ == "__main__":
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
|
|
|
| 3 |
|
| 4 |
+
# Your model on Hugging Face
|
| 5 |
MODEL_NAME = "Sazid2/assamese-english-translator"
|
| 6 |
+
|
| 7 |
+
# Load model and tokenizer
|
| 8 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
| 9 |
model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_NAME)
|
| 10 |
|
| 11 |
+
def translate(text):
|
| 12 |
+
"""Translate Assamese text → English"""
|
| 13 |
if not text.strip():
|
| 14 |
+
return "⚠️ Please enter Assamese text."
|
| 15 |
+
|
| 16 |
+
inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True)
|
| 17 |
+
outputs = model.generate(**inputs, max_length=128)
|
| 18 |
+
translated = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 19 |
+
return translated
|
| 20 |
+
|
| 21 |
+
title = "🌐 Assamese → English Translator"
|
| 22 |
+
description = """
|
| 23 |
+
### Fine-tuned Neural Machine Translation
|
| 24 |
+
This model translates **Assamese sentences to English**.
|
| 25 |
+
It is based on the **Helsinki-NLP/opus-mt-mul-en** model and fine-tuned on Assamese-English parallel data.
|
| 26 |
+
|
| 27 |
+
- 🔤 **Source language:** Assamese
|
| 28 |
+
- 🌍 **Target language:** English
|
| 29 |
+
- 🧠 **BLEU Score:** 38.02
|
| 30 |
+
- 🧩 **Framework:** Hugging Face Transformers
|
| 31 |
+
"""
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
+
examples = [
|
| 34 |
+
["মই কামলৈ গৈছো।"],
|
| 35 |
+
["তুমি ক'ত আছা?"],
|
| 36 |
+
["সেইখন অত্যন্ত ধুনীয়া।"]
|
| 37 |
+
]
|
| 38 |
|
| 39 |
+
# Build Gradio interface
|
| 40 |
demo = gr.Interface(
|
| 41 |
+
fn=translate,
|
| 42 |
+
inputs=gr.Textbox(label="Enter Assamese text"),
|
| 43 |
+
outputs=gr.Textbox(label="English Translation"),
|
| 44 |
+
title=title,
|
| 45 |
+
description=description,
|
| 46 |
+
examples=examples,
|
| 47 |
)
|
| 48 |
|
| 49 |
if __name__ == "__main__":
|