Spaces:
Sleeping
Sleeping
| 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")background-image: url("data:image/png;base64,{img}"); | |
| page_bg_img = f""" | |
| <style> | |
| [data-testid="stAppViewContainer"] > .main {{ | |
| background-image: url("https://i.pinimg.com/originals/6f/6c/15/6f6c1538b050072b002dbc06bedaaf90.jpg"); | |
| background-size: cover; | |
| background-position: center; | |
| background-repeat: no-repeat; | |
| }} | |
| [data-testid="stSidebar"] > div:first-child {{ | |
| 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=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') | |
| 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.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(sentiment_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') | |