Spaces:
Sleeping
Sleeping
File size: 947 Bytes
1c64d1f 5e4fe51 1c64d1f |
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 |
import streamlit as st
from transformers import pipeline
# Load model with error handling
@st.cache_resource
def load_model():
try:
return pipeline('sentiment-analysis', model="distilbert-base-uncased-finetuned-sst-2-english")
except Exception as e:
st.error(f"Model loading failed: {str(e)}")
st.stop()
classifier = load_model()
# Streamlit UI
st.title("Sentiment Analysis")
user_input = st.text_area("Enter text to analyze:", "I love this simple version!")
if st.button("Analyze"):
if user_input:
try:
result = classifier(user_input)
st.subheader("Result:")
emoji = "😊" if result[0]['label'] == 'POSITIVE' else "😞"
st.write(f"{emoji} **{result[0]['label']}** (confidence: {result[0]['score']:.2%})")
except Exception as e:
st.error(f"Analysis failed: {str(e)}")
else:
st.warning("Please enter some text first!") |