Ronio Jerico Roque commited on
Commit
87902a2
·
1 Parent(s): acd49a3

Refactor session state initialization and processing in ClientSummary and Sem_PPC classes for improved clarity and error handling

Browse files
Files changed (2) hide show
  1. classes/client_summary.py +40 -40
  2. classes/sem_ppc.py +135 -60
classes/client_summary.py CHANGED
@@ -1,5 +1,4 @@
1
  import streamlit as st
2
- import threading
3
  from dotenv import load_dotenv
4
  from helper.telemetry import collect_telemetry
5
  from helper.upload_File import uploadFile
@@ -13,50 +12,51 @@ class ClientSummary:
13
  self.row1()
14
 
15
  def initialize(self):
 
16
  load_dotenv()
17
- for key in ['client_summary', 'client_name', 'client_website', 'target_market']:
18
- if key not in st.session_state:
19
- st.session_state[key] = ''
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
- def run_in_background(self):
22
- try:
23
- client_summary = f"Client Summary: {self.client_summary}\n" if self.client_summary else ""
24
- client_name = f"{self.name}\n" if self.name else ""
25
- client_website = f"{self.website}\n" if self.website else ""
26
-
27
- debug_client_summary = {'data_field': 'Client Summary', 'result': client_summary}
28
- debug_client_name = {'data_field': 'Client Name', 'result': client_name}
29
- debug_client_website = {'data_field': 'Client Website', 'result': client_website}
30
-
31
- if self.client_summary:
32
- st.session_state['client_summary'] = 'uploaded'
33
- st.session_state['target_market'] = 'uploaded'
34
- collect_telemetry(debug_client_summary)
35
- if self.name:
36
- st.session_state['client_name'] = 'uploaded'
37
- collect_telemetry(debug_client_name)
38
- if self.website:
39
- st.session_state['client_website'] = 'uploaded'
40
- collect_telemetry(debug_client_website)
41
-
42
- except Exception as e:
43
- st.error(f"Error during Client Summary processing: {e}")
44
-
45
- st.session_state['analyzing'] = False
46
-
47
- def process(self):
48
- with st.spinner('Uploading Client Details...'):
49
- thread = threading.Thread(target=self.run_in_background)
50
- thread.start()
51
 
 
 
 
 
 
 
 
 
 
 
 
52
  def row1(self):
53
- self.client_summary = st.text_area("Client Summary:", help="Name of business, nature of business, location, products/services")
54
- self.name = st.text_input("Client Name:")
55
- self.website = st.text_input("Client Website:")
 
56
 
57
- session = st.session_state.get('analyze')
58
- if (self.client_summary or self.name or self.website) and session == 'clicked':
59
- self.process()
60
 
61
 
62
  if __name__ == "__main__":
 
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
 
12
  self.row1()
13
 
14
  def initialize(self):
15
+ # FOR ENV
16
  load_dotenv()
17
+ if 'client_summary' not in st.session_state:
18
+ st.session_state['client_summary'] = ''
19
+ if 'client_name' not in st.session_state:
20
+ st.session_state['client_name'] = ''
21
+ if 'client_website' not in st.session_state:
22
+ st.session_state['client_website'] = ''
23
+ if 'target_market' not in st.session_state:
24
+ st.session_state['target_market'] = ''
25
+
26
+ def process (self):
27
+ with st.spinner('Uploading Client Details...', show_time=True):
28
+ st.write('')
29
+ client_summary = ""
30
+ client_name = ""
31
+ client_website = ""
32
+ #
33
+ client_summary = f"Client Summary: {self.client_summary}\n"
34
+ client_name = f"{self.name}\n"
35
+ client_website = f"{self.website}\n"
36
 
