import streamlit as st
import joblib
import pandas as pd
import numpy as np
from preprocess_pipeline import SingleInstancePreprocessor
from get_real_home_listing import get_home_listings
from home_listing_display import display_home_listings
model = joblib.load('random_forest.joblib')
preprocessor = SingleInstancePreprocessor()
temp = {}
st.set_page_config(
page_title="🏠 Ev Fiyatı Tahmin ve Öneri aracı",
page_icon="🏠",
layout="wide",
initial_sidebar_state="expanded",
)
st.markdown("""
""", unsafe_allow_html=True)
with st.container():
st.markdown("""
""", unsafe_allow_html=True)
with st.container():
col1, col2 = st.columns([1, 1.2])
with col1:
st.markdown('📍 Lokasyon Bilgileri
', unsafe_allow_html=True)
st.markdown('Ev fiyatı tahmini yapmak için lütfen aşağıdaki bilgileri doldurun.
', unsafe_allow_html=True)
with st.container():
st.markdown('', unsafe_allow_html=True)
il_listesi = list(preprocessor.location_map.keys())
selected_il = st.selectbox('İl', options=il_listesi)
ilceler = list(preprocessor.location_map.get(selected_il, {}).keys())
selected_ilce = st.selectbox('İlçe', options=ilceler)
mahalleler = preprocessor.location_map.get(selected_il, {}).get(selected_ilce, [])
selected_mahalle = st.selectbox('Mahalle', options=mahalleler)
st.markdown('
', unsafe_allow_html=True)
st.markdown('📐 Temel Özellikler
', unsafe_allow_html=True)
with st.container():
st.markdown('', unsafe_allow_html=True)
tipi = st.selectbox('Konut Tipi', options=['Daire', 'Residence', 'Villa', 'Müstakil Ev', 'Yazlık'])
brut_metrekare = st.number_input('Brüt Metrekare (m²)', min_value=30, max_value=500, value=100)
binanin_yasi = st.number_input('Bina Yaşı', min_value=0, max_value=100, value=5)
st.markdown('
', unsafe_allow_html=True)
with col2:
st.markdown('📊 Detaylı Özellikler
', unsafe_allow_html=True)
with st.container():
st.markdown('', unsafe_allow_html=True)
cols = st.columns(2)
with cols[0]:
oda_sayisi = st.selectbox('Oda', options=['1+1', '2+1', '3+1', '4+1', '5+1'])
banyo_sayisi = st.number_input('Banyo', min_value=1, max_value=5, value=1)
isitma_tipi = st.selectbox('Isıtma Tipi', options=['Doğalgaz', 'Merkezi Sistem', 'Elektrikli', 'Soba'])
with cols[1]:
bulundugu_kat = 3 # Ortalama veya tipik bir değer
binanin_kat_sayisi = 10 # Ortalama veya tipik bir değer
esya_durumu = st.selectbox('Eşya Durumu', options=['Eşyalı', 'Eşyasız'])
st.markdown('
', unsafe_allow_html=True)
st.markdown('⚙️ Diğer Ayarlar
', unsafe_allow_html=True)
with st.container():
st.markdown('', unsafe_allow_html=True)
cols = st.columns(2)
with cols[0]:
site_icerisinde = st.selectbox('Site İçinde', options=['Evet', 'Hayır'])
with cols[1]:
kullanim_durumu = st.selectbox('Kullanım Durumu', options=['Konut', 'İş Yeri', 'Diğer'])
st.markdown('
', unsafe_allow_html=True)
if st.button('💵 Tahmin Yap', use_container_width=True):
input_data = {
'Oda Sayısı': oda_sayisi,
'Bulunduğu Kat': bulundugu_kat,
'Isıtma Tipi': isitma_tipi,
'Eşya Durumu': esya_durumu,
'Site İçerisinde': site_icerisinde,
'Tipi': tipi,
'Brüt Metrekare': brut_metrekare,
'Binanın Yaşı': binanin_yasi,
'Binanın Kat Sayısı': binanin_kat_sayisi,
'Kullanım Durumu': kullanim_durumu,
'Banyo Sayısı': banyo_sayisi,
'İl': selected_il,
'İlçe': selected_ilce,
'Mahalle': selected_mahalle
}
with st.spinner('AI analiz yapıyor...'):
input_array = preprocessor.transform(input_data)
tahmin = model.predict(input_array)
st.markdown(f'''
TAHMİN EDİLEN DEĞER
{tahmin[0]:,.0f} TL
*Gerçek değerler piyasa koşullarına göre değişiklik gösterebilir
''', unsafe_allow_html=True)
predicted_price = tahmin[0]
with st.spinner("Seçim ile benzer özelliğe sahip ilanlar getiriliyor..."):
home_listings = get_home_listings(selected_il, predicted_price)
display_home_listings(home_listings)
st.markdown('''
''', unsafe_allow_html=True)