Sk4467 commited on
Commit
4ac358c
·
1 Parent(s): 019522a

Added streamlit app for HF translator

Browse files
Files changed (1) hide show
  1. app.py +23 -0
app.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
3
+
4
+ # Load model and tokenizer from Hugging Face Model Hub
5
+ MODEL_NAME = "Sk4467/Bengali_translator" # Replace with your model's path on Hugging Face
6
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
7
+ model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_NAME)
8
+
9
+ st.title("English to Bengali Translation")
10
+
11
+ # User input
12
+ english_text = st.text_area("Enter English text:", "")
13
+
14
+ if english_text:
15
+ # Encode the text and generate translation
16
+ encoded = tokenizer.encode(english_text, return_tensors="pt")
17
+ translation_ids = model.generate(encoded)
18
+ bengali_translation = tokenizer.decode(translation_ids[0], skip_special_tokens=True)
19
+
20
+ # Display the translation
21
+ st.write("Bengali Translation:")
22
+ st.write(bengali_translation)
23
+