File size: 881 Bytes
20240f4
 
 
 
e56c4c7
 
ed4a54d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33b659a
 
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
30
31
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...")