Spaces:
Runtime error
Runtime error
gsheet
Browse files
app.py
CHANGED
|
@@ -13,47 +13,8 @@ from datetime import datetime
|
|
| 13 |
import gspread
|
| 14 |
import json
|
| 15 |
from oauth2client.service_account import ServiceAccountCredentials
|
| 16 |
-
|
| 17 |
-
from utils import geosubset
|
| 18 |
|
| 19 |
-
scope = ['https://www.googleapis.com/auth/spreadsheets',
|
| 20 |
-
"https://www.googleapis.com/auth/drive"]
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
keydict = {'type': st.secrets["type"],
|
| 27 |
-
'project_id': st.secrets["project_id"],
|
| 28 |
-
'private_key_id': st.secrets["private_key_id"],
|
| 29 |
-
'private_key': '-----BEGIN PRIVATE KEY-----\n' + st.secrets["private_key1"] + '\n' + st.secrets["private_key2"] + '\n' + st.secrets["private_key3"] + '\nz/Y8688FgEzPXYdHq7ip7DMBnEXYRGaI4B1k+F2PLi9AGrBJ2AnbMrPqftlZLHVC\n' + st.secrets["private_key13"] + '\njS7sPU4rL+NlPqvOdsrmHtuI0l9Obw0qU4rJN/rwatZI2Gli0wETgDdh23Mho2c8\n' + st.secrets["private_key4"] + '\nDSwcWUU0Uzw9OIDNR6LdOwscsxWBB5jnJHSaXOFSmCL6uStJde5TH948UBxIFSh5\n8k4HmWXU2Z3p8nZZy9DH+X52CMMRhenortk5DRkNsdTK8yZnLC3T/Zl/3EYD8DBk\n' + st.secrets["private_key6"] + '\ncelewiKhMGHHjSQqKHF0KWVEq0dr12FXouTbR1XGSbJrCXCxjOckBbuSAcRk7mAt\n' + st.secrets["private_key7"] + '\n6G+amSe9DqfQGVqRo4t+ZXxlKLQkOOKaz95HTGl6nIGzSiemsgOnIBZgeSRNvmsr\n' + st.secrets["private_key8"] + '\nd63heAd+1G8uglvyvk/ikTQnrwKBgQDL5IrUuqG+5HFyLRbX3Nhg/WM23Z7xGb1G\nDAr3sqxAJqz8sN1p5PmIHp4k6UYO46XpSR6ZP+S3IsFDeWmbp+1kEB3wyaYsoVHs\n' + st.secrets["private_key9"] + '\nM7lqFXaXqQKBgG3uesahQbbXcBY5zV2Fkwo2kNuBh9UgGNwexfus9G8F8m+B1WXE\n34d0wvgrJa0VeNqE1XC53lyPP/ZsKROzvW8XDUeebno2VOC95+RMzX7pmx5jdJaf\n' + st.secrets["private_key10"] + '\ndDLO7EHwEBWPDWIoulDT0X7GfRmGKYWrCxVjW5HEW9xhvkw5zuhiiPpE5sWXMqp3\n' + st.secrets["private_key11"] + '\nrws8MdFBKPxuRvP85O1BcdIZEKwt9Zx/nCWAx5eZAoGAeoOy8MD0EiXscQUYEN7E\n' + st.secrets["private_key12"] + '\n8zZ8vE6s+0Gj5P2fd2LrbMtJy6x/s6TwCcgIdfCycUC4GjVqHe3GdJ687AfhxoH1\n' + st.secrets["private_key5"] + '\n-----END PRIVATE KEY-----\n',
|
| 30 |
-
'client_email': st.secrets["client_email"],
|
| 31 |
-
'client_id': st.secrets["client_id"],
|
| 32 |
-
'auth_uri': st.secrets["auth_uri"],
|
| 33 |
-
'token_uri': st.secrets["token_uri"],
|
| 34 |
-
'auth_provider_x509_cert_url': st.secrets["auth_provider_x509_cert_url"],
|
| 35 |
-
'client_x509_cert_url': st.secrets["client_x509_cert_url"]}
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
credentials = ServiceAccountCredentials.from_json_keyfile_dict(keydict, scope)
|
| 41 |
-
client = gspread.authorize(credentials)
|
| 42 |
-
|
| 43 |
-
sheet = client.open("PropertyPricePredictor_Sheet").sheet1
|
| 44 |
-
sheet.append_row([1,2,3,4,5,655123])
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
fig, ax = plt.subplots()
|
| 49 |
-
geosubset = geosubset.sample(10)
|
| 50 |
-
geosubset['year'] = geosubset['transactDa'].dt.year
|
| 51 |
-
st.write(geosubset['transactDa'].dt.year)
|
| 52 |
-
sns.swarmplot(data=geosubset, y='resale_pri', orient='v', ax=ax, hue='year')
|
| 53 |
-
geosubset.drop(columns=['year'], inplace=True)
|
| 54 |
-
st.pyplot(fig)
|
| 55 |
-
|
| 56 |
-
st.stop()
|
| 57 |
########## Title for the Web App ##########
|
| 58 |
st.title("Property Price Predictor")
|
| 59 |
st.markdown('_Creator: GOH Hong Aik [[LinkedIn]](https://www.linkedin.com/in/hongaikgoh/)_')
|
|
@@ -227,8 +188,8 @@ with st.form("inputs"):
|
|
| 227 |
st_folium(map, width=700, height=450)
|
| 228 |
|
| 229 |
fig, ax = plt.subplots()
|
| 230 |
-
sns.swarmplot(y=geosubset['resale_pri'], orient='v', ax=ax, hue=geosubset['
|
| 231 |
-
plt.scatter(0, prediction_price, color='orange')
|
| 232 |
plt.text(0.05, prediction_price, 'Your predicted property price')
|
| 233 |
plt.ylabel('Resale Price ($)')
|
| 234 |
plt.title('Swarmplot of nearby similar properties')
|
|
@@ -332,54 +293,23 @@ with st.form("inputs"):
|
|
| 332 |
|
| 333 |
# Log searches
|
| 334 |
|
| 335 |
-
# private_key = st.secrets['private_key']
|
| 336 |
-
# st.write(private_key)
|
| 337 |
-
|
| 338 |
-
# private_key = "-----BEGIN PRIVATE KEY-----\nMIIEv" + private_key + "Y8yY=\n-----END PRIVATE KEY-----"
|
| 339 |
-
# st.write(private_key)
|
| 340 |
-
# st.write(private_key[:40])
|
| 341 |
-
# st.write(private_key[-40:])
|
| 342 |
-
|
| 343 |
-
# import re
|
| 344 |
-
# r = re.compile("\s*-----BEGIN (.*)-----\n")
|
| 345 |
-
# m = r.match(private_key)
|
| 346 |
-
# if not m:
|
| 347 |
-
# raise ValueError("Not a valid PEM pre boundaryAAA")
|
| 348 |
-
# marker = m.group(1)
|
| 349 |
-
# st.write(marker)
|
| 350 |
-
|
| 351 |
-
# # Verify Post-Encapsulation Boundary
|
| 352 |
-
# r = re.compile("-----END (.*)-----\s*$")
|
| 353 |
-
# m = r.search(private_key)
|
| 354 |
-
# if not m or m.group(1) != marker:
|
| 355 |
-
# raise ValueError("Not a valid PEM post boundaryAAA")
|
| 356 |
-
# st.write(m.group(1))
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
keydict = {'type': st.secrets["type"],
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
r = json.dumps(keydict)
|
| 372 |
-
loaded_r = json.loads(r)
|
| 373 |
|
| 374 |
scope = ['https://www.googleapis.com/auth/spreadsheets',
|
| 375 |
"https://www.googleapis.com/auth/drive"]
|
| 376 |
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
client = gspread.authorize(credentials)
|
| 381 |
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
except:
|
| 385 |
-
pass
|
|
|
|
| 13 |
import gspread
|
| 14 |
import json
|
| 15 |
from oauth2client.service_account import ServiceAccountCredentials
|
| 16 |
+
from utils import *
|
|
|
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
########## Title for the Web App ##########
|
| 19 |
st.title("Property Price Predictor")
|
| 20 |
st.markdown('_Creator: GOH Hong Aik [[LinkedIn]](https://www.linkedin.com/in/hongaikgoh/)_')
|
|
|
|
| 188 |
st_folium(map, width=700, height=450)
|
| 189 |
|
| 190 |
fig, ax = plt.subplots()
|
| 191 |
+
sns.swarmplot(x=['']*len(geosubset), y=geosubset['resale_pri'], orient='v', ax=ax, hue=geosubset['transactDa'].dt.year, alpha=0.75)
|
| 192 |
+
plt.scatter(0, prediction_price, color='orange', s=100, marker='x')
|
| 193 |
plt.text(0.05, prediction_price, 'Your predicted property price')
|
| 194 |
plt.ylabel('Resale Price ($)')
|
| 195 |
plt.title('Swarmplot of nearby similar properties')
|
|
|
|
| 293 |
|
| 294 |
# Log searches
|
| 295 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 296 |
keydict = {'type': st.secrets["type"],
|
| 297 |
+
'project_id': st.secrets["project_id"],
|
| 298 |
+
'private_key_id': st.secrets["private_key_id"],
|
| 299 |
+
'private_key': '-----BEGIN PRIVATE KEY-----\n' + st.secrets["private_key1"] + '\n' + st.secrets["private_key2"] + '\n' + st.secrets["private_key3"] + '\nz/Y8688FgEzPXYdHq7ip7DMBnEXYRGaI4B1k+F2PLi9AGrBJ2AnbMrPqftlZLHVC\n' + st.secrets["private_key13"] + '\njS7sPU4rL+NlPqvOdsrmHtuI0l9Obw0qU4rJN/rwatZI2Gli0wETgDdh23Mho2c8\n' + st.secrets["private_key4"] + '\nDSwcWUU0Uzw9OIDNR6LdOwscsxWBB5jnJHSaXOFSmCL6uStJde5TH948UBxIFSh5\n8k4HmWXU2Z3p8nZZy9DH+X52CMMRhenortk5DRkNsdTK8yZnLC3T/Zl/3EYD8DBk\n' + st.secrets["private_key6"] + '\ncelewiKhMGHHjSQqKHF0KWVEq0dr12FXouTbR1XGSbJrCXCxjOckBbuSAcRk7mAt\n' + st.secrets["private_key7"] + '\n6G+amSe9DqfQGVqRo4t+ZXxlKLQkOOKaz95HTGl6nIGzSiemsgOnIBZgeSRNvmsr\n' + st.secrets["private_key8"] + '\nd63heAd+1G8uglvyvk/ikTQnrwKBgQDL5IrUuqG+5HFyLRbX3Nhg/WM23Z7xGb1G\nDAr3sqxAJqz8sN1p5PmIHp4k6UYO46XpSR6ZP+S3IsFDeWmbp+1kEB3wyaYsoVHs\n' + st.secrets["private_key9"] + '\nM7lqFXaXqQKBgG3uesahQbbXcBY5zV2Fkwo2kNuBh9UgGNwexfus9G8F8m+B1WXE\n34d0wvgrJa0VeNqE1XC53lyPP/ZsKROzvW8XDUeebno2VOC95+RMzX7pmx5jdJaf\n' + st.secrets["private_key10"] + '\ndDLO7EHwEBWPDWIoulDT0X7GfRmGKYWrCxVjW5HEW9xhvkw5zuhiiPpE5sWXMqp3\n' + st.secrets["private_key11"] + '\nrws8MdFBKPxuRvP85O1BcdIZEKwt9Zx/nCWAx5eZAoGAeoOy8MD0EiXscQUYEN7E\n' + st.secrets["private_key12"] + '\n8zZ8vE6s+0Gj5P2fd2LrbMtJy6x/s6TwCcgIdfCycUC4GjVqHe3GdJ687AfhxoH1\n' + st.secrets["private_key5"] + '\n-----END PRIVATE KEY-----\n',
|
| 300 |
+
'client_email': st.secrets["client_email"],
|
| 301 |
+
'client_id': st.secrets["client_id"],
|
| 302 |
+
'auth_uri': st.secrets["auth_uri"],
|
| 303 |
+
'token_uri': st.secrets["token_uri"],
|
| 304 |
+
'auth_provider_x509_cert_url': st.secrets["auth_provider_x509_cert_url"],
|
| 305 |
+
'client_x509_cert_url': st.secrets["client_x509_cert_url"]}
|
|
|
|
|
|
|
|
|
|
| 306 |
|
| 307 |
scope = ['https://www.googleapis.com/auth/spreadsheets',
|
| 308 |
"https://www.googleapis.com/auth/drive"]
|
| 309 |
|
| 310 |
+
|
| 311 |
+
credentials = ServiceAccountCredentials.from_json_keyfile_dict(loaded_r, scope)
|
| 312 |
+
client = gspread.authorize(credentials)
|
|
|
|
| 313 |
|
| 314 |
+
sheet = client.open("PropertyPricePredictor_Sheet").sheet1
|
| 315 |
+
sheet.append_row([datetime.now().strftime('%Y-%m-%d %H:%M:%S'), int(input_postal),input_storey,input_age_asof_transaction,input_floor_area_sqft,input_propertyType])
|
|
|
|
|
|