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.")