File size: 4,949 Bytes
b538e2a
ee8d781
b538e2a
 
6ead712
b538e2a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1401cb7
d34e24d
b538e2a
d34e24d
 
 
 
 
 
ee8d781
 
1a1dab4
ee8d781
 
 
 
 
 
 
b538e2a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64028ba
b538e2a
 
 
 
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import gradio as gr
#from backports.zoneinfo import ZoneInfo
from datetime import datetime, timedelta, timezone
import pickle
import sklearn
weathers = ['Broken clouds ',
 'Clear ',
 'Cloudy ',
 'Cool ',
 'Dense fog ',
 'Drizzle  Broken clouds ',
 'Drizzle  Dense fog ',
 'Drizzle  Fog ',
 'Drizzle  More clouds than sun ',
 'Drizzle  Mostly cloudy ',
 'Drizzle  Overcast ',
 'Drizzle  Partly sunny ',
 'Duststorm ',
 'Extremely hot ',
 'Fog ',
 'Hail  Cloudy ',
 'Hail  Partly sunny ',
 'Hail  Passing clouds ',
 'Haze ',
 'Heavy rain  More clouds than sun ',
 'Heavy rain  Mostly cloudy ',
 'Heavy rain  Overcast ',
 'Heavy rain  Partly sunny ',
 'Hot ',
 'Light rain  Broken clouds ',
 'Light rain  Fog ',
 'Light rain  More clouds than sun ',
 'Light rain  Mostly cloudy ',
 'Light rain  Overcast ',
 'Light rain  Partly cloudy ',
 'Light rain  Partly sunny ',
 'Light rain  Passing clouds ',
 'Light rain  Scattered clouds ',
 'Low level haze ',
 'Mild ',
 'More clouds than sun ',
 'Mostly cloudy ',
 'Overcast ',
 'Partly cloudy ',
 'Partly sunny ',
 'Passing clouds ',
 'Pleasantly warm ',
 'Rain  Broken clouds ',
 'Rain  Clear ',
 'Rain  Fog ',
 'Rain  More clouds than sun ',
 'Rain  Mostly cloudy ',
 'Rain  Overcast ',
 'Rain  Partly cloudy ',
 'Rain  Partly sunny ',
 'Rain  Passing clouds ',
 'Rain  Sandstorm ',
 'Rain  Scattered clouds ',
 'Rain showers  Partly sunny ',
 'Refreshingly cool ',
 'Sandstorm ',
 'Scattered clouds ',
 'Smoke ',
 'Sprinkles  Cloudy ',
 'Sprinkles  Duststorm ',
 'Sprinkles  Low level haze ',
 'Sprinkles  Overcast ',
 'Strong thunderstorms  Cloudy ',
 'Strong thunderstorms  More clouds than sun ',
 'Strong thunderstorms  Partly sunny ',
 'Sunny ',
 'Thundershowers  Partly sunny ',
 'Thundershowers  Passing clouds ',
 'Thundershowers  Scattered clouds ',
 'Thunderstorms  Broken clouds ',
 'Thunderstorms  Cloudy ',
 'Thunderstorms  Fog ',
 'Thunderstorms  More clouds than sun ',
 'Thunderstorms  Mostly cloudy ',
 'Thunderstorms  Overcast ',
 'Thunderstorms  Partly cloudy ',
 'Thunderstorms  Partly sunny ',
 'Thunderstorms  Passing clouds ',
 'Thunderstorms  Sandstorm ',
 'Thunderstorms  Scattered clouds ',
 'Warm ']

months = ['January', 'February', 'March', 'April', 'May', 'June', 'July','August', 'September', 'October', 'November', 'December']

cities = ['Assir',
 'Baha',
 'EP',
 'Hail',
 'Jawf',
 'Jazan',
 'Madina',
 'Mecca',
 'Najran',
 'Northern boarder',
 'Qassim',
 'Riyadh',
 'Tabuk']

def predict(city,month,year,day,hour,minute,weathertype,wind,hu,baro,vis):
  
  loaded_model = pickle.load(open("WeatherPredictionKSA.pk", 'rb'))
  details = [cities.index(city),year,months.index(month),day,hour,minute,weathers.index(weathertype),wind,hu,baro,vis]
  temp = int(loaded_model.predict([details]))
  if temp >= 50:
    emoji = "🥵"
  elif 40 <= temp <= 49:
    emoji = "😳"
  elif 25 <= temp <= 39:
    emoji = "😌"
  elif 10 <= temp <= 24:
    emoji = "😊"
  elif temp <= 9:
    emoji = "🥶"
  return gr.Textbox.update("🌡️ {0} C {1}🌡️".format(temp,emoji))
 
with gr.Blocks() as demo:
  currentSecond= datetime.now().second
  currentMinute = datetime.now().minute
  currentHour = datetime.now().hour
  currentDay = datetime.now().day
  currentMonth = datetime.now().month
  currentYear = datetime.now().year
  #dt = datetime(currentYear, currentMonth, currentDay, tzinfo=ZoneInfo("Asia/Riyadh"))
  #fulltime = str(dt)
  ADD = 0
  # try:
  #   if "+" in fulltime:
  #     ADD = int(fulltime.split("+")[1].split(":")[0])
  #   elif "-" in fulltime:
  #     ADD = int(fulltime.split("-")[1].split(":")[0]) * -1
  # except:
  #   pass
  with gr.Row():
    gr.Markdown("# 🌧️☁️☀️KSA Weather prediction ☀️☁️🌧️\n**Day, Hour, and Minute** are set to **Asia/Riyadh** current time by default but can be changed")
  with gr.Box():
    with gr.Row():
      city = gr.Dropdown(cities,label='City',value='Assir',interactive=True)
      month = gr.Dropdown(months,label='Month',value=months[currentMonth-1],interactive=True)
    with gr.Row():
      year = gr.Number(int(currentYear),label='Year',interactive=True)
      day = gr.Number(int(currentDay),label='Day',interactive=True)
      hour = gr.Number(int(currentHour)+ADD,label='Hour',interactive=True)
      minute = gr.Number(int(currentMinute),label='Minute',interactive=True)
    with gr.Row():
      weathertype = gr.Dropdown(weathers,label='Weather type',value='Cloudy ',interactive=True)
      wind = gr.Number(label='Wind',interactive=True)
      hu = gr.Number(label='Humidity',interactive=True)
      baro = gr.Number(label='Barometer',interactive=True)
      vis = gr.Number(label='Visibility',interactive=True)
    with gr.Row():
      temp = gr.Textbox("😊😌Awaiting input😳🥵",label='Predicted temp',interactive=False)
  btn = gr.Button(value="Predict")
  btn.click(predict, inputs=[city,month,year,day,hour,minute,weathertype,wind,hu,baro,vis], outputs=temp)

demo.launch()