Spaces:
Runtime error
Runtime error
| import streamlit as st | |
| from transformers import pipeline | |
| # Load sentiment analysis model | |
| model = "cardiffnlp/twitter-roberta-base-sentiment-latest" | |
| sentiment_analysis = pipeline("text-classification", model=model) | |
| # Streamlit app | |
| def main(): | |
| # Set app title and description | |
| st.title("Sentiment Analysis App") | |
| st.write("Enter text to predict sentiment.") | |
| # User input | |
| text = st.text_area("Text", "") | |
| # Predict sentiment | |
| if st.button("Predict"): | |
| if text.strip() != "": | |
| sentiment = predict_sentiment(text) | |
| score = sentiment['score'] * 100 | |
| st.metric(label = f"Sentiment: {sentiment['label']}", value = f"Score: {score:.2f}%") | |
| #st.write(f"Sentiment: {sentiment['label']}") | |
| #st.write(f"Score: {sentiment['score']}") | |
| else: | |
| st.warning("Please enter some text.") | |
| def predict_sentiment(text): | |
| result = sentiment_analysis(text)[0] | |
| return result | |
| if __name__ == "__main__": | |
| main() |