UCS2014 commited on
Commit
c289c51
·
verified ·
1 Parent(s): 2044ec2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -20
app.py CHANGED
@@ -38,15 +38,16 @@ BOLD_FONT = "Arial Black, Arial, sans-serif" # used for bold axis titles & tick
38
  st.set_page_config(page_title="ST_GeoMech_UCS", page_icon="logo.png", layout="wide")
39
  st.markdown("""
40
  <style>
41
-   /* Reusable logo style */
42
-   .brand-logo { width: 16px; height: auto; object-fit: contain; }
43
 
44
-   /* Sidebar header layout */
45
-   .sidebar-header { display:flex; align-items:center; gap:12px; }
46
-   .sidebar-header .text h1 { font-size: 1.05rem; margin:0; line-height:1.1; }
47
-   .sidebar-header .text .tag { font-size: .85rem; color:#6b7280; margin:2px 0 0; }
48
  </style>
49
  """, unsafe_allow_html=True)
 
50
  # Hide uploader helper text ("Drag and drop file here", limits, etc.)
51
  st.markdown("""
52
  <style>
@@ -198,14 +199,9 @@ def cross_plot_static(actual, pred):
198
  return fig
199
 
200
  # =========================
201
- # Track plot (Plotly)
202
  # =========================
203
-
204
- ticks="outside",
205
- showline=True, linewidth=1.2, linecolor="#444", mirror=True,
206
- showgrid=True, gridcolor="rgba(0,0,0,0.12)", automargin=True
207
- )
208
- return figdef track_plot(df, include_actual=True):
209
  depth_col = next((c for c in df.columns if 'depth' in str(c).lower()), None)
210
  if depth_col is not None:
211
  y = pd.Series(df[depth_col]).astype(float)
@@ -230,14 +226,14 @@ def cross_plot_static(actual, pred):
230
  x=df["UCS_Pred"], y=y, mode="lines",
231
  line=dict(color=COLORS["pred"], width=1.8),
232
  name="UCS_Pred",
233
- hovertemplate="UCS_Pred: %{x:.0f}<br>" + ylab + ": %{y}<extra></extra>"
234
  ))
235
  if include_actual and TARGET in df.columns:
236
  fig.add_trace(go.Scatter(
237
  x=df[TARGET], y=y, mode="lines",
238
  line=dict(color=COLORS["actual"], width=2.0, dash="dot"),
239
  name="UCS (actual)",
240
- hovertemplate="UCS (actual): %{x:.0f}<br>" + ylab + ": %{y}<extra></extra>"
241
  ))
242
 
243
  fig.update_layout(
@@ -252,7 +248,7 @@ def cross_plot_static(actual, pred):
252
  legend_title_text=""
253
  )
254
 
255
- # These must stay inside the function (properly indented)
256
  fig.update_xaxes(
257
  title_text="UCS (psi)",
258
  title_font=dict(size=16, family=BOLD_FONT),
@@ -279,8 +275,7 @@ def cross_plot_static(actual, pred):
279
 
280
  return fig
281
 
282
-
283
- # ---------- Preview modal (matplotlib) ----------
284
  def preview_tracks(df: pd.DataFrame, cols: list[str]):
285
  cols = [c for c in cols if c in df.columns]
286
  n = len(cols)
@@ -470,7 +465,7 @@ if st.session_state.app_step == "dev":
470
  c1,c2,c3 = st.columns(3)
471
  c1.metric("R", f"{m['R']:.2f}"); c2.metric("RMSE", f"{m['RMSE']:.2f}"); c3.metric("MAE", f"{m['MAE']:.2f}")
472
 
473
- # NEW: 2-column layout, big gap, no nested columns, no 0-weights.
474
  col_cross, col_track = st.columns([3, 2], gap="large")
475
  with col_cross:
476
  st.pyplot(cross_plot_static(df[TARGET], df["UCS_Pred"]), use_container_width=True)
@@ -524,7 +519,9 @@ if st.session_state.app_step == "validate":
524
  tbl = df.loc[any_viol, FEATURES].copy()
525
  for c in FEATURES:
526
  if pd.api.types.is_numeric_dtype(tbl[c]): tbl[c] = tbl[c].round(2)
527
- tbl["Violations"] = pd.DataFrame({f:(df[f]<ranges[f][0])|(df[f]>ranges[f][1]) for f in FEATURES}).loc[any_viol].apply(lambda r:", ".join([c for c,v in r.items() if v]), axis=1)
 
 
528
  st.session_state.results["m_val"]={
529
  "R": pearson_r(df[TARGET], df["UCS_Pred"]),
530
  "RMSE": rmse(df[TARGET], df["UCS_Pred"]),
 
38
  st.set_page_config(page_title="ST_GeoMech_UCS", page_icon="logo.png", layout="wide")
39
  st.markdown("""
40
  <style>
41
+ /* Reusable logo style */
42
+ .brand-logo { width: 16px; height: auto; object-fit: contain; }
43
 
44
+ /* Sidebar header layout */
45
+ .sidebar-header { display:flex; align-items:center; gap:12px; }
46
+ .sidebar-header .text h1 { font-size: 1.05rem; margin:0; line-height:1.1; }
47
+ .sidebar-header .text .tag { font-size: .85rem; color:#6b7280; margin:2px 0 0; }
48
  </style>
49
  """, unsafe_allow_html=True)
50
+
51
  # Hide uploader helper text ("Drag and drop file here", limits, etc.)
52
  st.markdown("""
53
  <style>
 
199
  return fig
200
 
201
  # =========================
202
+ # Track plot (Plotly) — FIXED
203
  # =========================
204
+ def track_plot(df, include_actual=True):
 
 
 
 
 
205
  depth_col = next((c for c in df.columns if 'depth' in str(c).lower()), None)
206
  if depth_col is not None:
207
  y = pd.Series(df[depth_col]).astype(float)
 
226
  x=df["UCS_Pred"], y=y, mode="lines",
227
  line=dict(color=COLORS["pred"], width=1.8),
228
  name="UCS_Pred",
229
+ hovertemplate="UCS_Pred: %{x:.0f}<br>"+ylab+": %{y}<extra></extra>"
230
  ))
