File size: 2,366 Bytes
695d63f
2d0356a
7901fc5
 
94c0eb7
7901fc5
c34d627
17899fd
 
6811fb6
c6b3e48
7194376
006465f
5a48b1a
7194376
 
006465f
7194376
006465f
 
7194376
 
 
 
 
6811fb6
83caf2e
 
7194376
6f6882a
006465f
 
2984bac
f37ced0
08ea8eb
 
 
 
847cbae
7901fc5
1dd38d8
7194376
 
 
 
 
7901fc5
dfaf5f4
 
 
 
 
 
f37ced0
 
 
 
 
 
 
 
 
 
1c18727
f37ced0
 
 
 
 
 
 
 
 
 
 
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import pybase64 as base64
import pandas as pd
import streamlit as st
import seaborn as sns
from data_cleaning import preprocess
from transformers import pipeline
from data_integration import scrape_all_pages

    
page_bg_img = """
<style>
.stApp > header { background-color: transparent;}
.stApp {
    background: rgb(80,255,235);
    background: linear-gradient(90deg, rgba(80,255,235,1) 0%,
        rgba(0,0,255,1) 50%, rgba(188,0,255,1) 92%);
    background-size: 150% 150%;
    animation: my_animation 30s ease infinite;
}
@keyframes my_animation {
    0% {background-position: 0% 0%;}
    25% { background-position: 0% 0%;}
    50% {background-position: 100% 100%;}
    75% {background-position: 100% 100%;}
    100% {background-position: 0% 0%;}
}
</style>
"""

st.markdown(page_bg_img, unsafe_allow_html=True)
#st.image("logo.png", width=200, height=200)

st.image("logo.png", width=80)
st.subheader(':violet[NLP HUB®]')
st.markdown("")
st.markdown("")
st.markdown("")
st.markdown("")
st.subheader('Amazon Sentiment Analysis using FineTuned :red[GPT-2] Pre-Trained Model')

@st.cache_resource(experimental_allow_widgets=True)
def load_model():
    sentiment_model = pipeline(model="ashok2216/gpt2-amazon-sentiment-classifier")
    return sentiment_model

model = load_model()

sample_url = 'https://www.amazon.in/Dell-Inspiron-i7-1255U-Processor-Platinum/product-reviews/B0C9F142V6/ref=cm_cr_dp_d_show_all_btm?ie=UTF8&reviewerType=all_reviews'
url = st.text_input("Amazon product link", sample_url)
st.button("Re-run")
st.write("Done")
st.subheader('', divider='rainbow')

try:
    all_reviews = scrape_all_pages(url)
    # Convert to DataFrame for further analysis
    reviews = pd.DataFrame(all_reviews)
    reviews['processed_text'] = reviews['content'].apply(preprocess)
    # st.dataframe(reviews, use_container_width=True)
    # st.markdown(sentiment_model(['It is Super!']))
    
    sentiments = []
    for text in reviews['processed_text']:
        if list(model(text)[0].values())[0] == 'LABEL_1':
            output = 'Positive'
        else:
            output = 'Negative'
        sentiments.append(output)
    
    reviews['sentiments'] = sentiments
    st.markdown(':white[Output]')
    st.dataframe(reviews, use_container_width=True)
    # sns.countplot(reviews['sentiments'])
except KeyError:
    st.markdown('Please :red[Re-run] the app')