File size: 2,270 Bytes
7bacf44
 
cd7441f
 
672278d
cd7441f
fd16468
 
e93d87a
cd7441f
1d4bd7d
1eb4c51
cd7441f
fd16468
 
 
 
7bacf44
 
672278d
7bacf44
565b361
 
7bacf44
 
 
a1fb972
 
 
565b361
e93d87a
672278d
a1dc42b
672278d
 
e93d87a
565b361
1eb4c51
5ffe870
672278d
3db428e
1eb4c51
 
672278d
4cd5c70
 
5ffe870
672278d
 
e51da38
4da51f1
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import streamlit as st
from transformers import pipeline

# Load the sentiment analysis model pipeline
sentiment_classifier = pipeline("text-classification",model='Ryleeeee/CustomSentimentModel', return_all_scores=True)

# Load the product category classification model pipeline
product_categorizer = pipeline("text-classification", model="Ryleeeee/CustomProductCategoryModel")

# Streamlit application title and background image
st.image("./header.png", use_column_width=True)
st.markdown("<h1 style='text-align: center;'>Customer Review Analysis</h1>", unsafe_allow_html=True)

st.write("Sentiment classification: positive, netural, negative")
st.write("Product category classification: books, mobile, mobile accessories, refrigerator, smartTv")

product_dic = {0: "books", 1: "mobile", 2: "mobile accessories", 3: "refrigerator", 4: "smartTv"}

# User can enter the customer review
review = st.text_area("Enter the customer review", "")

def sentiment_class(text):
    results = sentiment_classifier(text)[0]
    max_score = float('-inf')
    max_label = ''
    for result in results:
        if result['score'] > max_score:
            max_score = result['score']
            max_label = result['label']
    return max_score, max_label

def product_category(text):
    results = product_categorizer(text)[0]
    return results


# Perform sentiment analysis when the user clicks the "Classify Sentiment" button
if st.button("Classify Sentiment"):
    # Check if the user has entered review
    if review is None or review.strip() == '':
        st.warning("Please enter a customer review first.")
    else:
        # Perform sentiment analysis on the input text
        sentiment_result = sentiment_class(review)
        st.write("Review sentiment: ", sentiment_result[1])
        st.write("Prediction score: ", sentiment_result[0])

        # Perform text summarization when the review sentiment is classified as negative           
        if sentiment_result[1] == 'negative':
            category = product_dic[int(product_category(review)["label"].split("_")[1])]
            predic_score = product_category(review)["score"]
            st.write("Category of the faulty product: ", category)
            st.write("Prediction score: ", predic_score)