Skip to content

Commit

Permalink
Update app.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Md-Emon-Hasan authored Sep 3, 2024
1 parent db056eb commit aafdbde
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
from flask import Flask
from flask import request
from flask import render_template
import os
from flask import Flask, request, render_template
import numpy as np
import pandas as pd

from sklearn.preprocessing import StandardScaler
from src.pipeline.predict_pipeline import CustomData
from src.pipeline.predict_pipeline import PredictPipeline
from src.pipeline.predict_pipeline import CustomData, PredictPipeline

application = Flask(__name__)
app = application

@app.route('/predictdata', methods=['GET', 'POST'])
def predict_datapoint():
if request.method == 'POST':
# Extract form data
gender = request.form.get('gender')
race_ethnicity = request.form.get('ethnicity')
parental_level_of_education = request.form.get('parental_level_of_education')
Expand All @@ -23,7 +19,6 @@ def predict_datapoint():
reading_score = float(request.form.get('reading_score'))
writing_score = float(request.form.get('writing_score'))

# Prepare data for prediction
data = CustomData(
gender=gender,
race_ethnicity=race_ethnicity,
Expand All @@ -36,12 +31,10 @@ def predict_datapoint():
pred_df = data.get_data_as_data_frame()
print(pred_df)

print("Before Prediction")
predict_pipeline = PredictPipeline()
results = f"{predict_pipeline.predict(pred_df)[0]:.2f}"
print("After Prediction")

# Pass form data and result to the template
return render_template(
'index.html',
results=results,
Expand All @@ -54,8 +47,8 @@ def predict_datapoint():
writing_score=writing_score
)
else:
# If GET request, render the template without pre-filled values
return render_template('index.html')

if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=5000)
port = int(os.environ.get('PORT', 5000))
app.run(debug=True, host='0.0.0.0', port=port)

0 comments on commit aafdbde

Please sign in to comment.