Spaces:
Sleeping
Sleeping
nn
commited on
Upload app.py
Browse files
app.py
CHANGED
|
@@ -36,12 +36,30 @@ def process_excel(file):
|
|
| 36 |
soil_data = np.stack([x_train, bh2, data_pile], axis=2)
|
| 37 |
return soil_data
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
def predict_pile(file_choice, uploaded_file, pile_length, section_width, section_length, pile_type):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
if file_choice == "default":
|
| 41 |
file = "default"
|
| 42 |
else:
|
| 43 |
if uploaded_file is None:
|
| 44 |
-
return "Please upload an Excel file or choose the default option."
|
| 45 |
file = uploaded_file
|
| 46 |
|
| 47 |
X = process_excel(file)
|
|
@@ -83,13 +101,13 @@ def predict_pile(file_choice, uploaded_file, pile_length, section_width, section
|
|
| 83 |
plt.xlabel("Deformation (mm)")
|
| 84 |
plt.ylabel("Load (kN)")
|
| 85 |
plt.title(f"Pile Prediction (Length: {pile_length}m, {pile_type})")
|
| 86 |
-
return plt
|
| 87 |
|
| 88 |
def update_file_input(choice):
|
| 89 |
return gr.update(visible=choice == "upload")
|
| 90 |
|
| 91 |
with gr.Blocks() as iface:
|
| 92 |
-
gr.Markdown("# Pile Prediction Model")
|
| 93 |
gr.Markdown("Choose the default Excel file or upload your own, then enter pile characteristics to predict pile behavior.")
|
| 94 |
|
| 95 |
with gr.Row():
|
|
@@ -103,6 +121,7 @@ with gr.Blocks() as iface:
|
|
| 103 |
pile_type = gr.Radio(["Circular", "Barrette"], label="Pile Type", value="Circular")
|
| 104 |
|
| 105 |
output = gr.Plot()
|
|
|
|
| 106 |
|
| 107 |
submit_btn = gr.Button("Predict")
|
| 108 |
|
|
@@ -118,7 +137,7 @@ with gr.Blocks() as iface:
|
|
| 118 |
submit_btn.click(
|
| 119 |
fn=predict_pile,
|
| 120 |
inputs=[file_choice, uploaded_file, pile_length, section_width, section_length, pile_type],
|
| 121 |
-
outputs=[output]
|
| 122 |
)
|
| 123 |
|
| 124 |
iface.launch()
|
|
|
|
| 36 |
soil_data = np.stack([x_train, bh2, data_pile], axis=2)
|
| 37 |
return soil_data
|
| 38 |
|
| 39 |
+
def validate_inputs(pile_length, section_width, section_length, pile_type):
|
| 40 |
+
if pile_length < 39 or pile_length > 60:
|
| 41 |
+
return False, "Pile length must be between 39 and 60 meters."
|
| 42 |
+
|
| 43 |
+
if pile_type == "Circular":
|
| 44 |
+
if section_width < 0.8 or section_width > 1.8 or section_length < 0.8 or section_length > 1.8:
|
| 45 |
+
return False, "For circular piles, section width and length must be between 0.8 and 1.8 meters."
|
| 46 |
+
elif pile_type == "Barrette":
|
| 47 |
+
if section_width < 1 or section_width > 4 or section_length < 1 or section_length > 4:
|
| 48 |
+
return False, "For barrette piles, section width and length must be between 1 and 4 meters."
|
| 49 |
+
|
| 50 |
+
return True, ""
|
| 51 |
+
|
| 52 |
def predict_pile(file_choice, uploaded_file, pile_length, section_width, section_length, pile_type):
|
| 53 |
+
# Validate inputs
|
| 54 |
+
is_valid, error_message = validate_inputs(pile_length, section_width, section_length, pile_type)
|
| 55 |
+
if not is_valid:
|
| 56 |
+
return None, error_message
|
| 57 |
+
|
| 58 |
if file_choice == "default":
|
| 59 |
file = "default"
|
| 60 |
else:
|
| 61 |
if uploaded_file is None:
|
| 62 |
+
return None, "Please upload an Excel file or choose the default option."
|
| 63 |
file = uploaded_file
|
| 64 |
|
| 65 |
X = process_excel(file)
|
|
|
|
| 101 |
plt.xlabel("Deformation (mm)")
|
| 102 |
plt.ylabel("Load (kN)")
|
| 103 |
plt.title(f"Pile Prediction (Length: {pile_length}m, {pile_type})")
|
| 104 |
+
return plt, ""
|
| 105 |
|
| 106 |
def update_file_input(choice):
|
| 107 |
return gr.update(visible=choice == "upload")
|
| 108 |
|
| 109 |
with gr.Blocks() as iface:
|
| 110 |
+
gr.Markdown("# Pile Prediction Model in Bangkok Subsoil")
|
| 111 |
gr.Markdown("Choose the default Excel file or upload your own, then enter pile characteristics to predict pile behavior.")
|
| 112 |
|
| 113 |
with gr.Row():
|
|
|
|
| 121 |
pile_type = gr.Radio(["Circular", "Barrette"], label="Pile Type", value="Circular")
|
| 122 |
|
| 123 |
output = gr.Plot()
|
| 124 |
+
error_output = gr.Textbox(label="Error", visible=True)
|
| 125 |
|
| 126 |
submit_btn = gr.Button("Predict")
|
| 127 |
|
|
|
|
| 137 |
submit_btn.click(
|
| 138 |
fn=predict_pile,
|
| 139 |
inputs=[file_choice, uploaded_file, pile_length, section_width, section_length, pile_type],
|
| 140 |
+
outputs=[output, error_output]
|
| 141 |
)
|
| 142 |
|
| 143 |
iface.launch()
|