|
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() |