Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,75 @@
|
|
| 1 |
-
import streamlit
|
| 2 |
-
|
| 3 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
# Title of the application
|
| 6 |
st.markdown("<h1 class='title'>🏡 House Price Predictor</h1>", unsafe_allow_html=True)
|
|
@@ -17,3 +86,22 @@ with st.expander("🔹 **Property Details**", expanded=True):
|
|
| 17 |
RESALE = st.selectbox("RESALE", [1, 0])
|
| 18 |
LONGITUDE = st.number_input("LONGITUDE", min_value=-37.713008, max_value=39.573320499999994, value=20.750000)
|
| 19 |
LATITUDE = st.number_input("LATITUDE", min_value=-121.761248, max_value=152.962676, value=77.324137)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import numpy as np
|
| 3 |
+
import pickle
|
| 4 |
+
import pandas as pd
|
| 5 |
+
|
| 6 |
+
# Load Model
|
| 7 |
+
try:
|
| 8 |
+
with open("final_model.pkl", "rb") as f:
|
| 9 |
+
model = pickle.load(f)
|
| 10 |
+
st.success("✅ Model loaded successfully!")
|
| 11 |
+
except FileNotFoundError:
|
| 12 |
+
st.error("❌ Model file not found! Please upload `final_model.pkl`.")
|
| 13 |
+
model = None
|
| 14 |
+
|
| 15 |
+
# Apply Dark Theme CSS
|
| 16 |
+
st.markdown(
|
| 17 |
+
"""
|
| 18 |
+
<style>
|
| 19 |
+
body {
|
| 20 |
+
background-color: #121212;
|
| 21 |
+
color: #FFFFFF;
|
| 22 |
+
}
|
| 23 |
+
.stApp {
|
| 24 |
+
background-color: #121212;
|
| 25 |
+
color: #FFFFFF;
|
| 26 |
+
}
|
| 27 |
+
.title {
|
| 28 |
+
text-align: center;
|
| 29 |
+
font-size: 36px;
|
| 30 |
+
font-weight: bold;
|
| 31 |
+
color: #BB86FC;
|
| 32 |
+
}
|
| 33 |
+
.stButton > button {
|
| 34 |
+
width: 100%;
|
| 35 |
+
background-color: #6200EE;
|
| 36 |
+
color: white;
|
| 37 |
+
font-size: 18px;
|
| 38 |
+
border-radius: 8px;
|
| 39 |
+
padding: 10px;
|
| 40 |
+
transition: 0.3s ease-in-out;
|
| 41 |
+
}
|
| 42 |
+
.stButton > button:hover {
|
| 43 |
+
background-color: #3700B3;
|
| 44 |
+
transform: scale(1.05);
|
| 45 |
+
}
|
| 46 |
+
.result-box {
|
| 47 |
+
text-align: center;
|
| 48 |
+
font-size: 20px;
|
| 49 |
+
font-weight: bold;
|
| 50 |
+
color: white;
|
| 51 |
+
padding: 12px;
|
| 52 |
+
border-radius: 8px;
|
| 53 |
+
margin-top: 20px;
|
| 54 |
+
box-shadow: 0px 4px 8px rgba(255, 255, 255, 0.2);
|
| 55 |
+
transition: 0.3s ease-in-out;
|
| 56 |
+
}
|
| 57 |
+
.result-box:hover {
|
| 58 |
+
transform: scale(1.05);
|
| 59 |
+
}
|
| 60 |
+
.high-risk {
|
| 61 |
+
background-color: #D32F2F;
|
| 62 |
+
}
|
| 63 |
+
.low-risk {
|
| 64 |
+
background-color: #388E3C;
|
| 65 |
+
}
|
| 66 |
+
.probability {
|
| 67 |
+
background-color: #FFA726;
|
| 68 |
+
}
|
| 69 |
+
</style>
|
| 70 |
+
""",
|
| 71 |
+
unsafe_allow_html=True,
|
| 72 |
+
)
|
| 73 |
|
| 74 |
# Title of the application
|
| 75 |
st.markdown("<h1 class='title'>🏡 House Price Predictor</h1>", unsafe_allow_html=True)
|
|
|
|
| 86 |
RESALE = st.selectbox("RESALE", [1, 0])
|
| 87 |
LONGITUDE = st.number_input("LONGITUDE", min_value=-37.713008, max_value=39.573320499999994, value=20.750000)
|
| 88 |
LATITUDE = st.number_input("LATITUDE", min_value=-121.761248, max_value=152.962676, value=77.324137)
|
| 89 |
+
|
| 90 |
+
if st.button("🔍 Predict Price"):
|
| 91 |
+
try:
|
| 92 |
+
# Create input data for prediction
|
| 93 |
+
input_data = [[POSTED_BY, UNDER_CONSTRUCTION, RERA, bhk_no, BHK_OR_RK, SQUARE_FT,
|
| 94 |
+
READY_TO_MOVE, RESALE, LONGITUDE, LATITUDE]]
|
| 95 |
+
|
| 96 |
+
# Make prediction using the model
|
| 97 |
+
predicted_price = model.predict(input_data)[0]
|
| 98 |
+
|
| 99 |
+
# Display predicted price
|
| 100 |
+
st.markdown(
|
| 101 |
+
f"<div class='result-box'>🏠 Predicted Price: ₹ {predicted_price:.2f} Lakhs</div>",
|
| 102 |
+
unsafe_allow_html=True,
|
| 103 |
+
)
|
| 104 |
+
|
| 105 |
+
except Exception as e:
|
| 106 |
+
st.error(f"⚠️ Prediction failed: {e}")
|
| 107 |
+
|