Spaces:
Sleeping
Sleeping
Rrrrrrrita
commited on
Commit
•
132c5cf
1
Parent(s):
4cfb062
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load the text summarization model pipeline
|
5 |
+
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
6 |
+
|
7 |
+
# Streamlit application title
|
8 |
+
st.title("Sentiment Analysis with text summarization for Singapore Airline")
|
9 |
+
st.write("Summarization first, then sentiment analysis")
|
10 |
+
|
11 |
+
# Text input for user to enter the text to summarize
|
12 |
+
text = st.text_area("Enter the text to analyze", "")
|
13 |
+
|
14 |
+
# Perform text summarization when the user clicks the "Go!" button
|
15 |
+
if st.button("Go!"):
|
16 |
+
# Perform text summarization on the input text
|
17 |
+
results = summarizer(text)[0]['summary_text']
|
18 |
+
st.write("Step 1: Text after summarization:", results)
|
19 |
+
|
20 |
+
# Sentiment analysis as the second step
|
21 |
+
classifier = pipeline("text-classification", model="Rrrrrrrita/Custom_Sentiment", return_all_scores=True)
|
22 |
+
st.write("Classification for 3 emotions: positve, neutral, and negative")
|
23 |
+
|
24 |
+
labels = classifier(text)[0]
|
25 |
+
max_score = float('-inf')
|
26 |
+
max_label = ''
|
27 |
+
|
28 |
+
for label in labels:
|
29 |
+
if label['score'] > max_score:
|
30 |
+
max_score = label['score']
|
31 |
+
max_label = label['label']
|
32 |
+
|
33 |
+
st.write('Step 2: Sentiment Analysis:')
|
34 |
+
st.write("Label:", max_label)
|
35 |
+
st.write("Score:", max_score)
|