Spaces:
Sleeping
Sleeping
File size: 1,676 Bytes
200ce40 d0ba749 200ce40 627887f 200ce40 627887f d0ba749 200ce40 627887f d0ba749 200ce40 627887f d0ba749 627887f d0ba749 |
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 |
import streamlit as st
from transformers import pipeline
# Model path
model_path = "citizenlab/twitter-xlm-roberta-base-sentiment-finetuned"
# Set Streamlit page config
st.set_page_config(page_title="Sentiment Analysis App")
# Load sentiment analysis model
sentiment_classifier = pipeline("text-classification", model=model_path, tokenizer=model_path)
# Title and user input
st.title("Sentiment Analysis App")
user_input = st.text_area("Enter a message:")
# Function to add CSS style and icons
def custom_css():
st.markdown(
"""
<style>
/* Add some custom CSS */
.btn {
background-color: #008CBA;
color: white;
padding: 8px 20px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
transition-duration: 0.4s;
cursor: pointer;
border-radius: 8px;
}
/* Add an icon to the button */
.icon {
display: inline-block;
vertical-align: middle;
width: 20px;
height: 20px;
margin-right: 5px;
}
</style>
""",
unsafe_allow_html=True,
)
# Render the custom CSS
custom_css()
# Analyze sentiment button
if st.button("Analyze Sentiment"):
if user_input:
# Perform sentiment analysis
results = sentiment_classifier(user_input)
sentiment_label = results[0]["label"]
sentiment_score = results[0]["score"]
st.write(f"Sentiment: {sentiment_label}")
st.write(f"Confidence Score: {sentiment_score:.2f}")
|