Spaces:
Build error
Build error
Ronio Jerico Roque commited on
Commit Β·
434b4b7
1
Parent(s): e190b12
Refactor analysis execution to streamline threading and improve error handling for SEM/PPC, Marketplace, and Target Market analyses
Browse files- pages/analyzing_page.py +81 -80
pages/analyzing_page.py
CHANGED
|
@@ -26,9 +26,9 @@ def run_analysis():
|
|
| 26 |
lld_pm_ln_status = st.empty()
|
| 27 |
pull_through_offers_status = st.empty()
|
| 28 |
content_status = st.empty()
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
executive_summary_status = st.empty()
|
| 33 |
snapshot_status = st.empty()
|
| 34 |
|
|
@@ -59,7 +59,7 @@ def run_analysis():
|
|
| 59 |
website_and_tools_status.success("Website and Tools completed successfully.")
|
| 60 |
return result
|
| 61 |
except Exception as e:
|
| 62 |
-
|
| 63 |
return None
|
| 64 |
|
| 65 |
def run_seo_analysis():
|
|
@@ -114,101 +114,102 @@ def run_analysis():
|
|
| 114 |
|
| 115 |
def run_sem_ppc_analysis():
|
| 116 |
try:
|
| 117 |
-
|
| 118 |
result = Sem_PPC(os.getenv('Model_SEM_PPC_Analyst'))
|
| 119 |
-
|
| 120 |
return result
|
| 121 |
except Exception as e:
|
| 122 |
-
|
| 123 |
return None
|
| 124 |
|
| 125 |
def run_marketplace_analysis():
|
| 126 |
try:
|
| 127 |
-
|
| 128 |
result = Marketplace(os.getenv('Model_SEM_PPC_Analyst'))
|
| 129 |
-
|
| 130 |
return result
|
| 131 |
except Exception as e:
|
| 132 |
-
|
| 133 |
return None
|
| 134 |
|
| 135 |
def run_target_market_analysis():
|
| 136 |
try:
|
| 137 |
-
|
| 138 |
result = TargetMarket(os.getenv('Model_Target_Market_Analyst'))
|
| 139 |
-
|
| 140 |
return result
|
| 141 |
except Exception as e:
|
| 142 |
-
|
| 143 |
-
return None
|
| 144 |
-
|
| 145 |
-
def run_snapshot_analysis():
|
| 146 |
-
try:
|
| 147 |
-
snapshot_status.info("Starting Snapshot by Channel Analysis...")
|
| 148 |
-
result = Snapshot(os.getenv('Model_Snapshot_by_Channel_Analyst'))
|
| 149 |
-
snapshot_status.success("Snapshot by Channel Analysis completed successfully.")
|
| 150 |
-
return result
|
| 151 |
-
except Exception as e:
|
| 152 |
-
snapshot_status.error(f"Snapshot by Channel Analysis failed: {e}")
|
| 153 |
-
return None
|
| 154 |
-
|
| 155 |
-
def run_executive_summary_analysis():
|
| 156 |
-
try:
|
| 157 |
-
executive_summary_status.info("Starting Executive Summary Analysis...")
|
| 158 |
-
result = ExecutiveSummary(os.getenv('Model_Executive_Summary_Analyst'))
|
| 159 |
-
executive_summary_status.success("Executive Summary Analysis completed successfully.")
|
| 160 |
-
return result
|
| 161 |
-
except Exception as e:
|
| 162 |
-
executive_summary_status.error(f"Executive Summary Analysis failed: {e}")
|
| 163 |
return None
|
| 164 |
|
| 165 |
-
# Create threads for
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
|
| 192 |
st.markdown("---")
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
# Wait for second batch threads to complete
|
| 210 |
-
for thread in second_batch_threads:
|
| 211 |
-
thread.join()
|
| 212 |
|
| 213 |
st.success("π All analyses completed!") # Final success message
|
| 214 |
|
|
@@ -218,5 +219,5 @@ def run_analysis():
|
|
| 218 |
|
| 219 |
# Execute the analysis
|
| 220 |
if st.button("Back"):
|
| 221 |
-
|
| 222 |
-
run_analysis()
|
|
|
|
| 26 |
lld_pm_ln_status = st.empty()
|
| 27 |
pull_through_offers_status = st.empty()
|
| 28 |
content_status = st.empty()
|
| 29 |
+
sem_ppc = st.empty()
|
| 30 |
+
marketplace = st.empty()
|
| 31 |
+
target_market = st.empty()
|
| 32 |
executive_summary_status = st.empty()
|
| 33 |
snapshot_status = st.empty()
|
| 34 |
|
|
|
|
| 59 |
website_and_tools_status.success("Website and Tools completed successfully.")
|
| 60 |
return result
|
| 61 |
except Exception as e:
|
| 62 |
+
on_page_status.error(f"Website and Tools Analysis failed: {e}")
|
| 63 |
return None
|
| 64 |
|
| 65 |
def run_seo_analysis():
|
|
|
|
| 114 |
|
| 115 |
def run_sem_ppc_analysis():
|
| 116 |
try:
|
| 117 |
+
sem_ppc.info("Starting SEM/PPC Analysis...")
|
| 118 |
result = Sem_PPC(os.getenv('Model_SEM_PPC_Analyst'))
|
| 119 |
+
sem_ppc.success("SEM/PPC Analysis completed successfully.")
|
| 120 |
return result
|
| 121 |
except Exception as e:
|
| 122 |
+
sem_ppc.error(f"SEM/PPC Analysis failed: {e}")
|
| 123 |
return None
|
| 124 |
|
| 125 |
def run_marketplace_analysis():
|
| 126 |
try:
|
| 127 |
+
marketplace.info("Starting Marketplace Analysis...")
|
| 128 |
result = Marketplace(os.getenv('Model_SEM_PPC_Analyst'))
|
| 129 |
+
marketplace.success("Marketplace Analysis completed successfully.")
|
| 130 |
return result
|
| 131 |
except Exception as e:
|
| 132 |
+
marketplace.error(f"Marketplace Analysis failed: {e}")
|
| 133 |
return None
|
| 134 |
|
| 135 |
def run_target_market_analysis():
|
| 136 |
try:
|
| 137 |
+
target_market.info("Starting Target Market Analysis...")
|
| 138 |
result = TargetMarket(os.getenv('Model_Target_Market_Analyst'))
|
| 139 |
+
target_market.success("Target Market Analysis completed successfully.")
|
| 140 |
return result
|
| 141 |
except Exception as e:
|
| 142 |
+
target_market.error(f"Target Market Analysis failed: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
return None
|
| 144 |
|
| 145 |
+
# Create threads for concurrent execution
|
| 146 |
+
off_page_thread = threading.Thread(target=run_off_page_analysis)
|
| 147 |
+
on_page_thread = threading.Thread(target=run_on_page_analysis)
|
| 148 |
+
website_and_tools_thread = threading.Thread(target=run_website_and_tools_analysis)
|
| 149 |
+
seo_thread = threading.Thread(target=run_seo_analysis)
|
| 150 |
+
social_media_thread = threading.Thread(target=run_social_media_analysis)
|
| 151 |
+
llm_pm_ln_thread = threading.Thread(target=run_lld_pm_ln)
|
| 152 |
+
pull_through_offers_thread = threading.Thread(target=run_pull_through_offers)
|
| 153 |
+
content_thread = threading.Thread(target=run_content)
|
| 154 |
+
content_sem_ppc_thread = threading.Thread(target=run_sem_ppc_analysis)
|
| 155 |
+
marketplace_thread = threading.Thread(target=run_marketplace_analysis)
|
| 156 |
+
target_market_thread = threading.Thread(target=run_target_market_analysis)
|
| 157 |
+
|
| 158 |
+
# Attach Streamlit context to threads
|
| 159 |
+
add_script_run_ctx(off_page_thread)
|
| 160 |
+
add_script_run_ctx(on_page_thread)
|
| 161 |
+
add_script_run_ctx(website_and_tools_thread)
|
| 162 |
+
add_script_run_ctx(seo_thread)
|
| 163 |
+
add_script_run_ctx(social_media_thread)
|
| 164 |
+
add_script_run_ctx(llm_pm_ln_thread)
|
| 165 |
+
add_script_run_ctx(pull_through_offers_thread)
|
| 166 |
+
add_script_run_ctx(content_thread)
|
| 167 |
+
add_script_run_ctx(content_sem_ppc_thread)
|
| 168 |
+
add_script_run_ctx(marketplace_thread)
|
| 169 |
+
add_script_run_ctx(target_market_thread)
|
| 170 |
+
|
| 171 |
+
# Start threads
|
| 172 |
+
off_page_thread.start()
|
| 173 |
+
on_page_thread.start()
|
| 174 |
+
website_and_tools_thread.start()
|
| 175 |
+
seo_thread.start()
|
| 176 |
+
social_media_thread.start()
|
| 177 |
+
llm_pm_ln_thread.start()
|
| 178 |
+
pull_through_offers_thread.start()
|
| 179 |
+
content_thread.start()
|
| 180 |
+
content_sem_ppc_thread.start()
|
| 181 |
+
marketplace_thread.start()
|
| 182 |
+
target_market_thread.start()
|
| 183 |
+
|
| 184 |
+
# Wait for threads to complete
|
| 185 |
+
off_page_thread.join()
|
| 186 |
+
on_page_thread.join()
|
| 187 |
+
website_and_tools_thread.join()
|
| 188 |
+
seo_thread.join()
|
| 189 |
+
social_media_thread.join()
|
| 190 |
+
llm_pm_ln_thread.join()
|
| 191 |
+
pull_through_offers_thread.join()
|
| 192 |
+
content_thread.join()
|
| 193 |
+
content_sem_ppc_thread.join()
|
| 194 |
+
marketplace_thread.join()
|
| 195 |
+
target_market_thread.join()
|
| 196 |
|
| 197 |
st.markdown("---")
|
| 198 |
+
snapshot_status.info("Starting Snapshot by Channel Analysis...")
|
| 199 |
+
try:
|
| 200 |
+
snapshot = Snapshot(os.getenv('Model_Snapshot_by_Channel_Analyst'))
|
| 201 |
+
snapshot_status.success("Snapshot by Channel Analysis completed successfully.")
|
| 202 |
+
except Exception as e:
|
| 203 |
+
snapshot_status.error(f"Snapshot by Channel Analysis failed: {e}")
|
| 204 |
+
|
| 205 |
+
executive_summary_status.info("Starting Executive Summary Analysis...")
|
| 206 |
+
try:
|
| 207 |
+
executive_summary = ExecutiveSummary(os.getenv('Model_Executive_Summary_Analyst'))
|
| 208 |
+
executive_summary_status.success("Executive Summary Analysis completed successfully.")
|
| 209 |
+
except Exception as e:
|
| 210 |
+
executive_summary_status.error(f"Executive Summary Analysis failed: {e}")
|
| 211 |
+
st.success("π All analyses completed!") # Final success message
|
| 212 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 213 |
|
| 214 |
st.success("π All analyses completed!") # Final success message
|
| 215 |
|
|
|
|
| 219 |
|
| 220 |
# Execute the analysis
|
| 221 |
if st.button("Back"):
|
| 222 |
+
st.switch_page("pages/home.py")
|
| 223 |
+
run_analysis()
|