import streamlit as st from transformers import BertForSequenceClassification, BertTokenizerFast, pipeline # Load the BERT model and tokenizer model_path = "./model/" model = BertForSequenceClassification.from_pretrained(model_path) tokenizer = BertTokenizerFast.from_pretrained(model_path) nlp = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer) # Function to update sentiment analysis def analyze_sentiment(text): if text.strip(): result = nlp(text) label = result[0]['label'] score = result[0]['score'] return label, score else: return None, None # Function to get emoji based on emotion def get_emoji(label): if label == "Anger": return "😠" elif label == "Astonished": return "😲" elif label == "Optimistic": return "😊" elif label == "Sadness": return "😢" else: return "🙂" # Streamlit app configuration st.set_page_config( page_title="G-Bert: Emotion Analysis", page_icon="😊", layout="centered" ) # Custom CSS for a modern UI st.markdown(""" """, unsafe_allow_html=True) # Title and description st.title("🌟 G-Bert: Emotion Analysis") st.markdown(""" G-Bert is a bangla sentiment analysis tool that uses a pre-trained BERT model to analyze the emotion of any bengali or religious (gita) text. It can detect emotions like Anger, Astonished, Optimistic, and Sadness with a confidence score. """) # Text input st.write("Enter some text below, and G-Bert will analyze its emotion for you!") text = st.text_area("Input Text", height=150, placeholder="Type your text here...") # Analyze button if st.button("✨ Analyze Emotion ✨"): if text.strip(): label, score = analyze_sentiment(text) if label and score: emoji = get_emoji(label) st.markdown(f"""

{emoji} Emotion: {label} {emoji}

Confidence Score: {score:.2f}

""", unsafe_allow_html=True) else: st.error("🚨 Something went wrong with the analysis.") else: st.warning("⚠️ Please enter some text to analyze.") # Footer with authorship st.markdown("---") st.markdown(""" """, unsafe_allow_html=True)