Spaces:
Sleeping
Sleeping
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}") | |