231
  if include_actual and TARGET in df.columns:
232
  fig.add_trace(go.Scatter(
233
  x=df[TARGET], y=y, mode="lines",
234
  line=dict(color=COLORS["actual"], width=2.0, dash="dot"),
235
  name="UCS (actual)",
236
+ hovertemplate="UCS (actual): %{x:.0f}<br>"+ylab+": %{y}<extra></extra>"
237
  ))
238
 
239
  fig.update_layout(
 
248
  legend_title_text=""
249
  )
250
 
251
+ # Bold axis titles & tick labels
252
  fig.update_xaxes(
253
  title_text="UCS (psi)",
254
  title_font=dict(size=16, family=BOLD_FONT),
 
275
 
276
  return fig
277
 
278
+ # ---------- Preview modal (matplotlib)
 
279
  def preview_tracks(df: pd.DataFrame, cols: list[str]):
280
  cols = [c for c in cols if c in df.columns]
281
  n = len(cols)
 
465
  c1,c2,c3 = st.columns(3)
466
  c1.metric("R", f"{m['R']:.2f}"); c2.metric("RMSE", f"{m['RMSE']:.2f}"); c3.metric("MAE", f"{m['MAE']:.2f}")
467
 
468
+ # clean 2-column layout
469
  col_cross, col_track = st.columns([3, 2], gap="large")
470
  with col_cross:
471
  st.pyplot(cross_plot_static(df[TARGET], df["UCS_Pred"]), use_container_width=True)
 
519
  tbl = df.loc[any_viol, FEATURES].copy()
520
  for c in FEATURES:
521
  if pd.api.types.is_numeric_dtype(tbl[c]): tbl[c] = tbl[c].round(2)
522
+ tbl["Violations"] = pd.DataFrame({f:(df[f]<ranges[f][0])|(df[f]>ranges[f][1]) for f in FEATURES}).loc[any_viol].apply(
523
+ lambda r:", ".join([c for c,v in r.items() if v]), axis=1
524
+ )
525
  st.session_state.results["m_val"]={
526
  "R": pearson_r(df[TARGET], df["UCS_Pred"]),
527
  "RMSE": rmse(df[TARGET], df["UCS_Pred"]),