File size: 4,697 Bytes
a4d1f5c
88ba180
 
a4d1f5c
1c283bc
0ebdcd8
1c283bc
 
a4d1f5c
1c283bc
 
 
88ba180
 
1c283bc
 
 
11701c0
1c283bc
 
 
 
 
 
 
 
 
 
 
 
11701c0
0ebdcd8
 
 
 
 
 
a4d1f5c
0ebdcd8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
af6ed2b
0ebdcd8
 
 
 
 
 
 
 
 
 
af6ed2b
88ba180
af6ed2b
 
1c283bc
0ebdcd8
 
1c283bc
059cff4
1c283bc
0ebdcd8
1c283bc
 
 
 
0ebdcd8
 
 
 
059cff4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1c283bc
0ebdcd8
1c283bc
0ebdcd8
1c283bc
059cff4
0ebdcd8
1c283bc
0ebdcd8
 
 
af6ed2b
059cff4
0ebdcd8
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import streamlit as st
from transformers import BertForSequenceClassification, BertTokenizerFast
from emotion_utils import predict  # Custom module for prediction

# Load the BERT model and tokenizer
model_path = "./model/"
model = BertForSequenceClassification.from_pretrained(model_path)
tokenizer = BertTokenizerFast.from_pretrained(model_path)

# Function to update sentiment analysis
def analyze_sentiment(text):
    if text.strip():
        probs, _, label = predict(text, model, tokenizer)
        score = probs.max().item()  # Get the highest probability 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("""
    <style>
        body {
            background: linear-gradient(to right, #6a11cb, #2575fc);
            color: white;
            font-family: 'Segoe UI', sans-serif;
        }
        .stButton button {
            color: white;
            border-radius: 8px;
            font-size: 16px;
            font-weight: bold;
        }
        .stTextArea textarea {
            border-radius: 8px;
        }
        footer {
            font-size: 14px;
            text-align: center;
            padding: 10px;
        }
        footer a {
            color: #2575fc;
            text-decoration: none;
        }
    </style>
""", 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
# 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"""
                <h2 style="text-align:center;">{emoji} Emotion: {label} {emoji}</h2>
                <p style="text-align:center; font-size:20px;">Confidence Score: <strong>{score:.2f}</strong></p>
            """, unsafe_allow_html=True)

            # Add issue reporting section
            st.markdown("""
                <div style="margin-top: 30px; padding: 20px; background-color: rgba(255, 255, 255, 0.1); border-radius: 8px;">
                    <h5 style="text-align: center;">πŸ€” Didn't get the expected result?</h5>
                    <p style="text-align: center; font-size: 16px;">
                        If you believe the emotion detected is incorrect, please let us know! 
                        Your feedback will help us improve our model. Click the button below to report the issue:
                    </p>
                    <div style="text-align: center; margin-top: 10px;">
                        <a href="https://forms.gle/RDT3Zwjpu63GYYZz8" target="_blank" style="text-decoration: none;">
                            <button style="
                                background-color: #2575fc;
                                color: white;
                                padding: 10px 20px;
                                font-size: 16px;
                                font-weight: bold;
                                border: none;
                                border-radius: 8px;
                                cursor: pointer;">
                                Report an Issue 🚨
                            </button>
                        </a>
                    </div>
                </div>
            """, 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("""
    <footer>
        Built with ❀️ by 
        <a href="https://github.com/sumonta056" target="_blank">Sumonta Saha Mridul</a>, 
        <a href="https://github.com/promimojumder38" target="_blank">Promi Mojumder</a>.
    </footer>
""", unsafe_allow_html=True)