File size: 2,696 Bytes
4996805
 
 
 
 
 
3b4c717
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4996805
3b4c717
4996805
 
 
 
 
 
3b4c717
 
 
 
 
 
 
 
 
 
 
 
4996805
3b4c717
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from transformers import pipeline

# Page settings
st.set_page_config(page_title="Sentiment Analysis App", page_icon="๐Ÿ’ฌ", layout="centered")

# Custom CSS for styling
st.markdown("""
    <style>
    .main-container {
        background-color: #f0f2f6;
        padding: 20px;
        border-radius: 15px;
        max-width: 600px;
        margin: auto;
        box-shadow: 2px 2px 15px rgba(0,0,0,0.1);
    }
    .title {
        text-align: center;
        color: #4CAF50;
        font-size: 2.5em;
        margin-bottom: 10px;
    }
    .subtitle {
        text-align: center;
        color: #555;
        margin-bottom: 30px;
    }
    .result-box {
        background-color: #ffffff;
        padding: 15px;
        border-radius: 10px;
        text-align: center;
        font-size: 1.2em;
        margin-top: 20px;
        box-shadow: 1px 1px 10px rgba(0,0,0,0.05);
    }
    .positive {
        color: #388e3c;
        font-weight: bold;
    }
    .negative {
        color: #d32f2f;
        font-weight: bold;
    }
    .neutral {
        color: #1976d2;
        font-weight: bold;
    }
    </style>
""", unsafe_allow_html=True)

# Load model
@st.cache_resource
def load_model():
    return pipeline("sentiment-analysis")

nlp = load_model()

# Main container
with st.container():
    st.markdown("<div class='main-container'>", unsafe_allow_html=True)

    st.markdown("<div class='title'>๐Ÿ’ฌ Sentiment Analysis</div>", unsafe_allow_html=True)
    st.markdown("<div class='subtitle'>Discover the sentiment behind your words!</div>", unsafe_allow_html=True)

    text = st.text_area("Enter your text here:", height=150, placeholder="Type your sentence...")

    if st.button("โœจ Analyze Sentiment"):
        if not text.strip():
            st.warning("Please enter some text to analyze.")
        else:
            with st.spinner("Analyzing..."):
                result = nlp(text)
                label = result[0]['label']
                score = result[0]['score']

            st.markdown("<div class='result-box'>", unsafe_allow_html=True)

            if label == "POSITIVE":
                st.markdown(f"<span class='positive'>๐Ÿ™‚ Positive Sentiment</span><br>Confidence: {score:.2f}", unsafe_allow_html=True)
            elif label == "NEGATIVE":
                st.markdown(f"<span class='negative'>โ˜น๏ธ Negative Sentiment</span><br>Confidence: {score:.2f}", unsafe_allow_html=True)
            else:
                st.markdown(f"<span class='neutral'>๐Ÿ˜ Neutral Sentiment</span><br>Confidence: {score:.2f}", unsafe_allow_html=True)

            st.markdown("</div>", unsafe_allow_html=True)

    st.markdown("</div>", unsafe_allow_html=True)