Pattr commited on
Commit
c4a845b
·
verified ·
1 Parent(s): 550c94b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -14
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
- with open('prophet_model.json', 'r') as fin:
35
- _model = model_from_json(json.load(fin))
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['จังหวัก']==_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
-
48
- return random_idx,random_idx,random_idx
 
 
 
49
 
50
 
51
 
@@ -79,13 +82,16 @@ iface = gr.Interface(
79
 
80
  ],
81
 
82
- outputs=[gr.components.Textbox(label="Place Name :"),
83
- gr.components.Textbox(label="Close day :"),
84
- gr.components.Textbox(label="Open hour :")],
 
 
 
85
  live=True,
86
- title="Weather Forecast",
87
- description="Get the weather forecast for a city.",
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)