|
import streamlit as st |
|
from transformers import pipeline |
|
|
|
|
|
@st.cache_resource |
|
def load_model(): |
|
return pipeline('sentiment-analysis', model='cardiffnlp/twitter-roberta-base-sentiment') |
|
|
|
model = load_model() |
|
|
|
|
|
st.title("Sentiment Analysis App using GenAI Models") |
|
|
|
|
|
user_input = st.text_area("Enter text to analyze sentiment:") |
|
|
|
|
|
if st.button("Analyze"): |
|
if user_input: |
|
|
|
result = model(user_input) |
|
sentiment = result[0]['label'] |
|
confidence = result[0]['score'] |
|
|
|
|
|
st.write(f"**Predicted Sentiment:** {sentiment}") |
|
st.write(f"**Confidence Score:** {confidence:.2f}") |
|
else: |
|
st.warning("Please enter some text to analyze.") |
|
|
|
|
|
st.write("---") |
|
st.caption("Built with Streamlit and Hugging Face's GenAI models.") |
|
|