Abid Ali Awan
commited on
Commit
β’
ee1e3c6
1
Parent(s):
e2549aa
pushing all the files
Browse files- .gitattributes +1 -0
- Dockerfile +16 -0
- README.md +4 -3
- app/main.py +55 -0
- app/templates/form.html +16 -0
- app/templates/result.html +11 -0
- models/metadata.json +25 -0
- models/scaler.joblib +3 -0
- models/water_quality_model.skops +3 -0
- requirements.txt +13 -0
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
*.skops filter=lfs diff=lfs merge=lfs -text
|
Dockerfile
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
|
2 |
+
# you will also find guides on how best to write your Dockerfile
|
3 |
+
|
4 |
+
FROM python:3.9
|
5 |
+
|
6 |
+
RUN useradd -m -u 1000 user
|
7 |
+
USER user
|
8 |
+
ENV PATH="/home/user/.local/bin:$PATH"
|
9 |
+
|
10 |
+
WORKDIR /app
|
11 |
+
|
12 |
+
COPY --chown=user ./requirements.txt requirements.txt
|
13 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
14 |
+
|
15 |
+
COPY --chown=user . /app
|
16 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
README.md
CHANGED
@@ -1,3 +1,6 @@
|
|
|
|
|
|
|
|
1 |
---
|
2 |
title: Water Quality Classifier
|
3 |
emoji: π
|
@@ -6,6 +9,4 @@ colorTo: blue
|
|
6 |
sdk: docker
|
7 |
pinned: false
|
8 |
license: apache-2.0
|
9 |
-
---
|
10 |
-
|
11 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
+
# Water-Quality-App
|
2 |
+
Building an Water Quality Classifier Application with o1-preview Model
|
3 |
+
|
4 |
---
|
5 |
title: Water Quality Classifier
|
6 |
emoji: π
|
|
|
9 |
sdk: docker
|
10 |
pinned: false
|
11 |
license: apache-2.0
|
12 |
+
---
|
|
|
|
app/main.py
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI, Request, Form
|
2 |
+
from fastapi.responses import HTMLResponse
|
3 |
+
from fastapi.templating import Jinja2Templates
|
4 |
+
import numpy as np
|
5 |
+
import skops.io as sio
|
6 |
+
import joblib
|
7 |
+
|
8 |
+
app = FastAPI()
|
9 |
+
templates = Jinja2Templates(directory="app/templates")
|
10 |
+
|
11 |
+
# Load the saved model and preprocessing pipeline
|
12 |
+
model = sio.load("models/water_quality_model.skops")
|
13 |
+
preprocessing_pipeline = joblib.load("models/scaler.joblib")
|
14 |
+
|
15 |
+
|
16 |
+
@app.get("/", response_class=HTMLResponse)
|
17 |
+
async def home(request: Request):
|
18 |
+
return templates.TemplateResponse("form.html", {"request": request})
|
19 |
+
|
20 |
+
|
21 |
+
@app.post("/predict", response_class=HTMLResponse)
|
22 |
+
async def predict(
|
23 |
+
request: Request,
|
24 |
+
ph: float = Form(...),
|
25 |
+
Hardness: float = Form(...),
|
26 |
+
Solids: float = Form(...),
|
27 |
+
Chloramines: float = Form(...),
|
28 |
+
Sulfate: float = Form(...),
|
29 |
+
Conductivity: float = Form(...),
|
30 |
+
Organic_carbon: float = Form(...),
|
31 |
+
Trihalomethanes: float = Form(...),
|
32 |
+
Turbidity: float = Form(...),
|
33 |
+
):
|
34 |
+
input_data = np.array(
|
35 |
+
[
|
36 |
+
[
|
37 |
+
ph,
|
38 |
+
Hardness,
|
39 |
+
Solids,
|
40 |
+
Chloramines,
|
41 |
+
Sulfate,
|
42 |
+
Conductivity,
|
43 |
+
Organic_carbon,
|
44 |
+
Trihalomethanes,
|
45 |
+
Turbidity,
|
46 |
+
]
|
47 |
+
]
|
48 |
+
)
|
49 |
+
# Preprocess input data
|
50 |
+
input_preprocessed = preprocessing_pipeline.transform(input_data)
|
51 |
+
prediction = model.predict(input_preprocessed)
|
52 |
+
result = "Potable" if prediction[0] == 1 else "Not Potable"
|
53 |
+
return templates.TemplateResponse(
|
54 |
+
"result.html", {"request": request, "result": result}
|
55 |
+
)
|
app/templates/form.html
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html>
|
3 |
+
<head>
|
4 |
+
<title>Water Quality Prediction</title>
|
5 |
+
</head>
|
6 |
+
<body>
|
7 |
+
<h2>Enter Water Parameters</h2>
|
8 |
+
<form action="/predict" method="post">
|
9 |
+
{% for feature in ['ph', 'Hardness', 'Solids', 'Chloramines', 'Sulfate', 'Conductivity', 'Organic_carbon', 'Trihalomethanes', 'Turbidity'] %}
|
10 |
+
<label for="{{ feature }}">{{ feature.replace('_', ' ').title() }}:</label><br>
|
11 |
+
<input type="number" step="any" id="{{ feature }}" name="{{ feature }}" required><br><br>
|
12 |
+
{% endfor %}
|
13 |
+
<input type="submit" value="Predict">
|
14 |
+
</form>
|
15 |
+
</body>
|
16 |
+
</html>
|
app/templates/result.html
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html>
|
3 |
+
<head>
|
4 |
+
<title>Prediction Result</title>
|
5 |
+
</head>
|
6 |
+
<body>
|
7 |
+
<h2>Prediction Result</h2>
|
8 |
+
<p>The water is predicted to be: <strong>{{ result }}</strong></p>
|
9 |
+
<a href="/">Try Again</a>
|
10 |
+
</body>
|
11 |
+
</html>
|
models/metadata.json
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"model_name": "RandomForestClassifier",
|
3 |
+
"parameters": {
|
4 |
+
"bootstrap": true,
|
5 |
+
"ccp_alpha": 0.0,
|
6 |
+
"class_weight": null,
|
7 |
+
"criterion": "gini",
|
8 |
+
"max_depth": null,
|
9 |
+
"max_features": "sqrt",
|
10 |
+
"max_leaf_nodes": null,
|
11 |
+
"max_samples": null,
|
12 |
+
"min_impurity_decrease": 0.0,
|
13 |
+
"min_samples_leaf": 1,
|
14 |
+
"min_samples_split": 2,
|
15 |
+
"min_weight_fraction_leaf": 0.0,
|
16 |
+
"monotonic_cst": null,
|
17 |
+
"n_estimators": 200,
|
18 |
+
"n_jobs": null,
|
19 |
+
"oob_score": false,
|
20 |
+
"random_state": 42,
|
21 |
+
"verbose": 0,
|
22 |
+
"warm_start": false
|
23 |
+
},
|
24 |
+
"training_score": 1.0
|
25 |
+
}
|
models/scaler.joblib
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3ceea3b3744f3a76b652ba6d36adde6a30173325b37d1b1378b8088829e21a04
|
3 |
+
size 1263
|
models/water_quality_model.skops
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:5eb05df695568c29f9b9adc597ef617e3bda2c27ce3dfbcc36d27b14ad2475cb
|
3 |
+
size 17861908
|
requirements.txt
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
fastapi
|
2 |
+
uvicorn
|
3 |
+
jinja2
|
4 |
+
pydantic
|
5 |
+
skops
|
6 |
+
joblib
|
7 |
+
numpy
|
8 |
+
pandas
|
9 |
+
scikit-learn
|
10 |
+
matplotlib
|
11 |
+
seaborn
|
12 |
+
kaggle
|
13 |
+
imbalanced-learn
|