Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,19 +2,19 @@ import streamlit as st
|
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
# Load the sentiment analysis model pipeline
|
| 5 |
-
sentiment_classifier = pipeline("text-classification",
|
| 6 |
|
| 7 |
# Load the text summarization model pipeline
|
| 8 |
-
|
| 9 |
|
| 10 |
# Streamlit application title and background image
|
| 11 |
st.image("./header.png", use_column_width=True)
|
| 12 |
st.markdown("<h1 style='text-align: center;'>Customer Review Analysis</h1>", unsafe_allow_html=True)
|
| 13 |
|
| 14 |
-
st.write("
|
| 15 |
|
| 16 |
# User can enter the customer review
|
| 17 |
-
|
| 18 |
|
| 19 |
def sentiment_class(text):
|
| 20 |
results = sentiment_classifier(text)[0]
|
|
@@ -26,22 +26,23 @@ def sentiment_class(text):
|
|
| 26 |
max_label = result['label']
|
| 27 |
return max_score, max_label
|
| 28 |
|
| 29 |
-
def
|
| 30 |
-
results =
|
| 31 |
-
return results
|
|
|
|
| 32 |
|
| 33 |
# Perform sentiment analysis when the user clicks the "Classify Sentiment" button
|
| 34 |
if st.button("Classify Sentiment"):
|
| 35 |
# Check if the user has entered review
|
| 36 |
-
if
|
| 37 |
st.warning("Please enter a customer review first.")
|
| 38 |
else:
|
| 39 |
# Perform sentiment analysis on the input text
|
| 40 |
-
sentiment_result = sentiment_class(
|
| 41 |
st.write("This review sentiment is ", sentiment_result[1])
|
| 42 |
st.write("Prediction score is ", sentiment_result[0])
|
| 43 |
|
| 44 |
-
# Perform text summarization when the review sentiment is classified as negative
|
| 45 |
-
if sentiment_result[1] == '
|
| 46 |
-
|
| 47 |
-
st.write("
|
|
|
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
# Load the sentiment analysis model pipeline
|
| 5 |
+
sentiment_classifier = pipeline("text-classification",model='Ryleeeee/CustomSentimentModel', return_all_scores=True)
|
| 6 |
|
| 7 |
# Load the text summarization model pipeline
|
| 8 |
+
product_categorizer = pipeline("zero-shot-classification", model="MoritzLaurer/deberta-v3-xsmall-zeroshot-v1.1-all-33")
|
| 9 |
|
| 10 |
# Streamlit application title and background image
|
| 11 |
st.image("./header.png", use_column_width=True)
|
| 12 |
st.markdown("<h1 style='text-align: center;'>Customer Review Analysis</h1>", unsafe_allow_html=True)
|
| 13 |
|
| 14 |
+
st.write("Setiment classification: positive, netural, negative")
|
| 15 |
|
| 16 |
# User can enter the customer review
|
| 17 |
+
review = st.text_area("Enter the customer review", "")
|
| 18 |
|
| 19 |
def sentiment_class(text):
|
| 20 |
results = sentiment_classifier(text)[0]
|
|
|
|
| 26 |
max_label = result['label']
|
| 27 |
return max_score, max_label
|
| 28 |
|
| 29 |
+
def product_category(text):
|
| 30 |
+
results = product_categorizer(text)[0]['summary_text']
|
| 31 |
+
return results
|
| 32 |
+
|
| 33 |
|
| 34 |
# Perform sentiment analysis when the user clicks the "Classify Sentiment" button
|
| 35 |
if st.button("Classify Sentiment"):
|
| 36 |
# Check if the user has entered review
|
| 37 |
+
if review is None or review.strip() == '':
|
| 38 |
st.warning("Please enter a customer review first.")
|
| 39 |
else:
|
| 40 |
# Perform sentiment analysis on the input text
|
| 41 |
+
sentiment_result = sentiment_class(review)
|
| 42 |
st.write("This review sentiment is ", sentiment_result[1])
|
| 43 |
st.write("Prediction score is ", sentiment_result[0])
|
| 44 |
|
| 45 |
+
# Perform text summarization when the review sentiment is classified as negative
|
| 46 |
+
if sentiment_result[1] == 'negative':
|
| 47 |
+
category = product_category(review)
|
| 48 |
+
st.write("Product category: ", category)
|