37
+ debug_client_summary = {'data_field' : 'Client Summary', 'result': client_summary}
38
+ debug_client_name = {'data_field' : 'Client Name', 'result': client_name}
39
+ debug_client_website = {'data_field' : 'Client Website', 'result': client_website}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
+ if self.client_summary:
42
+ st.session_state['client_summary'] = 'uploaded'
43
+ st.session_state['target_market'] = 'uploaded'
44
+ collect_telemetry(debug_client_summary)
45
+ if self.name:
46
+ st.session_state['client_name'] = 'uploaded'
47
+ collect_telemetry(debug_client_website)
48
+ if self.website:
49
+ st.session_state['client_website'] = 'uploaded'
50
+ collect_telemetry(debug_client_name)
51
+
52
  def row1(self):
53
+ self.client_summary = st.text_area("Client Summary:", help="Name of business, nature of business, location, products/services")
54
+ session = st.session_state.analyze
55
+ self.name = st.text_input("Client Name:")
56
+ self.website = st.text_input("Client Website:")
57
 
58
+ if (self.client_summary or self.name or self.website) and session == 'clicked':
59
+ self.process()
 
60
 
61
 
62
  if __name__ == "__main__":
classes/sem_ppc.py CHANGED
@@ -1,5 +1,4 @@
1
  import streamlit as st
2
- import threading
3
  from dotenv import load_dotenv
4
  from helper.telemetry import collect_telemetry
5
  from helper.upload_File import uploadFile
@@ -10,77 +9,153 @@ class Sem_PPC:
10
  def __init__(self, model_url):
11
  self.file_dict = {}
12
  self.model_url = model_url
13
- load_dotenv()
 
 
14
  self.initialize()
15
  self.row1()
16
 
17
  def initialize(self):
18
- for key in ['account_set_up', 'search_ads', 'display_ads', 'mobile_ads', 'video_ads', 'shopping_ads']:
19
- if key not in st.session_state:
20
- st.session_state[key] = ''
 
 
 
 
 
 
21
 
22
- def run_in_background(self):
23
  try:
24
- account_set_up = f"\nAccount Set Up: {self.account_set_up}" if self.account_set_up else ""
25
- search_ads = "\nSearch Ads" if self.search_ads else ""
26
- display_ads = "\nDisplay Ads" if self.display_ads else ""
27
- mobile_ads = "\nMobile Ads" if self.mobile_ads else ""
28
- video_ads = "\nVideo Ads" if self.video_ads else ""
29
- shopping_ads = "\nShopping Ads" if self.shopping_ads else ""
 
 
 
 
 
 
 
 
 
 
 
30
 
31
- # Simulated payload / model call here if needed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
- # Logging/Telemetry (each individually)
34
- if self.account_set_up:
35
- st.session_state['account_set_up'] = 'uploaded'
36
- collect_telemetry({'data_field': 'Account Set Up - Google Ads', 'result': account_set_up})
37
- if self.search_ads:
38
- st.session_state['search_ads'] = 'uploaded'
39
- collect_telemetry({'data_field': 'Search Ads - Google Ads/SEMRush', 'result': search_ads})
40
- if self.display_ads:
41
- st.session_state['display_ads'] = 'uploaded'
42
- collect_telemetry({'data_field': 'Display Ads - Google Ads/SEMRush', 'result': display_ads})
43
- if self.mobile_ads:
44
- st.session_state['mobile_ads'] = 'uploaded'
45
- collect_telemetry({'data_field': 'Mobile Ads - Google Ads', 'result': mobile_ads})
46
- if self.video_ads:
47
- st.session_state['video_ads'] = 'uploaded'
48
- collect_telemetry({'data_field': 'Video Ads - Google Ads', 'result': video_ads})
49
- if self.shopping_ads:
50
- st.session_state['shopping_ads'] = 'uploaded'
51
- collect_telemetry({'data_field': 'Shopping Ads - Google Ads/SEMRush', 'result': shopping_ads})
52
 
