Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add files via upload
Final upload
- Loading branch information
1 parent
b3de95b
commit 60eb17d
Showing
6 changed files
with
4,501 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
''' | ||
This is a Flask web application that reads a pickle file to load a machine learning model, | ||
accepts user input from a web form, and returns a prediction using the model. | ||
''' | ||
|
||
# https://flask.palletsprojects.com/en/2.2.x/quickstart/ | ||
from flask import Flask, render_template, request | ||
import pickle | ||
import numpy as np | ||
|
||
# create flask app | ||
app = Flask(__name__) | ||
|
||
# Load the pickle model file | ||
def load_model(): | ||
try: | ||
return pickle.load(open("model.pkl", "rb")) | ||
except: | ||
return None | ||
|
||
model = load_model() | ||
|
||
@app.route('/') | ||
def home(): | ||
return render_template('index.html') | ||
|
||
@app.route('/predict', methods=['POST']) | ||
def predict(): | ||
if model is None: | ||
error_message = "Sorry, an error occurred while loading the model. Please try again later." | ||
return render_template('index.html', result=error_message) | ||
|
||
# Get the features from the request form and make a prediction | ||
features = [float(x) for x in request.form.values()] | ||
final_features = [np.array(features)] | ||
prediction = model.predict(final_features) | ||
result = round(prediction[0], 1) | ||
|
||
# Create a result string to show to the user | ||
result_string = f"The predicted diabetes outcome is {result}." | ||
return render_template('index.html', result=result_string) | ||
|
||
if __name__ == "__main__": | ||
app.run(debug=True) |
Oops, something went wrong.