Spaces:
Runtime error

minor-project / app.py
RuthBebe's picture
Update app.py
6c02389
Raw History Blame Contribute Delete
2.02 kB
from flask import *
import sqlite3
import numpy as np
import pandas as pd
import joblib
from sklearn.linear_model import LinearRegression
app = Flask(__name__)
@app.route('/ml')
def run():
url='https://raw.githubusercontent.com/sarwansingh/Python/master/ClassExamples/data/student-pass-fail-data.csv'
df=pd.read_csv(url)
df1=df.values
X=df1[:,0:2]
Y= df1[:,2]
model=LinearRegression()
model.fit(X,Y)
var=model.predict([[7,27]])
return "The prdeicted result is " + str(var[0]* 100) + "%"
@app.route('/')
def indexpage():
return render_template('index.html')
@app.route('/p', methods=["POST"])
def mainpage():
selfstudy= eval(request.form.get("selfstudy"))
tut= eval(request.form.get("tut"))
# model prediction
url='https://raw.githubusercontent.com/sarwansingh/Python/master/ClassExamples/data/student-pass-fail-data.csv'
df=pd.read_csv(url)
df1=df.values
X=df1[:,0:2]
Y= df1[:,2]
model=LinearRegression()
model.fit(X,Y)
var=model.predict([[selfstudy,tut]])
result=var[0]*100
if result >50:
return render_template('index.html', data= str(round(result)) + "% implies a high chance of passing" )
else:
return render_template('index.html', data= str(round(result)) + "% implies you might fail" )
@app.route('/carprice')
def carpricepage():
return render_template('carprice.html')
@app.route('/carpriceprediction', methods=["POST"])
def carpricepredict():
fueltype=int(request.form.get("fueltype"))
enginetype=int(request.form.get("enginetype"))
enginesize=int(request.form.get("enginesize"))
horsepower=int(request.form.get("horsepower"))
car=pd.read_csv('https://raw.githubusercontent.com/Ruth-Oteng/data/main/car%20price.csv')
model5 =joblib.load('carprice.pkl') #carmodel=joblib.load('carprice.pkl')
predictModel= model5.predict([[fueltype,enginetype,enginesize,horsepower]])
return render_template('carprice.html', data=str(predictModel[0]))
if __name__ == '__main__':
app.run(host="0.0.0.0", port=7860)