Wen1201 commited on
Commit
0e299c0
Β·
verified Β·
1 Parent(s): 419f6a0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -3
app.py CHANGED
@@ -228,14 +228,57 @@ with tab1:
228
  # εŸ·θ‘Œεˆ†ζžζŒ‰ιˆ•
229
  st.markdown("---")
230
 
231
- if st.button("πŸš€ Run Analysis", type="primary", use_container_width=True):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
232
  with st.spinner("πŸ”„ Training Bayesian Network..."):
 
 
 
233
  try:
234
  # εˆε§‹εŒ–εˆ†ζžε™¨
 
 
 
235
  analyzer = BayesianNetworkAnalyzer(
236
  session_id=st.session_state.session_id
237
  )
238
 
 
 
 
239
  # εŸ·θ‘Œεˆ†ζž
240
  results = analyzer.run_analysis(
241
  df=df,
@@ -251,16 +294,29 @@ with tab1:
251
  n_bins=n_bins
252
  )
253
 
 
 
 
254
  # ε„²ε­˜η΅ζžœ
255
  st.session_state.analysis_results = results
256
  st.session_state.model_trained = True
257
 
258
- st.success("βœ… Analysis completed!")
 
 
 
 
 
 
 
 
259
  st.rerun()
260
 
261
  except Exception as e:
262
  st.error(f"❌ Error during analysis: {str(e)}")
263
  st.exception(e)
 
 
264
 
265
  with col2:
266
  st.header("Quick Stats")
@@ -459,4 +515,4 @@ st.markdown(
459
  </div>
460
  """.format(st.session_state.session_id[:8]),
461
  unsafe_allow_html=True
462
- )
 
228
  # εŸ·θ‘Œεˆ†ζžζŒ‰ιˆ•
229
  st.markdown("---")
230
 
231
+ col_btn1, col_btn2, col_btn3 = st.columns([2, 1, 1])
232
+
233
+ with col_btn1:
234
+ run_button = st.button("πŸš€ Run Analysis", type="primary", use_container_width=True)
235
+
236
+ with col_btn2:
237
+ if st.button("πŸ”„ Reset", use_container_width=True):
238
+ st.session_state.analysis_results = None
239
+ st.session_state.model_trained = False
240
+ st.session_state.chat_history = []
241
+ st.rerun()
242
+
243
+ with col_btn3:
244
+ with st.popover("ℹ️ Info"):
245
+ st.markdown("""
246
+ **Analysis Steps:**
247
+ 1. Split data (train/test)
248
+ 2. Learn network structure
249
+ 3. Process features (bins from train)
250
+ 4. Estimate parameters
251
+ 5. Evaluate performance
252
+
253
+ **Note:** Test set bins are derived from training set to prevent data leakage.
254
+ """)
255
+
256
+ if run_button:
257
+ # ι©—θ­‰
258
+ if not selected_features:
259
+ st.error("❌ Please select at least one feature!")
260
+ st.stop()
261
+
262
+ if target_variable in selected_features:
263
+ st.error("❌ Target variable cannot be in feature list!")
264
+ st.stop()
265
+
266
  with st.spinner("πŸ”„ Training Bayesian Network..."):
267
+ progress_bar = st.progress(0)
268
+ status_text = st.empty()
269
+
270
  try:
271
  # εˆε§‹εŒ–εˆ†ζžε™¨
272
+ status_text.text("πŸ“Š Initializing analyzer...")
273
+ progress_bar.progress(10)
274
+
275
  analyzer = BayesianNetworkAnalyzer(
276
  session_id=st.session_state.session_id
277
  )
278
 
279
+ status_text.text(f"πŸ“ Learning {algorithm} structure...")
280
+ progress_bar.progress(30)
281
+
282
  # εŸ·θ‘Œεˆ†ζž
283
  results = analyzer.run_analysis(
284
  df=df,
 
294
  n_bins=n_bins
295
  )
296
 
297
+ status_text.text("βœ… Analysis completed!")
298
+ progress_bar.progress(100)
299
+
300
  # ε„²ε­˜η΅ζžœ
301
  st.session_state.analysis_results = results
302
  st.session_state.model_trained = True
303
 
304
+ st.success("βœ… Analysis completed successfully!")
305
+ st.balloons()
306
+
307
+ # ζΈ…η©Ίι€²εΊ¦
308
+ import time
309
+ time.sleep(1)
310
+ progress_bar.empty()
311
+ status_text.empty()
312
+
313
  st.rerun()
314
 
315
  except Exception as e:
316
  st.error(f"❌ Error during analysis: {str(e)}")
317
  st.exception(e)
318
+ progress_bar.empty()
319
+ status_text.empty()
320
 
321
  with col2:
322
  st.header("Quick Stats")
 
515
  </div>
516
  """.format(st.session_state.session_id[:8]),
517
  unsafe_allow_html=True
518
+ )