File size: 3,044 Bytes
d17483b d018910 d17483b d018910 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
from flask import Flask, request, jsonify, render_template_string
import joblib
import numpy as np
# Load trained model
model = joblib.load('house_price_model.pkl')
app = Flask(__name__)
# Simple HTML UI
HTML_PAGE = """
<!DOCTYPE html>
<html>
<head>
<title>House Price Predictor</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #121212;
color: white;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
.container {
background: #1e1e1e;
padding: 30px;
border-radius: 12px;
width: 350px;
box-shadow: 0 0 15px rgba(0,0,0,0.4);
}
h1 {
text-align: center;
margin-bottom: 25px;
}
input {
width: 100%;
padding: 10px;
margin-top: 10px;
border-radius: 6px;
border: none;
font-size: 16px;
}
button {
width: 100%;
padding: 12px;
margin-top: 20px;
background: #00b894;
color: white;
border: none;
border-radius: 6px;
font-size: 16px;
cursor: pointer;
}
button:hover {
background: #00a383;
}
.result {
margin-top: 20px;
text-align: center;
font-size: 20px;
font-weight: bold;
color: #00ff99;
}
</style>
</head>
<body>
<div class="container">
<h1>House Price Predictor</h1>
<form method="POST">
<input type="number" name="area" placeholder="Area in sqft" required>
<input type="number" name="bath" placeholder="Bathrooms" required>
<input type="number" name="bhk" placeholder="BHK" required>
<input type="number" step="0.01" name="location" placeholder="Location Avg Price" required>
<button type="submit">Predict Price</button>
</form>
{% if prediction %}
<div class="result">
Predicted Price: ₹ {{ prediction }} Lakhs
</div>
{% endif %}
</div>
</body>
</html>
"""
@app.route('/', methods=['GET', 'POST'])
def home():
prediction = None
if request.method == 'POST':
area = float(request.form['area'])
bath = float(request.form['bath'])
bhk = float(request.form['bhk'])
location = float(request.form['location'])
features = np.array([[area, bath, bhk, location]])
pred = model.predict(features)
prediction = round(np.exp(pred[0]), 2)
return render_template_string(HTML_PAGE, prediction=prediction)
if __name__ == "__main__":
import os
port = int(os.environ.get("PORT", 7860))
app.run(host="0.0.0.0", port=port)
|