Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,7 +17,10 @@ st.write("Sentiment classification: positive, neutral, negative")
|
|
| 17 |
text = st.text_area("Enter the customer review", "")
|
| 18 |
|
| 19 |
def sentiment_class(text):
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
| 21 |
results = sentiment_classifier(text)[0]
|
| 22 |
max_score = float('-inf')
|
| 23 |
max_label = ''
|
|
@@ -28,22 +31,24 @@ def sentiment_class(text):
|
|
| 28 |
return max_score, max_label
|
| 29 |
|
| 30 |
def summarize_text(text):
|
| 31 |
-
print("Text for summarization:", text)
|
| 32 |
results = summarizer(text)[0]['summary_text']
|
| 33 |
return results
|
| 34 |
|
| 35 |
# Perform sentiment analysis when the user clicks the "Classify Sentiment" button
|
| 36 |
if st.button("Classify Sentiment"):
|
| 37 |
# Check if the user has entered a review
|
| 38 |
-
if
|
| 39 |
st.warning("Please enter a customer review first.")
|
| 40 |
else:
|
| 41 |
# Perform sentiment analysis on the input text
|
| 42 |
sentiment_result = sentiment_class(text)
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
text = st.text_area("Enter the customer review", "")
|
| 18 |
|
| 19 |
def sentiment_class(text):
|
| 20 |
+
# Check if the input text is empty or contains only whitespace
|
| 21 |
+
if not text.strip():
|
| 22 |
+
return None
|
| 23 |
+
|
| 24 |
results = sentiment_classifier(text)[0]
|
| 25 |
max_score = float('-inf')
|
| 26 |
max_label = ''
|
|
|
|
| 31 |
return max_score, max_label
|
| 32 |
|
| 33 |
def summarize_text(text):
|
|
|
|
| 34 |
results = summarizer(text)[0]['summary_text']
|
| 35 |
return results
|
| 36 |
|
| 37 |
# Perform sentiment analysis when the user clicks the "Classify Sentiment" button
|
| 38 |
if st.button("Classify Sentiment"):
|
| 39 |
# Check if the user has entered a review
|
| 40 |
+
if not text.strip():
|
| 41 |
st.warning("Please enter a customer review first.")
|
| 42 |
else:
|
| 43 |
# Perform sentiment analysis on the input text
|
| 44 |
sentiment_result = sentiment_class(text)
|
| 45 |
+
if sentiment_result is not None:
|
| 46 |
+
st.write("This review sentiment is", sentiment_result[1])
|
| 47 |
+
st.write("Prediction score is", sentiment_result[0])
|
| 48 |
+
|
| 49 |
+
# Perform text summarization when the review sentiment is classified as negative
|
| 50 |
+
if sentiment_result[1] == 'negative':
|
| 51 |
+
summary = summarize_text(text)
|
| 52 |
+
st.write("Review summary:", summary)
|
| 53 |
+
else:
|
| 54 |
+
st.warning("Please enter a non-empty customer review.")
|