File size: 1,138 Bytes
36d5e6f 49e01a6 36d5e6f 49e01a6 36d5e6f 49e01a6 36d5e6f 49e01a6 36d5e6f 49e01a6 36d5e6f 49e01a6 |
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 |
import streamlit as st
from transformers import pipeline
# Load the sentiment analysis model from Hugging Face
@st.cache_resource # Cache the model for faster loading
def load_model():
return pipeline('sentiment-analysis', model='cardiffnlp/twitter-roberta-base-sentiment')
model = load_model()
# Streamlit UI
st.title("Sentiment Analysis App using GenAI Models")
# Text input from the user
user_input = st.text_area("Enter text to analyze sentiment:")
# Prediction button
if st.button("Analyze"):
if user_input:
# Perform prediction
result = model(user_input) # Hugging Face pipeline returns a dictionary
sentiment = result[0]['label'] # Get sentiment label (Positive/Negative/Neutral)
confidence = result[0]['score'] # Confidence score
# Display the sentiment and confidence score
st.write(f"**Predicted Sentiment:** {sentiment}")
st.write(f"**Confidence Score:** {confidence:.2f}")
else:
st.warning("Please enter some text to analyze.")
# Optional: Footer
st.write("---")
st.caption("Built with Streamlit and Hugging Face's GenAI models.")
|