Hathang commited on
Commit
2af085b
·
verified ·
1 Parent(s): d380ea7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +86 -0
app.py CHANGED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import numpy as np
3
+ import Ulity as ult
4
+ import sklearn
5
+
6
+ st.title('HOUSE PRICE PREDICTION APPLICATION')
7
+ vung = st.sidebar.selectbox('Select region',['Việt Nam','Hà Nội','TP Hồ Chí Minh'])
8
+ method = st.sidebar.radio('Select treatment option:',['Alternative 1','Alternative 2(Most Recommended)','Alternative 3','Alternative 4'])
9
+ #Chọn phương án xử lý:',['Phương án 1','Phương án 2','Phương án 3','Phương án 4']
10
+ if vung=='Hà Nội':model = st.sidebar.selectbox("Select regression model",['XGBoost Regression'])
11
+ elif vung=="TP Hồ Chí Minh":
12
+ model = st.sidebar.selectbox("Select regression model",['RandomForest Regression'])
13
+ else:
14
+ model = st.sidebar.selectbox("Select regression model",['Catboost Regression'])
15
+ button = st.sidebar.button('Prediction')
16
+
17
+ col1, col2, col3 = st.columns(3)
18
+ with col1:
19
+ loaibds = st.selectbox('Type of real estate',['Nhà liền kề, biệt thự','Nhà mặt tiền','Nhà trong hẻm'])#Loại bất động sản'
20
+ loaibds_value = ['Nhà liền kề, biệt thự', 'Nhà mặt tiền', 'Nhà trong hẻm'].index(loaibds)
21
+ with col2:
22
+ huong = st.selectbox('The direction of the house',['Bắc','Nam','Tây','Tây Bắc','Tây Nam','Đông','Đông Bắc','Đông Nam'])
23
+ huong_value = ['Bắc','Nam','Tây','Tây Bắc','Tây Nam','Đông','Đông Bắc','Đông Nam'].index(huong)
24
+ with col3:
25
+ phaply = st.selectbox('Juridical',['Không','Có'])
26
+ phaply_value=['Không','Có'].index(phaply)
27
+
28
+ #city=['Hà Nội','Thành phố Hồ Chí Minh','Đà Nẵng','Lâm Đồng','Hải Phòng','Khánh Hòa','Bắc Ninh','Đồng Nai','Cần Thơ','Bà Rịa – Vũng Tàu','Thừa Thiên Huế','Đắk Lắk','Bình Dương']
29
+ #[4,8,7,5,10,6,12,3,2,9,0,11,1]
30
+
31
+ diachi1, diachi2=st.columns(2)
32
+ diachi3,diachi4=st.columns(2)
33
+ with diachi1:
34
+ if vung=='Việt Nam':
35
+ tinhthanhpho = st.selectbox('Province/City', list(ult.city_districts.keys()))
36
+ index_tinhthanhpho = list(ult.city_districts.keys()).index(tinhthanhpho)
37
+ tinhthanhpho_value = [3,7,6,4,8,5,9,2,1,0][index_tinhthanhpho]
38
+ elif vung == "Hà Nội":
39
+ tinhthanhpho = st.selectbox('Province/City',['Hà Nội'])
40
+ tinhthanhpho_value = 4
41
+ else:
42
+ tinhthanhpho = st.selectbox('Province/City', ['TP Hồ Chí Minh'])
43
+ tinhthanhpho_value = 8
44
+
45
+ if tinhthanhpho in ult.city_districts:
46
+ with diachi2:
47
+ quanhuyen = st.selectbox('District', list(ult.city_districts[tinhthanhpho].keys()))
48
+
49
+ if quanhuyen in ult.city_districts[tinhthanhpho]:
50
+ with diachi3:
51
+ xaphuong = st.selectbox('Wards', ult.city_districts[tinhthanhpho][quanhuyen])
52
+ with diachi4:diachi = st.text_input('Street')
53
+
54
+ col4,col5 = st.columns(2)
55
+ with col4:
56
+ matdodanso=ult.Find_Density(quanhuyen,tinhthanhpho)
57
+ matdo=st.number_input('Population density(person/km2)',matdodanso,disabled=True)
58
+ with col5:
59
+ gdp=ult.Find_GDPD(tinhthanhpho)
60
+ grdp=st.number_input('GRPD(%)',gdp,disabled=True)
61
+ col6, col7, col8,col9 = st.columns(4)
62
+ with col6:
63
+ dgtrcnha=st.number_input('Road in front of house(m)',step=1)
64
+ with col7:
65
+ solau=st.number_input('Number of floors',step=1)
66
+ with col8:
67
+ sophgngu=st.number_input('Number of bedroom',step=1)
68
+ with col9:
69
+ dientich=st.number_input('Acreage/Area(m2)',step=1)
70
+
71
+ if button:
72
+ st.snow()
73
+ if dientich!=0 and solau !=0 :
74
+ if method == 'Alternative 1':
75
+ new_record = np.array(
76
+ [dgtrcnha, loaibds_value, phaply_value, solau, sophgngu, dientich, tinhthanhpho_value, matdodanso, grdp])
77
+ sample = new_record.reshape(-1, 9)
78
+ else:
79
+ new_record = np.array(
80
+ [huong_value, dgtrcnha, loaibds_value, phaply_value, solau, sophgngu, dientich, tinhthanhpho_value,
81
+ matdodanso, grdp])
82
+ sample = new_record.reshape(-1, 10)
83
+ predict = ult.Prediction(sample, vung, method, model)
84
+ ult.Show_answer(predict,loaibds_value)
85
+ else:st.warning('You must type into Area and Number of floor!')
86
+