-
Notifications
You must be signed in to change notification settings - Fork 0
/
st_app.py
78 lines (61 loc) · 2.78 KB
/
st_app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import streamlit as st
import pandas as pd
import xgboost as xgb
# Load the pre-trained XGBoost model
model = xgb.XGBRegressor()
model.load_model("based_us_sans_trampush_early_stopping_combat_overfitting.ubj")
st.set_page_config(
page_title="BASED",
page_icon="🌊",
layout="wide",
initial_sidebar_state="expanded",
)
def predict(slope, discharge, width):
"""
Function for making predictions using the XGBoost model.
"""
# Prepare the input features for prediction
input_data = pd.DataFrame({'width': width, 'slope': slope, 'discharge': discharge}, index=[0], dtype=float)
# Make the prediction using the XGBoost model
prediction = model.predict(input_data)
# Return the prediction
return {"depth": float(prediction[0])}
def main():
st.title("🌊 Boost-Assisted Stream Estimator for Depth (BASED)")
st.sidebar.title("Input Values")
slope = st.sidebar.text_input("Slope [m/m]:", "0.0001")
discharge = st.sidebar.text_input("Discharge [m³/s]:", "400")
width = st.sidebar.text_input("Width [m]:", "250")
if slope and discharge and width:
try:
slope = float(slope)
discharge = float(discharge)
width = float(width)
prediction = predict(slope, discharge, width)
depth = prediction["depth"]
st.metric("Predicted Depth", f"{depth:.2f} m")
st.metric("Width/Depth Ratio", f"{width/depth:.2f}")
except ValueError:
st.error("Please enter valid numeric values for all inputs.")
st.subheader("📊 Model Performance")
st.markdown("- **MAE:** 33 cm\n- **RMSE:** 102 cm\n- **R²:** 0.89\n- **MAPE:** 20%")
st.image("img/BASED_validation.png", caption="BASED Validation Results", use_column_width=True)
st.caption("Image source: Gearon, J.H. et al. Rules of river avulsion change downstream. Nature 634, 91–95 (2024). https://doi.org/10.1038/s41586-024-07964-2")
st.subheader("ℹ️ Model Information")
st.markdown("""
**Version:** 1.0.0
**Citation:**
```
Gearon, James H. (2024). Boost-Assisted Stream Estimator for Depth (BASED) [Computer software]. Version 1.0.0. https://github.com/JakeGearon/based-api
```
**Description:** BASED is an XGBoost regressor designed for predicting channel depth using channel width, slope, and discharge.
""")
st.markdown("---")
st.subheader("⚠️ Disclaimer")
st.markdown("""
BASED is provided for informational and research purposes only. Do not use these predictions as the sole basis for critical decisions.
Always consult qualified professionals and conduct proper field measurements. The creators are not responsible for consequences arising
from the use or misuse of this tool.
""")
if __name__ == "__main__":
main()