Sazid2 commited on
Commit
d51ac59
·
verified ·
1 Parent(s): 35c388d

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ # Gradio UI
21
+ demo = gr.Interface(
22
+ fn=translate_text,
23
+ inputs=gr.Textbox(label="Enter Assamese or English text", placeholder="Type here..."),
24
+ outputs=gr.Textbox(label="Translation"),
25
+ title="🇮🇳 Assamese ↔ English Translator",
26
+ description="Fine-tuned model for Assamese ↔ English translation using Helsinki-NLP/opus-mt-mul-en base.",
27
+ theme="soft"
28
+ )
29
+
30
+ if __name__ == "__main__":
31
+ demo.launch()