Mustafa Al Hamad commited on
Commit
b538e2a
1 Parent(s): ba57008

Create new file

Browse files
Files changed (1) hide show
  1. app.py +160 -0
app.py ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from backports.zoneinfo import ZoneInfo
3
+ from datetime import datetime, timedelta, timezone
4
+ import pickle
5
+ weathers = ['Broken clouds ',
6
+ 'Clear ',
7
+ 'Cloudy ',
8
+ 'Cool ',
9
+ 'Dense fog ',
10
+ 'Drizzle Broken clouds ',
11
+ 'Drizzle Dense fog ',
12
+ 'Drizzle Fog ',
13
+ 'Drizzle More clouds than sun ',
14
+ 'Drizzle Mostly cloudy ',
15
+ 'Drizzle Overcast ',
16
+ 'Drizzle Partly sunny ',
17
+ 'Duststorm ',
18
+ 'Extremely hot ',
19
+ 'Fog ',
20
+ 'Hail Cloudy ',
21
+ 'Hail Partly sunny ',
22
+ 'Hail Passing clouds ',
23
+ 'Haze ',
24
+ 'Heavy rain More clouds than sun ',
25
+ 'Heavy rain Mostly cloudy ',
26
+ 'Heavy rain Overcast ',
27
+ 'Heavy rain Partly sunny ',
28
+ 'Hot ',
29
+ 'Light rain Broken clouds ',
30
+ 'Light rain Fog ',
31
+ 'Light rain More clouds than sun ',
32
+ 'Light rain Mostly cloudy ',
33
+ 'Light rain Overcast ',
34
+ 'Light rain Partly cloudy ',
35
+ 'Light rain Partly sunny ',
36
+ 'Light rain Passing clouds ',
37
+ 'Light rain Scattered clouds ',
38
+ 'Low level haze ',
39
+ 'Mild ',
40
+ 'More clouds than sun ',
41
+ 'Mostly cloudy ',
42
+ 'Overcast ',
43
+ 'Partly cloudy ',
44
+ 'Partly sunny ',
45
+ 'Passing clouds ',
46
+ 'Pleasantly warm ',
47
+ 'Rain Broken clouds ',
48
+ 'Rain Clear ',
49
+ 'Rain Fog ',
50
+ 'Rain More clouds than sun ',
51
+ 'Rain Mostly cloudy ',
52
+ 'Rain Overcast ',
53
+ 'Rain Partly cloudy ',
54
+ 'Rain Partly sunny ',
55
+ 'Rain Passing clouds ',
56
+ 'Rain Sandstorm ',
57
+ 'Rain Scattered clouds ',
58
+ 'Rain showers Partly sunny ',
59
+ 'Refreshingly cool ',
60
+ 'Sandstorm ',
61
+ 'Scattered clouds ',
62
+ 'Smoke ',
63
+ 'Sprinkles Cloudy ',
64
+ 'Sprinkles Duststorm ',
65
+ 'Sprinkles Low level haze ',
66
+ 'Sprinkles Overcast ',
67
+ 'Strong thunderstorms Cloudy ',
68
+ 'Strong thunderstorms More clouds than sun ',
69
+ 'Strong thunderstorms Partly sunny ',
70
+ 'Sunny ',
71
+ 'Thundershowers Partly sunny ',
72
+ 'Thundershowers Passing clouds ',
73
+ 'Thundershowers Scattered clouds ',
74
+ 'Thunderstorms Broken clouds ',
75
+ 'Thunderstorms Cloudy ',
76
+ 'Thunderstorms Fog ',
77
+ 'Thunderstorms More clouds than sun ',
78
+ 'Thunderstorms Mostly cloudy ',
79
+ 'Thunderstorms Overcast ',
80
+ 'Thunderstorms Partly cloudy ',
81
+ 'Thunderstorms Partly sunny ',
82
+ 'Thunderstorms Passing clouds ',
83
+ 'Thunderstorms Sandstorm ',
84
+ 'Thunderstorms Scattered clouds ',
85
+ 'Warm ']
86
+
87
+ months = ['January', 'February', 'March', 'April', 'May', 'June', 'July','August', 'September', 'October', 'November', 'December']
88
+
89
+ cities = ['Assir',
90
+ 'Baha',
91
+ 'EP',
92
+ 'Hail',
93
+ 'Jawf',
94
+ 'Jazan',
95
+ 'Madina',
96
+ 'Mecca',
97
+ 'Najran',
98
+ 'Northern boarder',
99
+ 'Qassim',
100
+ 'Riyadh',
101
+ 'Tabuk']
102
+
103
+ currentSecond= datetime.now().second
104
+ currentMinute = datetime.now().minute
105
+ currentHour = datetime.now().hour
106
+ currentDay = datetime.now().day
107
+ currentMonth = datetime.now().month
108
+ currentYear = datetime.now().year
109
+
110
+ dt = datetime(currentYear, currentMonth, currentDay, tzinfo=ZoneInfo("Asia/Riyadh"))
111
+ fulltime = str(dt)
112
+ ADD = 0
113
+ try:
114
+ if "+" in fulltime:
115
+ ADD = int(fulltime.split("+")[1].split(":")[0])
116
+ elif "-" in fulltime:
117
+ ADD = int(fulltime.split("-")[1].split(":")[0]) * -1
118
+ except:
119
+ pass
120
+
121
+ def predict(city,month,year,day,hour,minute,weathertype,wind,hu,baro,vis):
122
+
123
+ loaded_model = pickle.load(open("WeatherPredictionKSA.pk", 'rb'))
124
+ details = [cities.index(city),year,months.index(month),day,hour,minute,weathers.index(weathertype),wind,hu,baro,vis]
125
+ temp = int(loaded_model.predict([details]))
126
+ if temp >= 50:
127
+ emoji = "🥵"
128
+ elif 40 <= temp <= 49:
129
+ emoji = "😳"
130
+ elif 25 <= temp <= 39:
131
+ emoji = "😌"
132
+ elif 10 <= temp <= 24:
133
+ emoji = "😊"
134
+ elif temp <= 9:
135
+ emoji = "🥶"
136
+ return gr.Markdown.update("# 🌡️ {0} C {1}🌡️".format(temp,emoji))
137
+ with gr.Blocks() as demo:
138
+ with gr.Row():
139
+ gr.Markdown("# 🌧️☁️☀️KSA Weather prediction ☀️☁️🌧️\n**Day, Hour, and Minute** are set to **Asia/Riyadh** current time by default but can be changed")
140
+ with gr.Box():
141
+ with gr.Row():
142
+ city = gr.Dropdown(cities,label='City',value='Assir',interactive=True)
143
+ month = gr.Dropdown(months,label='Month',value=months[currentMonth-1],interactive=True)
144
+ with gr.Row():
145
+ year = gr.Number(int(currentYear),label='Year',interactive=True)
146
+ day = gr.Number(int(currentDay),label='Day',interactive=True)
147
+ hour = gr.Number(int(currentHour)+ADD,label='Hour',interactive=True)
148
+ minute = gr.Number(int(currentMinute),label='Minute',interactive=True)
149
+ with gr.Row():
150
+ weathertype = gr.Dropdown(weathers,label='Weather type',value='Cloudy ',interactive=True)
151
+ wind = gr.Number(label='Wind',interactive=True)
152
+ hu = gr.Number(label='Humidity',interactive=True)
153
+ baro = gr.Number(label='Barometer',interactive=True)
154
+ vis = gr.Number(label='Visibility',interactive=True)
155
+ with gr.Row():
156
+ temp = gr.Markdown("")
157
+ btn = gr.Button(value="Predict")
158
+ btn.click(predict, inputs=[city,month,year,day,hour,minute,weathertype,wind,hu,baro,vis], outputs=temp)
159
+
160
+ demo.launch()