|
| 1 | +import pickle #pip install pickle |
| 2 | + |
| 3 | +from flask import Flask, render_template, request #pip install flask |
| 4 | + |
| 5 | +from flask_sqlalchemy import SQLAlchemy #pip install Flask-SQLAlchemy |
| 6 | + |
| 7 | +app = Flask(__name__) |
| 8 | +app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///contact.db" |
| 9 | +app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False |
| 10 | +db = SQLAlchemy(app) |
| 11 | + |
| 12 | + |
| 13 | +file = open('model.pkl', 'rb') |
| 14 | +clf = pickle.load(file) |
| 15 | +file.close() |
| 16 | + |
| 17 | + |
| 18 | +class Contact(db.Model): |
| 19 | + id = db.Column(db.Integer, primary_key=True) |
| 20 | + email = db.Column(db.String(200), nullable=False) |
| 21 | + concern = db.Column(db.String(500), nullable=False) |
| 22 | + # date_created = db.Column(db.DateTime, default=datetime.utcnow) |
| 23 | + |
| 24 | + def __repr__(self) -> str: |
| 25 | + return f"{self.email} - {self.concern}" |
| 26 | + |
| 27 | +# route |
| 28 | +@app.route('/', methods=["GET", "POST"]) |
| 29 | +def index(): |
| 30 | + if request.method == "POST": |
| 31 | + query = request.form['query'] |
| 32 | + if query == "own": |
| 33 | + return render_template('form.html') |
| 34 | + elif query == "rent": |
| 35 | + # we can make two seperate form for owner and tenant but we will imrpove it |
| 36 | + return render_template('formrent.html') |
| 37 | + else: |
| 38 | + # we will make a seprate Error page for this in furture |
| 39 | + return "Page Not found please select valid input" |
| 40 | + return render_template('index.html') |
| 41 | + |
| 42 | + |
| 43 | +@app.route('/about', methods=["GET", "POST"]) |
| 44 | +def about(): |
| 45 | + if request.method == "POST": |
| 46 | + email = request.form['email'] |
| 47 | + concern = request.form['con'] |
| 48 | + detail = Contact(email=email, concern=concern) |
| 49 | + db.session.add(detail) |
| 50 | + db.session.commit() |
| 51 | + return render_template('about.html', res=True) |
| 52 | + return render_template('about.html') |
| 53 | + |
| 54 | + |
| 55 | +@app.route('/depend', methods=["GET", "POST"]) |
| 56 | +def depend(): |
| 57 | + return render_template('depend.html') |
| 58 | + |
| 59 | + |
| 60 | +@app.route('/form', methods=["GET", "POST"]) |
| 61 | +def form(): |
| 62 | + if request.method == "POST": |
| 63 | + bhk = int(request.form['bhk']) # range 1 to 3 |
| 64 | + health = int(request.form['health']) # range 1 to 5 |
| 65 | + school = int(request.form['school']) # range 1 to 4 |
| 66 | + pool = int(request.form['pool']) # 1 for exist 0 for not |
| 67 | + park = int(request.form['park']) # range 1 to 5 |
| 68 | + tax = int(request.form['tax']) # range 2000 to 5000 |
| 69 | + train = int(request.form['train']) # range 1 to 5 |
| 70 | + bus = int(request.form['bus']) # range 1 to 5 |
| 71 | + market = int(request.form['market']) # range 1 to 5 |
| 72 | + bank = int(request.form['bank']) # range 3 to 5 |
| 73 | + police_Station = int(request.form['police_Station']) # range 1 to 3 |
| 74 | + age = int(request.form['age']) # range 1 to 20 |
| 75 | + area = int(request.form['area']) # 1 for urban 0 for rural |
| 76 | + mall = int(request.form['mall']) # range 1 to 3 |
| 77 | + # range 5 to 10 for rural 10 to 20 for urban |
| 78 | + floor = int(request.form['floor']) |
| 79 | + worship = int(request.form['worship']) # range 1 to 12 |
| 80 | + |
| 81 | + inf = clf.predict([[pool, train, bus, school, park, 1, market, health, |
| 82 | + bank, bhk, tax, age, area, police_Station, mall, floor, worship]])[0] |
| 83 | + inf = -inf |
| 84 | + if area == 0: |
| 85 | + tag = "Lakh" |
| 86 | + else: |
| 87 | + inf = inf * 0.1 |
| 88 | + tag = "Crore" |
| 89 | + inf = round(inf, 2) |
| 90 | + # print(inf) |
| 91 | + return render_template('show.html', str="Price", inf=inf, tag=tag) |
| 92 | + |
| 93 | + |
| 94 | +@app.route('/formRent', methods=["GET", "POST"]) |
| 95 | +def form_Rent(): |
| 96 | + if request.method == "POST": |
| 97 | + bhk = int(request.form['bhk']) # range 1 to 3 |
| 98 | + health = int(request.form['health']) # range 1 to 5 |
| 99 | + school = int(request.form['school']) # range 1 to 4 |
| 100 | + pool = int(request.form['pool']) # 1 for exist 0 for not |
| 101 | + park = int(request.form['park']) # range 1 to 5 |
| 102 | + tax = int(request.form['tax']) # range 2000 to 5000 |
| 103 | + train = int(request.form['train']) # range 1 to 5 |
| 104 | + bus = int(request.form['bus']) # range 1 to 5 |
| 105 | + market = int(request.form['market']) # range 1 to 5 |
| 106 | + bank = int(request.form['bank']) # range 3 to 5 |
| 107 | + police_Station = int(request.form['police_Station']) # range 1 to 3 |
| 108 | + age = int(request.form['age']) # range 1 to 20 |
| 109 | + area = int(request.form['area']) # 1 for urban 0 for rural |
| 110 | + mall = int(request.form['mall']) # range 1 to 3 |
| 111 | + # range 5 to 10 for rural 10 to 20 for urban |
| 112 | + floor = int(request.form['floor']) |
| 113 | + worship = int(request.form['worship']) # range 1 to 12 |
| 114 | + |
| 115 | + inf = clf.predict([[pool, train, bus, school, park, 1, market, health, |
| 116 | + bank, bhk, tax, age, area, police_Station, mall, floor, worship]])[0] |
| 117 | + inf = -inf |
| 118 | + if area == 1: |
| 119 | + inf = inf - (inf*0.1*4) |
| 120 | + else: |
| 121 | + inf = inf - (inf*0.1*8) |
| 122 | + inf = round(inf, 2) |
| 123 | + |
| 124 | + # print(inf) |
| 125 | + return render_template('show.html', str="Rent", inf=inf, tag="thousand") |
| 126 | + |
| 127 | + |
| 128 | +if __name__ == "__main__": |
| 129 | + app.run(debug=True) |
0 commit comments