Spaces:
Sleeping
Sleeping
File size: 5,166 Bytes
5426d51 |
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 |
import streamlit as st
import pandas as pd
import numpy as np
from autogluon.multimodal import MultiModalPredictor
from autogluon.tabular import TabularPredictor
# Define icons
seller_icon = "🏡"
buyer_icon = "🔍"
submit_icon = "📝"
predict_icon = "🔮"
# Initialize df as a global variable
df = None
def predict_price():
global df # Declare df as a global variable
# Set the title and subheader
st.title("Real Estate Price Prediction")
st.subheader("Choose your role and provide property details")
# User role selection
option = st.selectbox("Who are you?", ['Seller', 'Buyer'], index=0)
if option == "Seller":
st.subheader(f"{seller_icon} Seller Information")
with st.spinner("Loading model..."):
predictor = MultiModalPredictor.load("C:/Users/duong/OneDrive/Desktop/mm-nlp-image-transformer")
st.success("Done")
description = st.text_area("Property Description", help="Describe your property")
title = st.text_input("Property Title", help="Enter a title for your property")
else:
st.subheader(f"{buyer_icon} Buyer Information")
with st.spinner("Loading model..."):
predictor = TabularPredictor.load("C:/Users/duong/OneDrive/Desktop/tabular", require_py_version_match=False)
st.success("Done")
# Property details input
area = st.number_input("Property Area (square meters)", min_value=1)
location = st.text_input("Property Location", help="Enter the location of the property")
city_code = st.text_input("City Code", help="Enter the city code")
district = st.text_input("District", help="Enter the district name")
bedroom = st.slider("Number of Bedrooms", min_value=1, max_value=10, value=5, step=1)
bathroom = st.slider("Number of Bathrooms", min_value=1, max_value=10, value=2, step=1)
# Submit button to create the DataFrame
submitted = st.button(f"{submit_icon} Submit")
# Create a DataFrame from user inputs
if submitted:
if area and location and city_code and district and bedroom and bathroom:
if option == "Seller":
if (not description or not title):
st.error("Please fill in both Description and Title fields for Sellers.")
else:
data = {
"Price": np.nan,
"Area": [area],
"Location": [location],
"Time stamp": np.nan,
"Certification status": np.nan,
"Direction": np.nan,
"Bedrooms": [bedroom],
"Bathrooms": [bathroom],
"Front width": np.nan,
"Floor": np.nan,
"Image URL": np.nan,
"Road width": np.nan,
"City_code": [city_code],
"DistrictId": [district],
"Balcony_Direction": np.nan,
"Longitude": np.nan,
"Lattitude": np.nan,
"Description": [description],
"Title": [title]
}
df = pd.DataFrame(data)
st.write(f"{seller_icon} Input Data:")
st.dataframe(df)
elif option == "Buyer":
data = {
"Price": np.nan,
"Area": [area],
"Location": [location],
"Time stamp": np.nan,
"Certification status": np.nan,
"Direction": np.nan,
"Bedrooms": [bedroom],
"Bathrooms": [bathroom],
"Front width": np.nan,
"Floor": np.nan,
"Image URL": np.nan,
"Road width": np.nan,
"City_code": [city_code],
"DistrictId": [district],
"Balcony_Direction": np.nan,
"Longitude": np.nan,
"Lattitude": np.nan
}
df = pd.DataFrame(data)
st.write(f"{buyer_icon} Input Data:")
st.dataframe(df)
else:
st.error("Please fill in all fields to have a better prediction!")
# Prediction button (enabled only when data has been submitted)
if st.button(f"{predict_icon} Predict"):
with st.spinner("Loading..."):
# Perform predictions and calculations here
predictions = predictor.predict(df.drop(columns="Price"))
st.success(f"Predicted Price: {predictions[0]:,.0f} VND")
scores = predictor.evaluate(
df,
metrics=[
"mean_squared_error",
"r2",
],
)
st.subheader("Model Evaluation Metrics:")
for metric, score in scores.items():
st.write(f"{metric}: {score:.2f}")
|