Rrrrrrrita's picture
Create app.py
132c5cf verified
raw
history blame
1.28 kB
import streamlit as st
from transformers import pipeline
# Load the text summarization model pipeline
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
# Streamlit application title
st.title("Sentiment Analysis with text summarization for Singapore Airline")
st.write("Summarization first, then sentiment analysis")
# Text input for user to enter the text to summarize
text = st.text_area("Enter the text to analyze", "")
# Perform text summarization when the user clicks the "Go!" button
if st.button("Go!"):
# Perform text summarization on the input text
results = summarizer(text)[0]['summary_text']
st.write("Step 1: Text after summarization:", results)
# Sentiment analysis as the second step
classifier = pipeline("text-classification", model="Rrrrrrrita/Custom_Sentiment", return_all_scores=True)
st.write("Classification for 3 emotions: positve, neutral, and negative")
labels = classifier(text)[0]
max_score = float('-inf')
max_label = ''
for label in labels:
if label['score'] > max_score:
max_score = label['score']
max_label = label['label']
st.write('Step 2: Sentiment Analysis:')
st.write("Label:", max_label)
st.write("Score:", max_score)