update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
# Import necessary libraries
|
2 |
import streamlit as st
|
3 |
import numpy as np
|
4 |
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
@@ -6,30 +5,26 @@ from normalizer import normalize
|
|
6 |
|
7 |
# Set the page configuration
|
8 |
st.set_page_config(
|
9 |
-
page_title="
|
10 |
page_icon=":shield:", # Path to a favicon or emoji to be displayed in the browser tab
|
11 |
initial_sidebar_state="auto" # Initial state of the sidebar ("auto", "expanded", or "collapsed")
|
12 |
)
|
13 |
|
14 |
-
|
15 |
# Load custom CSS styling
|
16 |
with open("assets/style.css") as f:
|
17 |
st.markdown("<style>{}</style>".format(f.read()), unsafe_allow_html=True)
|
18 |
|
19 |
# Function to load the pre-trained model
|
20 |
-
# @st.cache_data(experimental_allow_widgets=False)
|
21 |
def get_model():
|
22 |
-
tokenizer = AutoTokenizer.from_pretrained("kazalbrur/BanglaEnglishTokenizerBanglaT5", use_fast=True)
|
23 |
-
model = AutoModelForSeq2SeqLM.from_pretrained("kazalbrur/BanglaEnglishTranslationBanglaT5")
|
24 |
return tokenizer, model
|
25 |
|
26 |
-
|
27 |
# Load the tokenizer and model
|
28 |
tokenizer, model = get_model()
|
29 |
|
30 |
-
|
31 |
# Add a header to the Streamlit app
|
32 |
-
st.header("
|
33 |
|
34 |
# Add placeholder text with custom CSS styling
|
35 |
st.markdown("<span style='color:black'>Enter your Bengali text here</span>", unsafe_allow_html=True)
|
@@ -43,9 +38,6 @@ submit_button = st.button("Translate")
|
|
43 |
# Perform prediction when user input is provided and the submit button is clicked
|
44 |
if user_input and submit_button:
|
45 |
input_ids = tokenizer(normalize(user_input), padding=True, truncation=True, max_length=128, return_tensors="pt").input_ids
|
46 |
-
generated_tokens = model.generate(input_ids, max_new_tokens=128)
|
47 |
decoded_tokens = tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)[0]
|
48 |
-
st.write(f"<span style='color:black'>
|
49 |
-
|
50 |
-
|
51 |
-
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import numpy as np
|
3 |
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
|
|
5 |
|
6 |
# Set the page configuration
|
7 |
st.set_page_config(
|
8 |
+
page_title="Bengali to English Translator App", # Title of the app displayed in the browser tab
|
9 |
page_icon=":shield:", # Path to a favicon or emoji to be displayed in the browser tab
|
10 |
initial_sidebar_state="auto" # Initial state of the sidebar ("auto", "expanded", or "collapsed")
|
11 |
)
|
12 |
|
|
|
13 |
# Load custom CSS styling
|
14 |
with open("assets/style.css") as f:
|
15 |
st.markdown("<style>{}</style>".format(f.read()), unsafe_allow_html=True)
|
16 |
|
17 |
# Function to load the pre-trained model
|
|
|
18 |
def get_model():
|
19 |
+
tokenizer = AutoTokenizer.from_pretrained("kazalbrur/BanglaEnglishTokenizerBanglaT5", use_fast=True)
|
20 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("kazalbrur/BanglaEnglishTranslationBanglaT5")
|
21 |
return tokenizer, model
|
22 |
|
|
|
23 |
# Load the tokenizer and model
|
24 |
tokenizer, model = get_model()
|
25 |
|
|
|
26 |
# Add a header to the Streamlit app
|
27 |
+
st.header("Bengali to English Translator")
|
28 |
|
29 |
# Add placeholder text with custom CSS styling
|
30 |
st.markdown("<span style='color:black'>Enter your Bengali text here</span>", unsafe_allow_html=True)
|
|
|
38 |
# Perform prediction when user input is provided and the submit button is clicked
|
39 |
if user_input and submit_button:
|
40 |
input_ids = tokenizer(normalize(user_input), padding=True, truncation=True, max_length=128, return_tensors="pt").input_ids
|
41 |
+
generated_tokens = model.generate(input_ids, max_new_tokens=128)
|
42 |
decoded_tokens = tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)[0]
|
43 |
+
st.write(f"<span style='color:black'>English Translation: {decoded_tokens}</span>", unsafe_allow_html=True)
|
|
|
|
|
|