Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
2,890 changes: 1,363 additions & 1,527 deletions .ipynb_checkpoints/code-checkpoint.ipynb

Large diffs are not rendered by default.

132 changes: 132 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# app.py
import os
import pickle
import joblib
import numpy as np

from flask import Flask, render_template, request

app = Flask(__name__)

@app.route("/")
def enter():
return render_template("enter.html")

@app.route("/welcome")
def welcome():
return render_template("welcome.html")

@app.route("/form", methods=['GET', 'POST'])
def form():
if request.method == 'POST':
try:
# Extract form data
gender = int(request.form['gender'])
# Extract other form fields...

# Validate and process form data as needed

# Replace the following line with your logic to determine stroke or no stroke
result_data = "Your result data goes here"

return render_template('result.html', result_data=result_data)

except KeyError as e:
error_message = f"KeyError: {str(e)} is missing in form data."
return render_template('error.html', error_message=error_message)
except ValueError as ve:
error_message = f"ValueError: {str(ve)}"
return render_template('error.html', error_message=error_message)

# If it's a GET request, render the form template
return render_template('form.html')

@app.route('/result', methods=['POST'])

def result():

try:
gender = int(request.form['gender'])
age = int(request.form['age'])
hypertension = int(request.form['hypertension'])
heart_disease = int(request.form['heart_disease'])
ever_married = int(request.form['ever_married'])
work_type = int(request.form['work_type'])
residence_type = int(request.form['Residence_type'])
avg_glucose_level = float(request.form['avg_glucose_level'])
bmi = float(request.form['bmi'])
smoking_status = int(request.form['smoking_status'])

# Validate input values (add more validation if needed)
if age < 0 or avg_glucose_level < 0 or bmi < 0:
raise ValueError("Invalid input values")

x = np.array([gender, age, hypertension, heart_disease, ever_married, work_type, residence_type,
avg_glucose_level, bmi, smoking_status]).reshape(1, -1)

# Load scaler
scaler_path_mac = '/Users/arnav/Documents/CS 699 Project/CS699-SW-Lab/models/scaler.pkl'
scaler = None
try:
with open(scaler_path_mac, 'rb') as scaler_file:
scaler = pickle.load(scaler_file)
except Exception as e:
return render_template('error.html', error_message=f"Error loading scaler: {str(e)}")

# Transform input features using the loaded scaler
x = scaler.transform(x)

# Load the model
model_path = os.path.join('/Users/arnav/Documents/CS 699 Project/CS699-SW-Lab/models/random_forest_model.pkl')
dt = None
try:
dt = joblib.load(model_path)
except Exception as e:
return render_template('error.html', error_message=f"Error loading model: {str(e)}")

# Make predictions
y_pred = int(round(dt.predict(x)[0]))

# Render templates based on predictions
if y_pred == 0:
return render_template('nostroke.html')
else:
return render_template('stroke.html')

except KeyError as e:
# Handle missing keys in form data
error_message = f"KeyError: {str(e)} is missing in form data."
return render_template('error.html', error_message=error_message)
except ValueError as ve:
# Handle invalid input values
error_message = f"ValueError: {str(ve)}"
return render_template('error.html', error_message=error_message)

@app.route('/about')
def about():
return render_template('about.html')

@app.route('/legal')
def legal():
return render_template('dis.html')

@app.route('/privacy_policy')
def privacy_policy():
return render_template('privacy_policy.html')

@app.route('/terms_of_use')
def terms_of_use():
return render_template('termsofuse.html')

@app.route('/sales_policy')
def sales_policy():
return render_template('salespolicy.html')



@app.route('/buzzbeat')
def buzzbeat():
return render_template('buzzbeat.html')

if __name__ == "__main__":
app.run(debug=True, port=7384)
4,411 changes: 1,862 additions & 2,549 deletions code.ipynb

Large diffs are not rendered by default.

Binary file added models/.DS_Store
Binary file not shown.
Binary file removed models/dt.sav
Binary file not shown.
Binary file added models/random_forest_model.pkl
Binary file not shown.
Binary file modified models/scaler.pkl
Binary file not shown.