Spaces:
Runtime error
Runtime error
Mustafa Al Hamad commited on
Commit ·
b538e2a
1
Parent(s): ba57008
Create new file
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160import gradio as grfrom backports.zoneinfo import ZoneInfofrom datetime import datetime, timedelta, timezoneimport pickleweathers = ['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']
currentSecond= datetime.now().secondcurrentMinute = datetime.now().minutecurrentHour = datetime.now().hourcurrentDay = datetime.now().daycurrentMonth = datetime.now().monthcurrentYear = datetime.now().year
dt = datetime(currentYear, currentMonth, currentDay, tzinfo=ZoneInfo("Asia/Riyadh"))fulltime = str(dt)ADD = 0try: if "+" in fulltime: ADD = int(fulltime.split("+")[1].split(":")[0]) elif "-" in fulltime: ADD = int(fulltime.split("-")[1].split(":")[0]) * -1except: pass
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.Markdown.update("# 🌡️ {0} C {1}🌡️".format(temp,emoji))with gr.Blocks() as demo: 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.Markdown("") btn = gr.Button(value="Predict") btn.click(predict, inputs=[city,month,year,day,hour,minute,weathertype,wind,hu,baro,vis], outputs=temp)
demo.launch()app.pyAdded+160