Ryleeeee commited on
Commit
672278d
·
verified ·
1 Parent(s): 5ffe870

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -13
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", model='Ryleeeee/CustomSentimentModel', return_all_scores=True)
6
 
7
  # Load the text summarization model pipeline
8
- summarizer = pipeline("summarization", model="MurkatG/review-summarizer-en")
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("Sentiment classification: positive, neutral, negative")
15
 
16
  # User can enter the customer review
17
- text = st.text_area("Enter the customer review", "")
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 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)
 
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)