Spaces:
Build error
Build error
Ronio Jerico Roque commited on
Commit ·
fb0a511
1
Parent(s): d517f9a
Add Amazon class for handling product data input and telemetry collection
Browse files- classes/amazon.py +125 -0
classes/amazon.py
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from dotenv import load_dotenv
|
| 3 |
+
from helper.telemetry import collect_telemetry
|
| 4 |
+
from helper.upload_File import uploadFile
|
| 5 |
+
from helper.button_behaviour import hide_button
|
| 6 |
+
|
| 7 |
+
class Amazon:
|
| 8 |
+
def __init__(self, model_url):
|
| 9 |
+
self.file_dict = {}
|
| 10 |
+
self.model_url = model_url
|
| 11 |
+
#self.analyst_name = analyst_name
|
| 12 |
+
#self.data_src = data_src
|
| 13 |
+
#self.analyst_description = analyst_description
|
| 14 |
+
self.initialize()
|
| 15 |
+
self.row1()
|
| 16 |
+
|
| 17 |
+
def initialize(self):
|
| 18 |
+
# FOR ENV
|
| 19 |
+
load_dotenv()
|
| 20 |
+
'''
|
| 21 |
+
# AGENT NAME
|
| 22 |
+
st.header(self.analyst_name)
|
| 23 |
+
|
| 24 |
+
# EVALUATION FORM LINK
|
| 25 |
+
url = os.getenv('Link')
|
| 26 |
+
st.write('Evaluation Form: [Link](%s)' % url)
|
| 27 |
+
|
| 28 |
+
# RETURN BUTTON
|
| 29 |
+
try:
|
| 30 |
+
if st.button("Return", type='primary'):
|
| 31 |
+
st.switch_page("./pages/home.py")
|
| 32 |
+
except Exception:
|
| 33 |
+
pass
|
| 34 |
+
'''
|
| 35 |
+
if 'product_title_amazon' not in st.session_state:
|
| 36 |
+
st.session_state['product_title_amazon'] = ''
|
| 37 |
+
if 'images_amazon' not in st.session_state:
|
| 38 |
+
st.session_state['images_amazon'] = ''
|
| 39 |
+
if 'bullet_points_amazon' not in st.session_state:
|
| 40 |
+
st.session_state['bullet_points_amazon'] = ''
|
| 41 |
+
if 'product_description_amazon' not in st.session_state:
|
| 42 |
+
st.session_state['product_description_amazon'] = ''
|
| 43 |
+
|
| 44 |
+
def process(self):
|
| 45 |
+
session = st.session_state.analyze
|
| 46 |
+
if (self.product_title_amazon or self.images_amazon or self.bullet_points_amazon or self.product_description_amazon) and session == 'clicked':
|
| 47 |
+
try:
|
| 48 |
+
product_title_amazon = ""
|
| 49 |
+
images_amazon = ""
|
| 50 |
+
bullet_points_amazon = ""
|
| 51 |
+
product_description_amazon = ""
|
| 52 |
+
|
| 53 |
+
with st.spinner('Aamzon...', show_time=True):
|
| 54 |
+
st.write('')
|
| 55 |
+
# INITIALIZING SESSIONS
|
| 56 |
+
#combined_text += f"Client Summary: {st.session_state.nature}\n"
|
| 57 |
+
try:
|
| 58 |
+
product_title_amazon += f"\nProduct Title: {self.product_title_amazon}"
|
| 59 |
+
except KeyError:
|
| 60 |
+
pass
|
| 61 |
+
try:
|
| 62 |
+
images_amazon += f"\nImages: {self.images_amazon}"
|
| 63 |
+
except KeyError:
|
| 64 |
+
pass
|
| 65 |
+
try:
|
| 66 |
+
bullet_points_amazon += f"\nBullet Points: {self.bullet_points_amazon}"
|
| 67 |
+
except KeyError:
|
| 68 |
+
pass
|
| 69 |
+
try:
|
| 70 |
+
product_description_amazon += f"\nProduct Description: {self.product_description_amazon}"
|
| 71 |
+
except KeyError:
|
| 72 |
+
pass
|
| 73 |
+
|
| 74 |
+
# OUTPUT FOR SEO ANALYST
|
| 75 |
+
#payload_txt = {"question": combined_text}
|
| 76 |
+
#result = self.request_model(payload_txt)
|
| 77 |
+
|
| 78 |
+
#end_time = time.time()
|
| 79 |
+
#time_lapsed = end_time - start_time
|
| 80 |
+
|
| 81 |
+
debug_info_product_title_amazon = {'data_field' : 'Product Title - Amazon', 'result': self.product_title_amazon}
|
| 82 |
+
debug_info_images_amazon = {'data_field' : 'Images - Amazon', 'result': self.images_amazon}
|
| 83 |
+
debug_info_bullet_points_amazon = {'data_field' : 'Bullet Points - Amazon', 'result': self.bullet_points_amazon}
|
| 84 |
+
debug_product_description_amazon = {'data_field' : 'Product Description - Amazon', 'result': self.product_description_amazon}
|
| 85 |
+
|
| 86 |
+
'''
|
| 87 |
+
debug_info = {
|
| 88 |
+
#'analyst': self.analyst_name,
|
| 89 |
+
'url_uuid': self.model_url.split("-")[-1],
|
| 90 |
+
'time_lapsed': time_lapsed,
|
| 91 |
+
'payload': payload_txt,
|
| 92 |
+
'result': result,
|
| 93 |
+
}
|
| 94 |
+
'''
|
| 95 |
+
if self.product_title_amazon:
|
| 96 |
+
st.session_state['product_title_amazon'] = 'uploaded'
|
| 97 |
+
collect_telemetry(debug_info_product_title_amazon)
|
| 98 |
+
if self.images_amazon:
|
| 99 |
+
st.session_state['images_amazon'] = 'uploaded'
|
| 100 |
+
collect_telemetry(debug_info_images_amazon)
|
| 101 |
+
if self.bullet_points_amazon:
|
| 102 |
+
st.session_state['bullet_points_amazon'] = 'uploaded'
|
| 103 |
+
collect_telemetry(debug_info_bullet_points_amazon)
|
| 104 |
+
if self.product_description_amazon:
|
| 105 |
+
st.session_state['product_description_amazon'] = 'uploaded'
|
| 106 |
+
collect_telemetry(debug_product_description_amazon)
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
st.session_state['analyzing'] = False
|
| 110 |
+
except AttributeError:
|
| 111 |
+
st.info("Please upload CSV or PDF files first.")
|
| 112 |
+
hide_button()
|
| 113 |
+
|
| 114 |
+
def row1(self):
|
| 115 |
+
self.product_title_amazon = st.text_input("Product Title - Amazon:", placeholder='Enter Product Title')
|
| 116 |
+
self.images_amazon = st.text_input("Images - Amazon:", placeholder='Enter Images')
|
| 117 |
+
self.bullet_points_amazon = st.text_input("Bullet Points - Amazon:", placeholder='Enter Bullet Points')
|
| 118 |
+
self.product_description_amazon = st.text_input("Product Description - Amazon:", placeholder='Enter Product Description')
|
| 119 |
+
|
| 120 |
+
self.process()
|
| 121 |
+
|
| 122 |
+
if __name__ == "__main__":
|
| 123 |
+
st.set_page_config(layout="wide")
|
| 124 |
+
|
| 125 |
+
upload = uploadFile()
|