Skip to content

Commit

Permalink
Front end commit with flask
Browse files Browse the repository at this point in the history
  • Loading branch information
isaac-aryan committed May 31, 2021
1 parent a69764f commit ec2dc9e
Show file tree
Hide file tree
Showing 3 changed files with 224 additions and 0 deletions.
55 changes: 55 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from flask import Flask, render_template, request
import jsonify
import requests
import pickle
import numpy as np
import sklearn
from sklearn.preprocessing import StandardScaler
app = Flask(__name__)
model = pickle.load(open('xgbcl_model.pkl', 'rb'))
@app.route('/',methods=['GET'])
def Home():
return render_template('index.html')


@app.route("/predict", methods=['POST'])
def predict():
if request.method == 'POST':
ref_index = float(request.form['ref_index'])
sodium = float(request.form['sodium'])
magnesium = float(request.form['magnesium'])
alum = float(request.form['alum'])
silicon = float(request.form['silicon'])
potash = float(request.form['potash'])
barium = float(request.form['barium'])
calcium = float(request.form['calcium'])
iron = float(request.form['iron'])

params = np.array([[ref_index, sodium, magnesium, alum, silicon, potash, barium, calcium, iron]])
preds = model.predict(params)
output = preds
if output<0:
return render_template('index.html',prediction_texts="This type of glass does not exist.")
else:
if output==1:
return render_template('index.html',prediction_text="The Type of glass is Building Window (float processed)")
elif output==2:
return render_template('index.html',prediction_text="The Type of glass is Building Window (non float processed)")
elif output==3:
return render_template('index.html',prediction_text="The Type of glass is Vehicle Window (float processed)")
elif output==4:
return render_template('index.html',prediction_text="The Type of glass is Vehicle Window (non float processed)")
elif output==5:
return render_template('index.html',prediction_text="The Type of glass is Containers")
elif output==6:
return render_template('index.html',prediction_text="The Type of glass is Tableware")
elif output==7:
return render_template('index.html',prediction_text="The Type of glass is Headlamps")
else:
return render_template('index.html',prediction_text="Unable to classify the type of glass.")

else:
return render_template('index.html')

if __name__=="__main__":
app.run(debug=True)
7 changes: 7 additions & 0 deletions glassmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
#Ba: Barium
#Fe: Iron

# 1 buildingwindowsfloatprocessed
# 2 buildingwindowsnonfloatprocessed
# 3 vehiclewindowsfloatprocessed
# 4 vehiclewindowsnonfloatprocessed
# 5 containers
# 6 tableware
# 7 headlamps
print(df.Ba.unique())
print(df.shape)

Expand Down
162 changes: 162 additions & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>

<body>

<div style="color:rgb(133, 133, 226)">
<form action="{{ url_for('predict')}}" method="post">
<h2>Predictive analysis</h2>

<h3>Refractive Index</h3>
<input id="ref_index" name="ref_index" type="number ">

<h3>What is the amount of Sodium? (With decimal precision)</h3><br><input id="sodium" name="sodium" required="required">

<h3>What is the amount of Magnesium? (With decimal precision)</h3><br><input id="magnesium" name="magnesium" required="required">

<h3>What is the amount of Alluminium? (With decimal precision)</h3><br><input id="alum" name="alum" required="required">

<h3>What is the amount of Silicon? (With decimal precision)</h3><br><input id="silicon" name="silicon" required="required">

<h3>What is the amount of Potassium? (With decimal precision)</h3><br><input id="potash" name="potash" required="required">

<h3>What is the amount of Calcium? (With decimal precision)</h3><br><input id="calcium" name="calcium" required="required">

<h3>What is the amount of Barium? (With decimal precision)</h3><br><input id="barium" name="barium" required="required">

<h3>What is the amount of Iron? (With decimal precision)</h3><br><input id="iron" name="iron" required="required">


<br><br><button id="sub" type="submit ">Classify the glass!</button>
<br>




</form>



<br><br><h3>{{ prediction_text }}<h3>
</div>




<style>
body {
background-color: rgb(20, 20, 20);
text-align: center;
padding: 0px;
}

#research {
font-size: 18px;
width: 100px;
height: 23px;
top: 23px;
}

#box {
border-radius: 60px;
border-color: 45px;
border-style: solid;
font-family: cursive;
text-align: center;
background-color: rgb(168, 131, 61);
font-size: medium;
position: absolute;
width: 700px;
bottom: 9%;
height: 850px;
right: 30%;
padding: 0px;
margin: 0px;
font-size: 14px;
}

#fuel {
width: 83px;
height: 43px;
text-align: center;
border-radius: 14px;
font-size: 20px;
}

#fuel:hover {
background-color: coral;
}

#research {
width: 99px;
height: 43px;
text-align: center;
border-radius: 14px;
font-size: 18px;
}

#research:hover {
background-color: coral;
}

#resea {
width: 99px;
height: 43px;
text-align: center;
border-radius: 14px;
font-size: 18px;
}

#resea:hover {
background-color: coral;
}

#sub {
width: 120px;
height: 43px;
text-align: center;
border-radius: 14px;
font-size: 18px;
}

#sub:hover {
background-color: darkcyan;
}

#first {
border-radius: 14px;
height: 25px;
font-size: 20px;
text-align: center;
}

#second {
border-radius: 14px;
height: 25px;
font-size: 20px;
text-align: center;
}

#third {
border-radius: 14px;
height: 25px;
font-size: 20px;
text-align: center;
}

#fourth {
border-radius: 14px;
height: 25px;
font-size: 20px;
text-align: center;
}
</style>
</body>

</html>

0 comments on commit ec2dc9e

Please sign in to comment.