Update app.py
Browse files
app.py
CHANGED
@@ -16,7 +16,8 @@ province_dict = {
|
|
16 |
'Samut Songkhram':'สมุทรสงคราม'
|
17 |
}
|
18 |
|
19 |
-
|
|
|
20 |
|
21 |
def weather_forcast(year,month,date):
|
22 |
_date = pd.to_datetime(f'{year}-{month}-{date}')
|
@@ -24,28 +25,30 @@ def weather_forcast(year,month,date):
|
|
24 |
_df = pd.DataFrame({'ds':[_date]})
|
25 |
|
26 |
_prediction = _model.predict(_df)
|
27 |
-
_prediction = _prediction['yhat']
|
28 |
|
29 |
_israin = False if(_prediction<0.5) else True
|
30 |
return _israin
|
31 |
|
32 |
def get_advice(province,activity,purpose,year,month,date):
|
33 |
_province = province_dict[province]
|
34 |
-
|
35 |
-
|
36 |
-
_purpose = purpose.lower()
|
37 |
_day = pd.to_datetime(f'{year}-{month}-{date}').day_name()
|
38 |
_activity = 'indoor' if(weather_forcast(year,month,date)) else activity.lower()
|
39 |
|
40 |
_places = pd.read_csv('Places.csv')
|
41 |
-
_places = _places[_places['
|
42 |
_places = _places[_places['indoor/outdoor']==_activity]
|
43 |
_places = _places[_places['หมวดหมู่']==_purpose]
|
44 |
_places = _places[_places['ปิดวัน']!=_day]
|
45 |
|
46 |
random_idx = random.randrange(0,len(_places))
|
47 |
-
|
48 |
-
|
|
|
|
|
|
|
49 |
|
50 |
|
51 |
|
@@ -79,13 +82,16 @@ iface = gr.Interface(
|
|
79 |
|
80 |
],
|
81 |
|
82 |
-
outputs=[
|
83 |
-
|
84 |
-
|
|
|
|
|
|
|
85 |
live=True,
|
86 |
-
title="
|
87 |
-
description="Get the weather forecast for a
|
88 |
theme="default",
|
89 |
)
|
90 |
|
91 |
-
iface.launch()
|
|
|
16 |
'Samut Songkhram':'สมุทรสงคราม'
|
17 |
}
|
18 |
|
19 |
+
with open('prophet_model.json', 'r') as fin:
|
20 |
+
_model = model_from_json(json.load(fin))
|
21 |
|
22 |
def weather_forcast(year,month,date):
|
23 |
_date = pd.to_datetime(f'{year}-{month}-{date}')
|
|
|
25 |
_df = pd.DataFrame({'ds':[_date]})
|
26 |
|
27 |
_prediction = _model.predict(_df)
|
28 |
+
_prediction = float(_prediction['yhat'])
|
29 |
|
30 |
_israin = False if(_prediction<0.5) else True
|
31 |
return _israin
|
32 |
|
33 |
def get_advice(province,activity,purpose,year,month,date):
|
34 |
_province = province_dict[province]
|
35 |
+
|
36 |
+
_purpose = str(purpose).lower()
|
|
|
37 |
_day = pd.to_datetime(f'{year}-{month}-{date}').day_name()
|
38 |
_activity = 'indoor' if(weather_forcast(year,month,date)) else activity.lower()
|
39 |
|
40 |
_places = pd.read_csv('Places.csv')
|
41 |
+
_places = _places[_places['จังหวัด']==_province]
|
42 |
_places = _places[_places['indoor/outdoor']==_activity]
|
43 |
_places = _places[_places['หมวดหมู่']==_purpose]
|
44 |
_places = _places[_places['ปิดวัน']!=_day]
|
45 |
|
46 |
random_idx = random.randrange(0,len(_places))
|
47 |
+
_advice = f'It might rain on {year}-{month}-{date} so we suggest you to go indoor place such as...' if(weather_forcast(year,month,date)) else f'It might not rain on {year}-{month}-{date} so we suggest you to go to place such as...'
|
48 |
+
_place_name = _places['ที่เที่ยว'][random_idx]
|
49 |
+
_place_close = _places['ปิดวัน'][random_idx]
|
50 |
+
_place_hour = _places['เวลา'][random_idx]
|
51 |
+
return _advice,_place_name,_place_close,_place_hour
|
52 |
|
53 |
|
54 |
|
|
|
82 |
|
83 |
],
|
84 |
|
85 |
+
outputs=[
|
86 |
+
gr.components.Textbox(label='Advice :'),
|
87 |
+
gr.components.Textbox(label="Place Name :"),
|
88 |
+
gr.components.Textbox(label="Close day :"),
|
89 |
+
gr.components.Textbox(label="Open hour :")
|
90 |
+
],
|
91 |
live=True,
|
92 |
+
title="Right place , Right day",
|
93 |
+
description="Get the weather forecast for a place you would like to go.",
|
94 |
theme="default",
|
95 |
)
|
96 |
|
97 |
+
iface.launch(share=True)
|