Ryleeeee commited on
Commit
5ffe870
·
verified ·
1 Parent(s): 08fb6d2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -18
app.py CHANGED
@@ -17,10 +17,6 @@ st.write("Sentiment classification: positive, neutral, negative")
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,24 +27,21 @@ def sentiment_class(text):
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.")
 
17
  text = st.text_area("Enter the customer review", "")
18
 
19
  def sentiment_class(text):
 
 
 
 
20
  results = sentiment_classifier(text)[0]
21
  max_score = float('-inf')
22
  max_label = ''
 
27
  return max_score, max_label
28
 
29
  def summarize_text(text):
30
+ results = summarizer(text, max_length=100, min_length=5, do_sample=False)
31
+ return results[0]['summary_text']
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 text is None or text.strip() == '':
37
  st.warning("Please enter a customer review first.")
38
  else:
39
  # Perform sentiment analysis on the input text
40
  sentiment_result = sentiment_class(text)
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] == 'LABEL_2': # Change this to match the negative label in your model
46
+ summary = summarize_text(text)
47
+ st.write("Review summary: ", summary)