a7madmostafa's picture
Update app.py
c50bd13 verified
raw
history blame contribute delete
No virus
1.07 kB
import streamlit as st
from transformers import pipeline
# Load the models
pipe_5_star = pipeline("text-classification", model="nlptown/bert-base-multilingual-uncased-sentiment")
pipe_pos_neg = pipeline("text-classification", model="distilbert/distilbert-base-uncased-finetuned-sst-2-english")
# Streamlit app
st.title("Sentiment Analysis")
# Dropdown menu for model selection
model_choice = st.selectbox("Choose a model:", ["5-Star Sentiment", "Positive/Negative Sentiment"])
# Input text
user_message = st.text_area("Enter your text:", "")
if st.button("Analyze"):
if user_message:
if model_choice == "5-Star Sentiment":
result = pipe_5_star(user_message)
st.write("Sentiment Analysis (5-Star):")
st.write(result[0]['label'])
elif model_choice == "Positive/Negative Sentiment":
result = pipe_pos_neg(user_message)
st.write("Sentiment Analysis (Positive/Negative):")
st.write(result[0]['label'])
else:
st.error("Please enter a message before analyzing.")