53
- except Exception as e:
54
- st.error(f"Error during SEM/PPC processing: {e}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
 
56
- st.session_state['analyzing'] = False
57
-
58
- def process(self):
59
- session = st.session_state.get('analyze')
60
- if session == 'clicked' and (
61
- self.account_set_up or self.search_ads or self.display_ads or
62
- self.mobile_ads or self.video_ads or self.shopping_ads
63
- ):
64
- try:
65
- with st.spinner("Uploading SEM/PPC..."):
66
- # Launch processing thread
67
- thread = threading.Thread(target=self.run_in_background)
68
- thread.start()
69
- except AttributeError:
70
- st.info("Please upload CSV or PDF files first.")
71
- hide_button()
72
 
73
  def row1(self):
74
- self.account_set_up = st.text_input("Account Set Up - Google Ads:", placeholder='Enter Account Set Up')
75
- self.search_ads = st.checkbox("Search Ads - Google Ads/SEMRush")
76
- self.display_ads = st.checkbox("Display Ads - Google Ads/SEMRush")
77
- self.mobile_ads = st.checkbox("Mobile Ads - Google Ads")
78
- self.video_ads = st.checkbox("Video Ads - Google Ads")
79
- self.shopping_ads = st.checkbox("Shopping Ads - Google Ads/SEMRush")
80
-
81
- self.process()
82
-
83
 
 
 
 
 
 
 
 
 
 
 
84
  if __name__ == "__main__":
85
  st.set_page_config(layout="wide")
86
- upload = uploadFile()
 
 
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
 
9
  def __init__(self, model_url):
10
  self.file_dict = {}
11
  self.model_url = model_url
12
+ #self.analyst_name = analyst_name
13
+ #self.data_src = data_src
14
+ #self.analyst_description = analyst_description
15
  self.initialize()
16
  self.row1()
17
 
18
  def initialize(self):
19
+ # FOR ENV
20
+ load_dotenv()
21
+ '''
22
+ # AGENT NAME
23
+ st.header(self.analyst_name)
24
+
25
+ # EVALUATION FORM LINK
26
+ url = os.getenv('Link')
27
+ st.write('Evaluation Form: [Link](%s)' % url)
28
 
29
+ # RETURN BUTTON
30
  try:
31
+ if st.button("Return", type='primary'):
32
+ st.switch_page("./pages/home.py")
33
+ except Exception:
34
+ pass
35
+ '''
36
+ if 'account_set_up' not in st.session_state:
37
+ st.session_state['account_set_up'] = ''
38
+ if 'search_ads' not in st.session_state:
39
+ st.session_state['search_ads'] = ''
40
+ if 'display_ads' not in st.session_state:
41
+ st.session_state['display_ads'] = ''
42
+ if 'mobile_ads' not in st.session_state:
43
+ st.session_state['mobile_ads'] = ''
44
+ if 'video_ads' not in st.session_state:
45
+ st.session_state['video_ads'] = ''
46
+ if 'shopping_ads' not in st.session_state:
47
+ st.session_state['shopping_ads'] = ''
48
 
49
+ def process(self):
50
+ session = st.session_state.analyze
51
+ if (self.account_set_up or self.search_ads or self.display_ads or self.mobile_ads or self.video_ads or self.shopping_ads) and session == 'clicked':
52
+ try:
53
+ account_set_up = ""
54
+ search_ads = ""
55
+ display_ads = ""
56
+ mobile_ads = ""
57
+ video_ads = ""
58
+ shopping_ads = ""
59
+ with st.spinner('Uploading SEM/PPC...', show_time=True):
60
+ st.write('')
61
+ # INITIALIZING SESSIONS
62
+ #combined_text += f"Client Summary: {st.session_state.nature}\n"
63
+ try:
64
+ account_set_up += f"\nAccount Set Up: {self.account_set_up}"
65
+ except KeyError:
66
+ pass
67
+ try:
68
+ search_ads += f"\nSearch Ads: {self.search_ads}"
69
+ except KeyError:
70
+ pass
71
+ try:
72
+ display_ads += f"\nDisplay Ads: {self.display_ads}"
73
+ except KeyError:
74
+ pass
75
+ try:
76
+ mobile_ads += f"\nMobile Ads: {self.mobile_ads}"
77
+ except KeyError:
78
+ pass
79
+ try:
80
+ video_ads += f"\nVideo Ads: {self.video_ads}"
81
+ except KeyError:
82
+ pass
83
+ try:
84
+ shopping_ads += f"\nShopping Ads: {self.shopping_ads}"
85
+ except KeyError:
86
+ pass
87
 
88
+ # OUTPUT FOR SEO ANALYST
89
+ #payload_txt = {"question": combined_text}
90
+ #result = self.request_model(payload_txt)
91
+
92
+ #end_time = time.time()
93
+ #time_lapsed = end_time - start_time
94
+
95
+ debug_info_account_set_up = {'data_field' : 'Account Set Up - Google Ads', 'result': account_set_up}
96
+ debug_info_search_ads = {'data_field' : 'Search Ads - Google Ads/SEMRush', 'result': search_ads}
97
+ debug_info_display_ads = {'data_field' : 'Display Ads - Google Ads/SEMRush', 'result': display_ads}
98
+ debug_info_mobile_ads = {'data_field' : 'Mobile Ads - Google Ads', 'result': mobile_ads}
99
+ debug_info_video_ads = {'data_field' : 'Video Ads - Google Ads', 'result': video_ads}
100
+ debug_info_shopping_ads = {'data_field' : 'Shopping Ads - Google Ads/SEMRush', 'result': shopping_ads}
 
 
 
 
 
 
101
 
102
+ '''
103
+ debug_info = {
104
+ #'analyst': self.analyst_name,
105
+ 'url_uuid': self.model_url.split("-")[-1],
106
+ 'time_lapsed': time_lapsed,
107
+ 'payload': payload_txt,
108
+ 'result': result,
109
+ }
110
+ '''
111
+ if self.account_set_up:
112
+ st.session_state['account_set_up'] = 'uploaded'
113
+ collect_telemetry(debug_info_account_set_up)
114
+ if self.search_ads:
115
+ st.session_state['search_ads'] = 'uploaded'
116
+ collect_telemetry(debug_info_search_ads)
117
+ if self.display_ads:
118
+ st.session_state['display_ads'] = 'uploaded'
119
+ collect_telemetry(debug_info_display_ads)
120
+ if self.mobile_ads:
121
+ st.session_state['mobile_ads'] = 'uploaded'
122
+ collect_telemetry(debug_info_mobile_ads)
123
+ if self.video_ads:
124
+ st.session_state['video_ads'] = 'uploaded'
125
+ collect_telemetry(debug_info_video_ads)
126
+ if self.shopping_ads:
127
+ st.session_state['shopping_ads'] = 'uploaded'
128
+ collect_telemetry(debug_info_shopping_ads)
129
+
130
+
131
+
132
+ #with st.expander("Debug information", icon="⚙"):
133
+ # st.write(debug_info)
134
 
135
+ st.session_state['analyzing'] = False
136
+ except AttributeError:
137
+ st.info("Please upload CSV or PDF files first.")
138
+ hide_button()
 
 
 
 
 
 
 
 
 
 
 
 
139
 
140
  def row1(self):
141
+ self.account_set_up = st.text_input("Account Set Up - Google Ads:", placeholder='Enter Account Set Up')
142
+ self.search_ads = st.checkbox("Search Ads - Google Ads/SEMRush")
143
+ self.display_ads = st.checkbox("Display Ads - Google Ads/SEMRush")
144
+ self.mobile_ads = st.checkbox("Mobile Ads - Google Ads")
145
+ self.video_ads = st.checkbox("Video Ads - Google Ads")
146
+ self.shopping_ads = st.checkbox("Shopping Ads - Google Ads/SEMRush")
 
 
 
147
 
148
+ '''
149
+ st.write("") # FOR THE HIDE BUTTON
150
+ st.write("") # FOR THE HIDE BUTTON
151
+ st.write("AI Analyst Output: ")
152
+ st.session_state['analyzing'] = False
153
+ st.write("") # FOR THE HIDE BUTTON'
154
+ '''
155
+ #analyze_button = st.button("Analyze", disabled=initialize_analyze_session())
156
+ self.process()
157
+
158
  if __name__ == "__main__":
159
  st.set_page_config(layout="wide")
160
+
161
+ upload = uploadFile()