Sazid2 commited on
Commit
a232bc9
·
verified ·
1 Parent(s): e1cfd8c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -33
app.py CHANGED
@@ -1,47 +1,49 @@
1
  import gradio as gr
2
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
3
- import torch
4
 
5
- # Load fine-tuned Assamese English model
6
  MODEL_NAME = "Sazid2/assamese-english-translator"
 
 
7
  tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
8
  model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_NAME)
9
 
10
- # Translation function
11
- def translate_text(text):
12
  if not text.strip():
13
- return "⚠️ Please enter some text."
14
- inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
15
- with torch.no_grad():
16
- outputs = model.generate(**inputs, max_length=128)
17
- translation = tokenizer.decode(outputs[0], skip_special_tokens=True)
18
- return translation
19
-
20
- # ---------------------------
21
- # Safe Model Info Section
22
- # ---------------------------
23
- model_info = (
24
- "### 🧠 Model Info\n"
25
- "- **Model Name:** [Sazid2/assamese-english-translator](https://huggingface.co/Sazid2/assamese-english-translator)\n"
26
- "- **Base Model:** Helsinki-NLP/opus-mt-mul-en\n"
27
- "- **Language Pair:** Assamese <-> English\n"
28
- "- **Fine-tuned By:** Abu Sazid Ahmed\n"
29
- "- **Training Epochs:** 8\n"
30
- "- **BLEU Score:** 🏆 38.02\n"
31
- "- **Framework:** 🤗 Transformers (PyTorch)\n"
32
- "- **Dataset:** Custom Assamese-English parallel corpus (~20k sentences)\n"
33
- )
34
 
35
- # ---------------------------
 
 
 
 
36
 
37
- # Gradio UI
38
  demo = gr.Interface(
39
- fn=translate_text,
40
- inputs=gr.Textbox(label="Enter Assamese or English text", placeholder="Type here..."),
41
- outputs=gr.Textbox(label="Translation"),
42
- title="🇮🇳 Assamese ↔ English Translator",
43
- description="Fine-tuned model for Assamese ↔ English translation using Helsinki-NLP/opus-mt-mul-en base.",
44
- theme="soft"
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__":