Spaces:
Runtime error
Runtime error
Nathanotal
commited on
Commit
·
870119b
1
Parent(s):
bcf937e
pricefix
Browse files
app.py
CHANGED
@@ -35,6 +35,17 @@ featureToMinMax = {
|
|
35 |
'soldDate': (2010, 2025)
|
36 |
} # Extracted from the data
|
37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
def downloadAutogluonModel():
|
39 |
# Download saved Autogluon model from Hopsworks
|
40 |
project = hopsworks.login(
|
@@ -121,14 +132,6 @@ def fixChange(df):
|
|
121 |
|
122 |
return df
|
123 |
|
124 |
-
def fixChange(df):
|
125 |
-
# Set change to be the difference between the current and previous price
|
126 |
-
df['change'] = df['value'].diff()
|
127 |
-
# If the change is Nan set it to 0
|
128 |
-
df['change'] = df['change'].fillna(0)
|
129 |
-
|
130 |
-
return df
|
131 |
-
|
132 |
def cleanAddress(x):
|
133 |
# Remove "-" from the street
|
134 |
x = ''.join(x.split('-'))
|
@@ -211,13 +214,12 @@ def parsePrice(price):
|
|
211 |
|
212 |
def addDotsToPrice(price):
|
213 |
# Takes an int like 1000000 and returns a string like 1.000.000
|
214 |
-
price = str(price)
|
215 |
toReturn = ''
|
216 |
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
if i % 3 == 0 and i != 0:
|
221 |
toReturn += '.'
|
222 |
|
223 |
# Reverse the string
|
@@ -273,9 +275,9 @@ def isValidInput(streetName, number, sqm, rooms, monthlyFee, monthlyCost, floor,
|
|
273 |
MIN = featureToMinMax[name][0]
|
274 |
MAX = featureToMinMax[name][1]
|
275 |
if val < MIN:
|
276 |
-
return f'{name} is too low'
|
277 |
if val > MAX:
|
278 |
-
return f'{name} is too high'
|
279 |
|
280 |
return None
|
281 |
|
@@ -304,18 +306,15 @@ def sthlm(streetName, number, sqm, rooms, monthlyFee, monthlyCost, floor, yearBu
|
|
304 |
if inputErrors is not None:
|
305 |
return '', inputErrors
|
306 |
lat, lon = getAddressInfo(streetName, number)
|
307 |
-
print('1')
|
308 |
# If none
|
309 |
if lat is None or lon is None:
|
310 |
return '', 'Address not found in the OpenStreetMap dataset (Nominatim), please try another address'
|
311 |
-
print('2')
|
312 |
|
313 |
agency = 'Notar' # Make fun if categorical works
|
314 |
brf = 'BRF Kartboken 1' # TODO: remove
|
315 |
dates = getDates()
|
316 |
input_variables = pd.DataFrame(
|
317 |
columns=columnHeaders)
|
318 |
-
print('3')
|
319 |
|
320 |
for soldDate in dates.keys():
|
321 |
# gdp, unemployment, interestRate = getFinancialInfo(soldDate)
|
@@ -325,12 +324,9 @@ def sthlm(streetName, number, sqm, rooms, monthlyFee, monthlyCost, floor, yearBu
|
|
325 |
input_variables = input_variables.append(
|
326 |
pd.DataFrame(
|
327 |
[[streetName,number,sqm,rooms,soldDate,monthlyFee,monthlyCost,floor,yearBuilt,brf,agency,lat,lon]], columns=columnHeaders))
|
328 |
-
print('4')
|
329 |
|
330 |
df = populateApartmentData(input_variables)
|
331 |
-
print('5')
|
332 |
df = normalizeData(df)
|
333 |
-
print('6')
|
334 |
df = xgbFix(df)
|
335 |
|
336 |
pricePred = None
|
@@ -338,9 +334,7 @@ def sthlm(streetName, number, sqm, rooms, monthlyFee, monthlyCost, floor, yearBu
|
|
338 |
# pricePred = autoPred(df)
|
339 |
'', 'Autogluon is not working right now, please try again later'
|
340 |
else:
|
341 |
-
print('7')
|
342 |
pricePred = xgboostPred(df)
|
343 |
-
print('8')
|
344 |
|
345 |
explanations = list(dates.values())
|
346 |
result = []
|
@@ -365,16 +359,7 @@ def sthlm(streetName, number, sqm, rooms, monthlyFee, monthlyCost, floor, yearBu
|
|
365 |
numericalInputs = ['number', 'sqm','rooms', 'monthlyFee','monthlyCost','floor','yearBuilt']
|
366 |
inputs = [gr.inputs.Textbox(lines=1, label='streetName')]
|
367 |
|
368 |
-
|
369 |
-
'number' : 'Street number',
|
370 |
-
'sqm' : 'Size of the apartment in square meters',
|
371 |
-
'rooms' : 'Number of rooms',
|
372 |
-
'monthlyFee' : 'Monthly fee',
|
373 |
-
'monthlyCost' : 'Monthly operating cost',
|
374 |
-
'floor' : 'Floor',
|
375 |
-
'yearBuilt' : 'Year built',
|
376 |
-
'streetName' : 'Name of street',
|
377 |
-
}
|
378 |
|
379 |
# Generate the input form
|
380 |
for feature in numericalInputs:
|
|
|
35 |
'soldDate': (2010, 2025)
|
36 |
} # Extracted from the data
|
37 |
|
38 |
+
featureToName = {
|
39 |
+
'number' : 'Street number',
|
40 |
+
'sqm' : 'Size of the apartment in square meters',
|
41 |
+
'rooms' : 'Number of rooms',
|
42 |
+
'monthlyFee' : 'Monthly fee',
|
43 |
+
'monthlyCost' : 'Monthly operating cost',
|
44 |
+
'floor' : 'Floor',
|
45 |
+
'yearBuilt' : 'Year built',
|
46 |
+
'streetName' : 'Name of street',
|
47 |
+
}
|
48 |
+
|
49 |
def downloadAutogluonModel():
|
50 |
# Download saved Autogluon model from Hopsworks
|
51 |
project = hopsworks.login(
|
|
|
132 |
|
133 |
return df
|
134 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
def cleanAddress(x):
|
136 |
# Remove "-" from the street
|
137 |
x = ''.join(x.split('-'))
|
|
|
214 |
|
215 |
def addDotsToPrice(price):
|
216 |
# Takes an int like 1000000 and returns a string like 1.000.000
|
217 |
+
price = str(price)[::-1]
|
218 |
toReturn = ''
|
219 |
|
220 |
+
for i, c in enumerate(price):
|
221 |
+
toReturn += c
|
222 |
+
if (len(price) - i) % 3 == 1 and i != len(price) - 1:
|
|
|
223 |
toReturn += '.'
|
224 |
|
225 |
# Reverse the string
|
|
|
275 |
MIN = featureToMinMax[name][0]
|
276 |
MAX = featureToMinMax[name][1]
|
277 |
if val < MIN:
|
278 |
+
return f'{featureToName.get(name)} is too low'
|
279 |
if val > MAX:
|
280 |
+
return f'{featureToName.get(name)} is too high'
|
281 |
|
282 |
return None
|
283 |
|
|
|
306 |
if inputErrors is not None:
|
307 |
return '', inputErrors
|
308 |
lat, lon = getAddressInfo(streetName, number)
|
|
|
309 |
# If none
|
310 |
if lat is None or lon is None:
|
311 |
return '', 'Address not found in the OpenStreetMap dataset (Nominatim), please try another address'
|
|
|
312 |
|
313 |
agency = 'Notar' # Make fun if categorical works
|
314 |
brf = 'BRF Kartboken 1' # TODO: remove
|
315 |
dates = getDates()
|
316 |
input_variables = pd.DataFrame(
|
317 |
columns=columnHeaders)
|
|
|
318 |
|
319 |
for soldDate in dates.keys():
|
320 |
# gdp, unemployment, interestRate = getFinancialInfo(soldDate)
|
|
|
324 |
input_variables = input_variables.append(
|
325 |
pd.DataFrame(
|
326 |
[[streetName,number,sqm,rooms,soldDate,monthlyFee,monthlyCost,floor,yearBuilt,brf,agency,lat,lon]], columns=columnHeaders))
|
|
|
327 |
|
328 |
df = populateApartmentData(input_variables)
|
|
|
329 |
df = normalizeData(df)
|
|
|
330 |
df = xgbFix(df)
|
331 |
|
332 |
pricePred = None
|
|
|
334 |
# pricePred = autoPred(df)
|
335 |
'', 'Autogluon is not working right now, please try again later'
|
336 |
else:
|
|
|
337 |
pricePred = xgboostPred(df)
|
|
|
338 |
|
339 |
explanations = list(dates.values())
|
340 |
result = []
|
|
|
359 |
numericalInputs = ['number', 'sqm','rooms', 'monthlyFee','monthlyCost','floor','yearBuilt']
|
360 |
inputs = [gr.inputs.Textbox(lines=1, label='streetName')]
|
361 |
|
362 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
363 |
|
364 |
# Generate the input form
|
365 |
for feature in numericalInputs:
|