Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -228,14 +228,57 @@ with tab1:
|
|
| 228 |
# ε·θ‘εζζι
|
| 229 |
st.markdown("---")
|
| 230 |
|
| 231 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
)
|