Skip to content
Browse files
Add files via upload
Final upload
  • Loading branch information
gebremedik committed Apr 18, 2023
1 parent b3de95b commit 60eb17d466755903b2def8a7ab67665571ff94e0
Show file tree
Hide file tree
Showing 6 changed files with 4,501 additions and 0 deletions.
@@ -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.

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():
return pickle.load(open("model.pkl", "rb"))
return None

model = load_model()

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__":

0 comments on commit 60eb17d

Please sign in to comment.