predict_weather / app.py
matheuscvp
update
e702b56
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()