Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
SayamAlt committed Jun 5, 2022
0 parents commit fab8fed
Show file tree
Hide file tree
Showing 15 changed files with 39,429 additions and 0 deletions.
175 changes: 175 additions & 0 deletions .ipynb_checkpoints/Model Deployment-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "a039038d",
"metadata": {},
"outputs": [],
"source": [
"from flask import Flask, render_template, request\n",
"import joblib\n",
"from datetime import date"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "72ca2b80",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"ExtraTreesClassifier()"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"model = joblib.load('model.pkl')\n",
"model"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "d8644c65",
"metadata": {},
"outputs": [],
"source": [
"app = Flask(__name__)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "199c0604",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2022"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"year = date.today().year\n",
"year"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "1b57ef0e",
"metadata": {},
"outputs": [],
"source": [
"@app.route(\"/\")\n",
"def home():\n",
" return render_template('home.html',current_year=year)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "ed816e8b",
"metadata": {},
"outputs": [],
"source": [
"@app.route(\"/predict\", methods=[\"GET\",\"POST\"])\n",
"def predict():\n",
" if request.method == \"POST\":\n",
" ph = request.form['ph'] #Range: (0.00,14.00)\n",
" hardness = request.form['hardness'] #Range: (117.12,276.39)\n",
" solids = request.form['solids'] #Range: (320.94,44831.86)\n",
" chloramines = request.form['chloramines'] #Range: (3.14,11.09)\n",
" sulfate = request.form['sulfate'] #Range: (267.15,400.32)\n",
" conductivity = request.form['conductivity'] #Range: (191.64,655.87)\n",
" organic_carbon = request.form['organic_carbon'] #Range: (5.32,23.29)\n",
" trihalomethanes = request.form['trihalomethanes'] #Range: (26.61,106.69)\n",
" turbidity = request.form['turbidity'] #Range: (1.84,6.09)\n",
" \n",
" predictions = model.predict([[\n",
" ph,\n",
" hardness,\n",
" solids,\n",
" chloramines,\n",
" sulfate,\n",
" conductivity,\n",
" organic_carbon,\n",
" trihalomethanes,\n",
" turbidity\n",
" ]])\n",
" \n",
" output = int(predictions[0])\n",
" \n",
" if output == 1:\n",
" return render_template('home.html',current_year=year,prediction_text=\"The water with given details is pure and potable enough to drink and meets the federal standards for domestic consumption.\")\n",
" else:\n",
" return render_template('home.html',current_year=year,prediction_text=\"The water with specified details is impure, contaminated and non-potable. It may not be suitable for domestic consumption.\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bb97512c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" * Serving Flask app '__main__' (lazy loading)\n",
" * Environment: production\n",
"\u001b[31m WARNING: This is a development server. Do not use it in a production deployment.\u001b[0m\n",
"\u001b[2m Use a production WSGI server instead.\u001b[0m\n",
" * Debug mode: off\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" * Running on http://127.0.0.1:8080/ (Press CTRL+C to quit)\n",
"127.0.0.1 - - [05/Jun/2022 22:54:35] \"GET / HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [05/Jun/2022 22:54:51] \"POST /predict HTTP/1.1\" 200 -\n"
]
}
],
"source": [
"if __name__ == \"__main__\":\n",
" app.run(port=8080)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading

0 comments on commit fab8fed

Please sign in to comment.