Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
|
| 2 |
|
| 3 |
import pandas as pd
|
| 4 |
import numpy as np
|
|
@@ -237,49 +237,52 @@ with gr.Blocks(title="Water Quality Analysis") as iface:
|
|
| 237 |
gr.Markdown("# 💧 Detailed Water Quality Prediction System")
|
| 238 |
gr.Markdown("Analyze water parameters using K-Means Clustering and an Artificial Neural Network.")
|
| 239 |
|
| 240 |
-
with gr.
|
| 241 |
-
with gr.
|
| 242 |
-
|
| 243 |
-
input_components = []
|
| 244 |
-
|
| 245 |
-
# Create a 4-column layout for the inputs
|
| 246 |
with gr.Row():
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 253 |
with gr.Row():
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
gr.
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
)
|
| 261 |
-
|
| 262 |
-
with gr.Column(scale=1):
|
| 263 |
-
gr.Markdown("### 2. Prediction Results")
|
| 264 |
-
out_cluster = gr.Textbox(label="Predicted Cluster Type")
|
| 265 |
-
out_safety = gr.Textbox(label="Water Safety Status")
|
| 266 |
-
|
| 267 |
-
predict_btn.click(
|
| 268 |
-
fn=predict_water_safety,
|
| 269 |
-
inputs=input_components,
|
| 270 |
-
outputs=[out_cluster, out_safety]
|
| 271 |
-
)
|
| 272 |
-
|
| 273 |
-
gr.Markdown("---")
|
| 274 |
-
gr.Markdown("### Algorithm Insights")
|
| 275 |
-
with gr.Row():
|
| 276 |
-
plot1 = gr.Plot(label="Elbow Method")
|
| 277 |
-
plot2 = gr.Plot(label="PCA Cluster Visualization")
|
| 278 |
-
with gr.Row():
|
| 279 |
-
plot3 = gr.Plot(label="ANN Loss Curve")
|
| 280 |
-
plot4 = gr.Plot(label="ANN Confusion Matrix")
|
| 281 |
-
|
| 282 |
-
iface.load(fn=get_algo_plots, inputs=None, outputs=[plot1, plot2, plot3, plot4])
|
| 283 |
-
|
| 284 |
# Launch the interface
|
| 285 |
-
iface.launch()
|
|
|
|
| 1 |
+
from tab_extra import add_extra_tabs
|
| 2 |
|
| 3 |
import pandas as pd
|
| 4 |
import numpy as np
|
|
|
|
| 237 |
gr.Markdown("# 💧 Detailed Water Quality Prediction System")
|
| 238 |
gr.Markdown("Analyze water parameters using K-Means Clustering and an Artificial Neural Network.")
|
| 239 |
|
| 240 |
+
with gr.Tabs():
|
| 241 |
+
with gr.TabItem("🔍 Predict"):
|
| 242 |
+
|
|
|
|
|
|
|
|
|
|
| 243 |
with gr.Row():
|
| 244 |
+
with gr.Column(scale=2):
|
| 245 |
+
gr.Markdown("### 1. Enter Water Parameters")
|
| 246 |
+
input_components = []
|
| 247 |
+
|
| 248 |
+
# Create a 4-column layout for the inputs
|
| 249 |
+
with gr.Row():
|
| 250 |
+
cols = [gr.Column() for _ in range(4)]
|
| 251 |
+
for i, col in enumerate(feature_columns):
|
| 252 |
+
with cols[i % 4]:
|
| 253 |
+
inp = gr.Slider(minimum=float(X[col].min()), maximum=float(X[col].max()), label=col)
|
| 254 |
+
input_components.append(inp)
|
| 255 |
+
|
| 256 |
+
with gr.Row():
|
| 257 |
+
predict_btn = gr.Button("Predict Safety Status", variant="primary")
|
| 258 |
+
|
| 259 |
+
gr.Examples(
|
| 260 |
+
examples=examples_data,
|
| 261 |
+
inputs=input_components,
|
| 262 |
+
label="Quick Presets"
|
| 263 |
+
)
|
| 264 |
+
|
| 265 |
+
with gr.Column(scale=1):
|
| 266 |
+
gr.Markdown("### 2. Prediction Results")
|
| 267 |
+
out_cluster = gr.Textbox(label="Predicted Cluster Type")
|
| 268 |
+
out_safety = gr.Textbox(label="Water Safety Status")
|
| 269 |
+
|
| 270 |
+
predict_btn.click(
|
| 271 |
+
fn=predict_water_safety,
|
| 272 |
+
inputs=input_components,
|
| 273 |
+
outputs=[out_cluster, out_safety]
|
| 274 |
+
)
|
| 275 |
+
|
| 276 |
+
gr.Markdown("---")
|
| 277 |
+
gr.Markdown("### Algorithm Insights")
|
| 278 |
with gr.Row():
|
| 279 |
+
plot1 = gr.Plot(label="Elbow Method")
|
| 280 |
+
plot2 = gr.Plot(label="PCA Cluster Visualization")
|
| 281 |
+
with gr.Row():
|
| 282 |
+
plot3 = gr.Plot(label="ANN Loss Curve")
|
| 283 |
+
plot4 = gr.Plot(label="ANN Confusion Matrix")
|
| 284 |
+
|
| 285 |
+
iface.load(fn=get_algo_plots, inputs=None, outputs=[plot1, plot2, plot3, plot4])
|
| 286 |
+
add_extra_tabs()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 287 |
# Launch the interface
|
| 288 |
+
iface.launch(debug=True, share=True)
|