File size: 2,048 Bytes
ee1b6ca
 
 
 
 
e91630e
e5d06f2
e91630e
e5d06f2
e91630e
e5d06f2
e91630e
 
 
e5d06f2
 
 
 
 
e91630e
ee1b6ca
 
 
69722dc
ee1b6ca
e5d06f2
 
 
 
ee1b6ca
 
69722dc
 
 
 
 
 
d6eb02e
69722dc
 
 
 
 
d6eb02e
738eec2
d6eb02e
738eec2
d6eb02e
f0603d8
d6eb02e
738eec2
d6eb02e
 
e5d06f2
d6eb02e
 
 
 
 
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
import streamlit as st
from transformers import pipeline

model_path = "citizenlab/twitter-xlm-roberta-base-sentiment-finetunned"

st.set_page_config(page_title="Sentiment Analysis App", layout="wide")

# Set the background color of the Streamlit app using CSS
st.markdown(
    """
    <style>
    body {
        background-color: #FFA500; /* Orange color */
    }
    </style>
    """,
    unsafe_allow_html=True,
)

sentiment_classifier = pipeline("text-classification", model=model_path)

st.title("Sentiment Analysis App")

user_input = st.text_area("Enter a message:", height=150)

if st.button(
    "Analyze Sentiment πŸš€", key="analyze_button", help="Click to analyze sentiment", 
    background_color="black", text_color="white", border_radius=5
):
    if user_input:
        # Perform sentiment analysis
        st.markdown("---")
        with st.spinner('Analyzing...'):
            results = sentiment_classifier(user_input)
            sentiment_label = results[0]["label"]
            sentiment_score = results[0]["score"]

        st.success("Analysis Complete! πŸŽ‰")
        st.write("")

        st.subheader("Sentiment Analysis Result")
        st.write(f"**Sentiment:** {sentiment_label}")
        st.write(f"**Confidence Score:** {sentiment_score:.2f}")

        # Set button colors based on sentiment
        if sentiment_label == "positive":
            button_color = "#3399ff"  # blue color for positive sentiment
        elif sentiment_label == "negative":
            button_color = "#ff3333"  # red color for negative sentiment
        else:
            button_color = "#ff66cc"  # pink color for neutral sentiment

        st.markdown(
            f'<a style="background-color:{button_color};color:white;text-decoration:none;padding:8px 12px;'
            f"border-radius:5px;display:inline-block;margin-top:15px;"
            f'font-weight:bold;" href="https://www.streamlit.io/">'
            f'Share Analysis on Streamlit <span style="font-size:20px;">πŸ”—</span></a>',
            unsafe_allow_html=True,
        )