kmanoj's picture
Update app.py
ed4a54d
raw history blame
No virus
881 Bytes
import streamlit as st
from transformers import pipeline
pipe=pipeline('sentiment-analysis')
# Set the title
st.title("Sentiment Analysis")
# Using 'form' to group input elements together
with st.form("sentiment Analysis"):
# Input for text to analyze sentiment
text = st.text_area("Enter text for sentiment analysis:")
# Add a button to analyze sentiment
submit_button = st.form_submit_button("Analyze Sentiment")
# Check if the form was submitted
if text and submit_button:
out = pipe(text)
result = out[0] # Assuming you want the first result if multiple are returned
sentiment = result["label"]
score = round(result["score"], 2) # Round the score to two decimal places
st.write(f"Sentiment: {sentiment}")
st.write(f"Sentiment Score: {score}")
# else:
# st.error("Error: Something went wrong. Please try again...")