Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -20,18 +20,26 @@ from sklearn.metrics import mean_squared_error, mean_absolute_error
|
|
| 20 |
# Constants (Ts variant)
|
| 21 |
# =========================
|
| 22 |
APP_NAME = "ST_Sonic_Ts"
|
| 23 |
-
TAGLINE = "Real-Time Shear Slowness (Ts)
|
| 24 |
-
|
| 25 |
-
#
|
| 26 |
-
FEATURES = [
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
MODELS_DIR = Path("models")
|
| 31 |
-
DEFAULT_MODEL = MODELS_DIR / "ts_model.joblib"
|
| 32 |
MODEL_FALLBACKS = [MODELS_DIR / "model.joblib", MODELS_DIR / "model.pkl"]
|
| 33 |
COLORS = {"pred": "#1f77b4", "actual": "#f2b702", "ref": "#5a5a5a"}
|
| 34 |
|
|
|
|
| 35 |
# ---- Plot sizing controls ----
|
| 36 |
CROSS_W = 350
|
| 37 |
CROSS_H = 350
|
|
@@ -216,6 +224,26 @@ def _excel_engine() -> str:
|
|
| 216 |
except Exception:
|
| 217 |
return "openpyxl"
|
| 218 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 219 |
def _excel_safe_name(name: str) -> str:
|
| 220 |
bad = '[]:*?/\\'
|
| 221 |
safe = ''.join('_' if ch in bad else ch for ch in str(name))
|
|
@@ -498,18 +526,19 @@ def track_plot(df, include_actual=True):
|
|
| 498 |
|
| 499 |
# X axis with NO decimals (Ts is in µs/ft; typically integer-like)
|
| 500 |
fig.update_xaxes(
|
| 501 |
-
|
| 502 |
-
|
| 503 |
-
|
| 504 |
-
|
| 505 |
-
|
| 506 |
-
|
| 507 |
-
|
| 508 |
-
|
| 509 |
-
|
| 510 |
-
|
| 511 |
-
|
| 512 |
-
|
|
|
|
| 513 |
fig.update_yaxes(
|
| 514 |
title_text=ylab,
|
| 515 |
title_font=dict(size=20, family=BOLD_FONT, color="#000"),
|
|
|
|
| 20 |
# Constants (Ts variant)
|
| 21 |
# =========================
|
| 22 |
APP_NAME = "ST_Sonic_Ts"
|
| 23 |
+
TAGLINE = "Real-Time Shear Slowness (Ts) Prediction"
|
| 24 |
+
|
| 25 |
+
# Use the exact column headers you have in Excel (from your screenshot)
|
| 26 |
+
FEATURES = [
|
| 27 |
+
"WOB, klbf",
|
| 28 |
+
"Torque(kft.lbf)",
|
| 29 |
+
"SPP(psi)",
|
| 30 |
+
"RPM(1/min)",
|
| 31 |
+
"ROP(ft/h)",
|
| 32 |
+
"Flow Rate, gpm",
|
| 33 |
+
]
|
| 34 |
+
TARGET = "Ts,us/ft_Actual" # actual Ts column in your sheets
|
| 35 |
+
PRED_COL = "Ts_Pred" # predicted Ts column we’ll add
|
| 36 |
|
| 37 |
MODELS_DIR = Path("models")
|
| 38 |
+
DEFAULT_MODEL = MODELS_DIR / "ts_model.joblib" # your uploaded model filename
|
| 39 |
MODEL_FALLBACKS = [MODELS_DIR / "model.joblib", MODELS_DIR / "model.pkl"]
|
| 40 |
COLORS = {"pred": "#1f77b4", "actual": "#f2b702", "ref": "#5a5a5a"}
|
| 41 |
|
| 42 |
+
|
| 43 |
# ---- Plot sizing controls ----
|
| 44 |
CROSS_W = 350
|
| 45 |
CROSS_H = 350
|
|
|
|
| 224 |
except Exception:
|
| 225 |
return "openpyxl"
|
| 226 |
|
| 227 |
+
def _normalize_columns(df: pd.DataFrame) -> pd.DataFrame:
|
| 228 |
+
out = df.copy()
|
| 229 |
+
out.columns = [str(c).strip() for c in out.columns]
|
| 230 |
+
|
| 231 |
+
# Map legacy/alternate headers -> current headers (so older files still pass)
|
| 232 |
+
alias = {
|
| 233 |
+
"WOB(klbf)": "WOB, klbf",
|
| 234 |
+
"TORQUE(kft.lbf)": "Torque(kft.lbf)",
|
| 235 |
+
"Flow Rate, gpm ": "Flow Rate, gpm",
|
| 236 |
+
"Fow Rate, gpm": "Flow Rate, gpm",
|
| 237 |
+
"Fow Rate, gpm ": "Flow Rate, gpm",
|
| 238 |
+
"Ts": "Ts,us/ft_Actual",
|
| 239 |
+
"Ts_Actual": "Ts,us/ft_Actual",
|
| 240 |
+
"Ts (us/ft)": "Ts,us/ft_Actual",
|
| 241 |
+
"Depth": "Depth, ft",
|
| 242 |
+
"Depth(ft)": "Depth, ft",
|
| 243 |
+
}
|
| 244 |
+
out = out.rename(columns={k: v for k, v in alias.items() if k in out.columns})
|
| 245 |
+
return out
|
| 246 |
+
|
| 247 |
def _excel_safe_name(name: str) -> str:
|
| 248 |
bad = '[]:*?/\\'
|
| 249 |
safe = ''.join('_' if ch in bad else ch for ch in str(name))
|
|
|
|
| 526 |
|
| 527 |
# X axis with NO decimals (Ts is in µs/ft; typically integer-like)
|
| 528 |
fig.update_xaxes(
|
| 529 |
+
title_text="Ts (μs/ft)",
|
| 530 |
+
title_font=dict(size=20, family=BOLD_FONT, color="#000"),
|
| 531 |
+
tickfont=dict(size=15, family=BOLD_FONT, color="#000"),
|
| 532 |
+
side="top",
|
| 533 |
+
range=[xmin, xmax],
|
| 534 |
+
ticks="outside",
|
| 535 |
+
tickformat=",.0f", # ← integers; change to ",.1f" if you want one decimal
|
| 536 |
+
tickmode="auto",
|
| 537 |
+
tick0=tick0,
|
| 538 |
+
showline=True, linewidth=1.2, linecolor="#444", mirror=True,
|
| 539 |
+
showgrid=True, gridcolor="rgba(0,0,0,0.12)", automargin=True
|
| 540 |
+
)
|
| 541 |
+
|
| 542 |
fig.update_yaxes(
|
| 543 |
title_text=ylab,
|
| 544 |
title_font=dict(size=20, family=BOLD_FONT, color="#000"),
|