nurindahpratiwi
first commit
2cec43b
raw
history blame
1.09 kB
import streamlit as st
from transformers import pipeline
# title
st.title("Sentiment Analysis App")
# subtitle
st.markdown("Enter a text and select a pretrained model to get the sentiment analysis:")
st.markdown("Link to the app - [sentiment-analysis-streamlit on πŸ€— Spaces](https://huggingface.co/spaces/rd448/sentiment-analysis-streamlit)")
# text input
text = st.text_input("Enter text here", "I love you")
# Model selection dropdown
model_names = ["distilbert-base-uncased-finetuned-sst-2-english"]
model = st.selectbox("Select a pretrained model", model_names)
# Sentiment analysis function
def analyze_sentiment(text, model):
if model == "distilbert-base-uncased-finetuned-sst-2-english":
classifier = pipeline("sentiment-analysis", model=model)
result = classifier(text)[0]
sentiment = result['label']
score = result['score']
return sentiment, score
if st.button("Analyze"):
sentiment, score = analyze_sentiment(text, model)
st.write(f"Sentiment: {sentiment}")
if score is not None:
st.write(f"Score: {score}")