Spaces:
Sleeping
Sleeping
File size: 2,260 Bytes
695d63f 2d0356a 7901fc5 94c0eb7 7901fc5 c34d627 7901fc5 f1275c9 83caf2e f1275c9 83caf2e 6f6882a 648492d 665760e 22d2c5b 7901fc5 4f574b7 2bb3a11 ed041a7 94c0eb7 ffea153 0a568e5 94c0eb7 02e7577 7901fc5 4f574b7 94c0eb7 02e7577 94c0eb7 6ca2c27 befb2f1 8e21ec3 |
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
#@st.cache_data
#def get_img_as_base64(file):
# with open(file, "rb") as f:
# data = f.read()
# return base64.b64encode(data).decode()
#img = get_img_as_base64("image.jpg")
page_bg_img = f"""
<style>
[data-testid="stAppViewContainer"] > .main {{
background-image: url("https://images.unsplash.com/photo-1501426026826-31c667bdf23d");
background-size: 180%;
background-position: top left;
background-repeat: no-repeat;
background-attachment: local;
}}
[data-testid="stSidebar"] > div:first-child {{
background-image: url("data:image/png;base64,{img}");
background-position: center;
background-repeat: no-repeat;
background-attachment: fixed;
}}
[data-testid="stHeader"] {{
background: rgba(0,0,0,0);
}}
[data-testid="stToolbar"] {{
right: 2rem;
}}
</style>
"""
st.markdown(page_bg_img, unsafe_allow_html=True)
# st.image("logo.png", width=200, height=200)
st.image("logo.png", width=100)
st.subheader(':blue[NLP HUB®]')
st.header('Amazon Sentiment Analysis using FineTuned :green[GPT-2] Pre-Trained Model')
sentiment_model = pipeline(model="ashok2216/gpt2-amazon-sentiment-classifier")
# Example usage:-
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.write("Done")
st.subheader('', divider='rainbow')
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(sentiment_model(text)[0].values())[0] == 'LABEL_1':
output = 'Positive'
else:
output = 'Negative'
sentiments.append(output)
reviews['sentiments'] = sentiments
st.markdown(':rainbow[Output]')
st.dataframe(reviews, use_container_width=True)
# sns.countplot(reviews['sentiments'])
|