File size: 2,645 Bytes
82c9f5e
 
 
7128315
519bce2
1be00cd
da69a3c
1be00cd
7128315
1be00cd
 
 
 
 
 
 
 
82aff7d
 
 
1be00cd
 
 
 
 
 
 
82c9f5e
1be00cd
 
82c9f5e
1be00cd
 
 
91c669e
1be00cd
 
 
 
da69a3c
 
 
 
 
 
57ffc1c
82c9f5e
da69a3c
1be00cd
 
82c9f5e
 
49b4712
82c9f5e
 
 
1be00cd
82c9f5e
 
 
 
 
 
 
1be00cd
82c9f5e
 
 
1be00cd
82c9f5e
 
 
 
 
 
 
 
 
 
 
 
b73df29
 
 
82c9f5e
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import gradio as gr
import pandas as pd
import numpy as np
from prophet import Prophet
from mysql import connector
import json
import random
from prophet.serialize import model_from_json

province_dict = {
    "Bangkok":"กรุงเทพฯ",
    'Nakohn Pathom':'นครปฐม',
    'Pathum Thani':'ปทุมธานี',
    'Nakohn Nayok':'นครนายก',
    'Nonthaburi':'นนทบุรี',
    'Samut Songkhram':'สมุทรสงคราม'
}



def weather_forcast(year,month,date):
    _date = pd.to_datetime(f'{year}-{month}-{date}')
        
    _df = pd.DataFrame({'ds':[_date]})

    _prediction = _model.predict(_df)
    _prediction = _prediction['yhat']

    _israin = False if(_prediction<0.5) else True
    return _israin
    
def get_advice(province,activity,purpose,year,month,date):
    _province = province_dict[province]
    with open('prophet_model.json', 'r') as fin:
        _model = model_from_json(json.load(fin))
    _purpose = purpose.lower()
    _day = pd.to_datetime(f'{year}-{month}-{date}').day_name()
    _activity = 'indoor' if(weather_forcast(year,month,date)) else activity.lower()

    _places = pd.read_csv('Places.csv')
    _places = _places[_places['จังหวัก']==_province]
    _places = _places[_places['indoor/outdoor']==_activity]
    _places = _places[_places['หมวดหมู่']==_purpose]
    _places = _places[_places['ปิดวัน']!=_day]

    random_idx = random.randrange(0,len(_places))
    
    return random_idx,random_idx,random_idx



iface = gr.Interface(
    fn = get_advice,
    inputs = [
        
        gr.Dropdown(
            ["Bangkok",'Nakohn Pathom','Pathum Thani','Nakohn Nayok','Nonthaburi','Samut Songkhram'], label="Province", info="Will add more later!"
        ),

        gr.Dropdown(
            ["Indoor","Outdoor"], label="Activity"
        ),

        gr.Dropdown(
            ["Shopping","Relax",'Education','Culture','Nature'], label="Purpose"
        ),

        gr.Dropdown(
            [2024], label="Year", info="Will add more later!"
        ),

        gr.Dropdown(
            [1,2,3,4,5,6,7,8,9,10,11,12], label="Month"
        ),

        gr.Dropdown(
            [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31], label="Date"
        )

    ],
    
    outputs=[gr.components.Textbox(label="Place Name :"),
           gr.components.Textbox(label="Close day :"),
           gr.components.Textbox(label="Open hour :")],
    live=True,
    title="Weather Forecast",
    description="Get the weather forecast for a city.",
    theme="default",
)

iface.launch()