Muntasir006 commited on
Commit
2c45440
·
verified ·
1 Parent(s): 5f9e2d4

Upload 3 files

Browse files
Files changed (3) hide show
  1. XGBoost_best_of_10.joblib +3 -0
  2. app.py +141 -0
  3. requirements.txt +4 -0
XGBoost_best_of_10.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:86ec2890140b347fb2c78e4d47c1013897553efd52638abc0ff687ad9b3920c4
3
+ size 126041
app.py ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import joblib
3
+ import gradio as gr
4
+ import matplotlib.pyplot as plt
5
+
6
+ # Load the pre-trained model
7
+ model = joblib.load("XGBoost_best_of_10.joblib")
8
+
9
+ def predict_hc(mt_content, liquid_limit, plastic_limit, specific_gravity,
10
+ initial_wc, temperature, dry_density_values):
11
+ warnings = []
12
+ predictions = []
13
+ single_pred = None
14
+
15
+ # Process dry density values
16
+ try:
17
+ density_values = [float(x.strip()) for x in dry_density_values.split(',')]
18
+ if len(density_values) < 4 or len(density_values) > 8:
19
+ raise ValueError("Please enter 4 to 8 values separated by commas")
20
+ except ValueError as e:
21
+ return f"Error in dry density input: {str(e)}", None, None, None
22
+
23
+ # Fixed features (same for all predictions)
24
+ fixed_features = np.array([
25
+ mt_content,
26
+ liquid_limit,
27
+ plastic_limit,
28
+ specific_gravity,
29
+ initial_wc,
30
+ temperature
31
+ ])
32
+
33
+ # Define trained ranges for soil properties
34
+ trained_ranges = {
35
+ "Montmorillonite Content": (33.60, 92.00),
36
+ "Liquid Limit": (50.00, 500.00),
37
+ "Plastic Limit": (20.00, 200.00),
38
+ "Specific Gravity": (2.65, 2.82),
39
+ "Initial Water Content": (5.40, 21.10),
40
+ "Temperature": (20.00, 40.00),
41
+ "Dry Density": (1.30, 2.05),
42
+ }
43
+
44
+ # Check input values against trained ranges
45
+ input_values = {
46
+ "Montmorillonite Content": mt_content,
47
+ "Liquid Limit": liquid_limit,
48
+ "Plastic Limit": plastic_limit,
49
+ "Specific Gravity": specific_gravity,
50
+ "Initial Water Content": initial_wc,
51
+ "Temperature": temperature,
52
+ }
53
+
54
+ for feature, value in input_values.items():
55
+ min_val, max_val = trained_ranges[feature]
56
+ if value < min_val:
57
+ warnings.append(f"⚠️ {feature} is below the trained range ({min_val}-{max_val}).")
58
+ elif value > max_val:
59
+ warnings.append(f"⚠️ {feature} is above the trained range ({min_val}-{max_val}).")
60
+
61
+ # Make predictions for all density values
62
+ for density in density_values:
63
+ # Check dry density range
64
+ min_density, max_density = trained_ranges["Dry Density"]
65
+ if density < min_density:
66
+ warnings.append(f"⚠️ Dry Density {density} is below the trained range ({min_density}-{max_density}).")
67
+ elif density > max_density:
68
+ warnings.append(f"⚠️ Dry Density {density} is above the trained range ({min_density}-{max_density}).")
69
+
70
+ # Create input array
71
+ input_array = np.append(fixed_features, density).reshape(1, -1)
72
+ pred = model.predict(input_array)[0]
73
+ predictions.append(pred)
74
+
75
+ # If only one density value provided, show single prediction
76
+ if len(density_values) == 1:
77
+ single_pred = predictions[0]
78
+
79
+ # Create plot if multiple density values
80
+ plot_path_png = None
81
+ if len(density_values) > 1:
82
+ fig, ax = plt.subplots(figsize=(5, 4))
83
+ ax.plot(density_values, predictions, marker="o", linestyle="-", color="blue", markersize=8)
84
+ ax.set_xlabel("Dry Density [g/cm³]")
85
+ ax.set_ylabel("Saturated Hydraulic Conductivity (HC) [-]")
86
+ ax.grid(True, linestyle="--", alpha=0.5)
87
+
88
+ plot_path_png = "HC_plot.png"
89
+ fig.savefig(plot_path_png, dpi=600, bbox_inches="tight")
90
+ plt.close(fig)
91
+
92
+ # Format output
93
+ pred_text = ""
94
+ if single_pred is not None:
95
+ pred_text += f"Predicted Saturated HC: {single_pred:.4f} [-]\n\n"
96
+ else:
97
+ pred_text += "Predicted Saturated HC values:\n"
98
+ for d, p in zip(density_values, predictions):
99
+ pred_text += f"• At ρ = {d:.2f} g/cm³: HC = {p:.4f} [-]\n"
100
+ pred_text += "\n"
101
+
102
+ if warnings:
103
+ pred_text += "\n".join(warnings)
104
+
105
+ # Team text
106
+ marketing_text = (
107
+ "**Developed by:** \nMuntasir Shehab*, Reza Taherdangkoo and Christoph Butscher \n\n"
108
+ "**Institution:** \nTU Bergakademie Freiberg, Institute of Geotechnics \n"
109
+ "Gustav-Zeuner-Str. 1, Freiberg, 09599, Germany"
110
+ )
111
+
112
+ return pred_text, plot_path_png, marketing_text
113
+
114
+ # Input components
115
+ inputs = [
116
+ gr.Number(label="Montmorillonite Content [%]", value=60, minimum=5.60, maximum=96.00, step=0.1),
117
+ gr.Number(label="Liquid Limit [%]", value=150, minimum=50.00, maximum=500.00, step=1),
118
+ gr.Number(label="Plastic Limit [%]", value=50, minimum=20.00, maximum=200.00, step=1),
119
+ gr.Number(label="Specific Gravity", value=2.7, minimum=2.15, maximum=2.92, step=0.01),
120
+ gr.Number(label="Initial Water Content [%]", value=10, minimum=5.40, maximum=21.10, step=0.1),
121
+ gr.Number(label="Temperature [°C]", value=25, minimum=20.00, maximum=40.00, step=0.1),
122
+ gr.Textbox(label="Dry Density values [g/cm³] (4-8 values, comma separated)",
123
+ value="1.3, 1.5, 1.7, 1.9",
124
+ placeholder="Enter 4-8 values separated by commas (e.g., 1.3, 1.5, 1.7, 1.9)"),
125
+ ]
126
+
127
+ # Output components
128
+ outputs = [
129
+ gr.Textbox(label="Prediction Results & Warnings"),
130
+ gr.Image(label="HC vs Dry Density Plot", type="filepath"),
131
+ gr.Markdown(label="About the Team")
132
+ ]
133
+
134
+ # Launch interface
135
+ gr.Interface(
136
+ fn=predict_hc,
137
+ inputs=inputs,
138
+ outputs=outputs,
139
+ title="Saturated Hydraulic Conductivity Prediction Model",
140
+ description="Predict saturated hydraulic conductivity (HC) based on soil properties. Enter 4-8 dry density values to see the trend."
141
+ ).launch(share=True)
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio
2
+ joblib
3
+ numpy
4
+ xgboost