Spaces:
Runtime error

File size: 6,157 Bytes
52d6091
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
132
133
134
135
import pickle
import json
import pandas as pd
import numpy as np
import streamlit as st


with open('./src/model.pkl', 'rb') as file_5:
  model = pickle.load(file_5)

def category_type(type):
    resident = ['Condo for sale','House for sale','Townhouse for sale','Co-op for sale','Multi-family home for sale', 'Mobile house for sale','Condop for sale']
    land = ['Land for sale']
    status = ['Foreclosure','Contingent','Pending','Coming Soon']
    general = ['For sale']

    if type in resident:
        return 'Residential'
    elif type in land:
        return 'Land'
    elif type in status:
        return 'Sales Status'
    elif type in general:
        return 'General Sale Status'
    else:
        return 'Other'

def category_beds(beds):
    if beds <= 5:
        return '0-5'
    elif beds <= 10:
        return '6-10'
    elif beds <= 15:
        return '11-15'
    elif beds <= 20:
        return '16-20'
    elif beds <= 25:
        return '21-25'
    elif beds <= 30:
        return '26-30'
    elif beds <= 35:
        return '31-35'
    elif beds <= 40:
        return '36-40'
    else:
        return '40+'

def extract_state(state):
    manhattan = ["Manhattan","New York","New York City","Roosevelt Island","Ny","Nyc","New York County"]
    brooklyn = ["Brooklyn","Brownville","Brooklyn Heights","Kensington","Canarsie","Bedford Stuyvesant","Crown Heights","Old Mill Basin","Stuyvesant Heights","East Flatbush","Ditmas Park","Brighton Beach",
                 "Prospect Lefferts Gardens","Kings County","Flatbush","Coney Island","Brooklyn Heights","Dumbo", "Snyder Avenue"]
    queens = ["Queens","Jackson Heights","Elmhurst","Woodside","Rego Park","Forest Hills","Briarwood","Flushing","Woodhaven","Jamaica","Richmond Hill South","Whitestone","Ridgewood","Rosedale","Ozone Park",
                "Springfield Gardens","Far Rockaway","Bellerose","Bayside","Astoria","Floral Park","Fresh Meadows","Howard Beach","Cambria Heights","Rockaway Park","East Elmhurst","Little Neck","Long Island City",
                "Corona","Kew Gardens","Maspeth","Queens Village","Richmond Hill","Middle Village","Saint Albans","South Ozone Park","College Point","Hollis","Malba","Glen Oaks","Douglaston","Sunnyside",
                "Arverne","Glendale","New Hyde Park","Beechhurst","Kew Gardens Hills","Belle Harbor","Kew Garden Hills","Queens County","Jackson Heights","Rego Park",]
    bronx = ["Bronx","Bronx Ny","The Bronx","Bronx County","East Bronx","Riverdale"]
    staten_island = ["Staten Island","Richmond County","Fort Hamilton" ]
    zip_code = ["11214", "10301", "10309", "10303", "11234", "11414", "10310","10003", "11417", "10304", "10463", "10017", "10306", "10471","11229", "10312", "11412", "10465", "10002", "10466", "11237","11218"]
    if state in manhattan:
        return 'Manhattan'
    elif state in brooklyn:
        return 'Brooklyn'
    elif state in queens:
        return 'Queens'
    elif state in bronx:
        return 'Bronx'
    elif state in staten_island:
        return 'Staten Island'
    elif state in zip_code:
        return 'Zip Codes'
    else:
        return 'Other'


def run():
  with st.form(key='prediksi_rumah'):
    brokertitle = st.text_input('Nama Anda', value='Bryan')
    type_properti = st.text_input('Type Properti', value='House for sale')
    beds = st.number_input('Jumlah Kamar Tidur',min_value=0,value=5,step=1)
    bath = st.number_input('Jumlah Kamar Mandi',min_value=0,value=5,step=1)
    luas = st.number_input('Luas Tanah(sqft)',min_value=100,value=100,step=1)
    address = st.text_input('Address',value='3652 DE Reimer Ave')
    state = st.text_input('State',value='Manhattan, NY 10010')
    main_address = st.text_area('Main Address',value='214 W 11th StManhattan, NY 10014')
    area_lvel_2 = st.text_input('Area Administrative',value='New York')
    sub_locality = st.text_input('Sublocality',value='New York County')
    locality = st.text_input('Locality',value='New York')
    street_name = st.text_input('Street Name',value='14 W 11th St, New York, NY 10014, USA')
    long_name = st.text_input('Long Name',value='Queens')
    formatted_addres = st.text_area('Formatted Address',value='250 E 21st St #12b, New York, NY 10010, USA')
    latitude = st.number_input('Latitude',min_value=200.00,value=200.00,step=0.001,format="%.2f")
    longitude = st.number_input('Longitude',min_value=-180.00,max_value=0.00,value=-73.95,step=0.01,format="%.2f")

    submited = st.form_submit_button('Predict')

    if submited:
        data_inf = {
            'BROKERTITLE' : brokertitle,
            'TYPE' : type_properti,
            'BEDS' : beds,
            'BATH' : bath,
            'PROPERTYSQFT' : luas,
            'ADDRESS' : address,
            'STATE' : state,
            'MAIN_ADDRESSS' : main_address,
            'ADMINISTRATIVE_AREA_LEVEL_2': area_lvel_2,
            'SUBLOCALITY': sub_locality,
            'LOCALITY': locality,
            'LONG_NAME': long_name,
            'STREET_NAME': street_name,
            'FORMATTED_ADDRES': formatted_addres,
            'LATITUDE': latitude,
            'LONGITUDE': longitude
        }

        data_inf = pd.DataFrame([data_inf])
        data_inf

        data_inf['TYPE'] = data_inf['TYPE'].apply(category_type)
        data_inf['BEDS'] = data_inf['BEDS'].apply(category_beds)
        data_inf['BATH'] = data_inf['BATH'].apply(category_beds)
        data_inf['STATE'] = data_inf['STATE'].str.split(',').str[0].str.strip()
        data_inf['STATE'] = data_inf['STATE'].apply(extract_state)
        data_inf['LOCALITY'] = data_inf['LOCALITY'].apply(extract_state)
        data_inf['SUBLOCALITY'] = data_inf['SUBLOCALITY'].apply(extract_state)
        data_inf['ADMINISTRATIVE_AREA_LEVEL_2'] = data_inf['ADMINISTRATIVE_AREA_LEVEL_2'].apply(extract_state)
        data_inf['STREET_NAME'] = data_inf['STREET_NAME'].apply(extract_state)

        y_pred_inf = model.predict(data_inf)
        st.write('### Prediksi Harga Rumah : ', str(int(y_pred_inf)))



if __name__ == '__name__':
  run()