Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- app.py +30 -0
- model.joblib +3 -0
- templates/index.html +23 -0
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, render_template, request
|
| 2 |
+
import joblib
|
| 3 |
+
|
| 4 |
+
app = Flask(__name__) # Inilitize the flask app
|
| 5 |
+
|
| 6 |
+
# Load model once at startup
|
| 7 |
+
model = joblib.load('model.joblib')
|
| 8 |
+
|
| 9 |
+
@app.route('/') # home route
|
| 10 |
+
def home():
|
| 11 |
+
return render_template('index.html')
|
| 12 |
+
|
| 13 |
+
@app.route('/predict', methods=['POST'])
|
| 14 |
+
def predict():
|
| 15 |
+
try:
|
| 16 |
+
# Get input values from HTML form
|
| 17 |
+
sepal_length = float(request.form.get("sepal_length"))
|
| 18 |
+
sepal_width = float(request.form.get("sepal_width"))
|
| 19 |
+
petal_length = float(request.form.get("petal_length"))
|
| 20 |
+
petal_width = float(request.form.get("petal_width"))
|
| 21 |
+
except Exception:
|
| 22 |
+
return "Invalid input. Make sure all fields are numeric."
|
| 23 |
+
|
| 24 |
+
# Predict using the model
|
| 25 |
+
pred = model.predict([[sepal_length, sepal_width, petal_length, petal_width]])[0]
|
| 26 |
+
|
| 27 |
+
return render_template('index.html', pred=pred)
|
| 28 |
+
|
| 29 |
+
if __name__ == "__main__":
|
| 30 |
+
app.run(debug=True)
|
model.joblib
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6a8742a871d330edc37a89febd6450e2157d0a20b47f0e4a3f51dc5b77a1eaa4
|
| 3 |
+
size 1407
|
templates/index.html
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<html>
|
| 2 |
+
<head>
|
| 3 |
+
<title>My Web Page</title>
|
| 4 |
+
</head>
|
| 5 |
+
<body>
|
| 6 |
+
<h1> Welcome to the inris flower prediction project</h1> <br>
|
| 7 |
+
<form action="/predict" method="post">
|
| 8 |
+
<label for="sepal_length">Sepal Length:</label>
|
| 9 |
+
<input type="number" name="sepal_length" step="0.1"><br><br>
|
| 10 |
+
<label for="sepal_width">Sepal Width:</label>
|
| 11 |
+
<input type="number" name="sepal_width" step="0.1"><br><br>
|
| 12 |
+
<label for="petal_length">Petal Length:</label>
|
| 13 |
+
<input type="number" name="petal_length" step="0.1"><br><br>
|
| 14 |
+
<label for="petal_width">Petal Width:</label>
|
| 15 |
+
<input type="number" name="petal_width" step="0.1"><br><br>
|
| 16 |
+
<input type="submit" value="Predict">
|
| 17 |
+
</form>
|
| 18 |
+
{% if pred %}
|
| 19 |
+
<h2>Prediction: {{ pred }}</h2>
|
| 20 |
+
{% endif %}
|
| 21 |
+
|
| 22 |
+
</body>
|
| 23 |
+
</html>
|