Spaces:
Runtime error
Runtime error
# import streamlit as st | |
# from transformers import pipeline | |
# sentiment_analysis = pipeline("sentiment-analysis") | |
# text = st.text_input("Enter some text") | |
# if text: | |
# result = sentiment_analysis(text) | |
# st.json(result) | |
import streamlit as st | |
from transformers import pipeline, AutoModelForSequenceClassification, AutoTokenizer | |
# Load sentiment analysis model from Hugging Face | |
model_name = "distilbert-base-uncased-finetuned-sst-2-english" | |
model = AutoModelForSequenceClassification.from_pretrained(model_name) | |
tokenizer = AutoTokenizer.from_pretrained(model_name) | |
sentiment_analyzer = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer) | |
# Streamlit UI | |
st.title("Sentiment Analysis App") | |
# User input | |
user_input = st.text_input("Enter a sentence:") | |
if user_input: | |
# Perform sentiment analysis | |
results = sentiment_analyzer(user_input) | |
# Display sentiment and confidence | |
sentiment = results[0]['label'] | |
confidence = results[0]['score'] | |
st.write(f"Sentiment: {sentiment}") | |
st.write(f"Confidence: {confidence:.2f}") |