File size: 1,140 Bytes
e702b56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import torch, numpy as np, pandas as pd
import skimage 
import pickle

default_columns = [
  'Wind',
  'Max Temperature',
  'Min Temperature',
  'Precipitation',
]

options = [
  'drizzle',
  'fog',
  'rain',
  'snow',
  'sun',
]

with open("model.pkl", "rb") as f:
  model = pickle.load(f)


def predict(wind, max_temp, min_temp, precipitation):
  f_wind = float(wind)
  f_max_temp = float(max_temp)
  f_min_temp = float(min_temp)
  f_precipitation = float(precipitation)

  default = [
    f_wind,
    f_max_temp,
    f_min_temp,
    f_precipitation,
  ]

  df = pd.DataFrame([default], columns=default_columns)

  prediction = model.predict(df)

  return options[prediction[0]]
  
iface = gr.Interface(
  fn=predict,
  title="Weather Prediction",
  allow_flagging="never",
  inputs=[
    gr.inputs.Slider(0, 100, default=50, label="Wind"),
    gr.inputs.Slider(0, 100, default=50, label="Max Temperature"),
    gr.inputs.Slider(0, 100, default=50, label="Min Temperature"),
    gr.inputs.Slider(0, 100, default=50, label="Precipitation"),
  ],
  outputs=[
    gr.outputs.Label(label="Weather"),
  ],
)

iface.launch()