kk90ujhun's picture
Update app.py
44f6dab
raw
history blame
2.36 kB
import streamlit as st
import hopsworks
import joblib
import pandas as pd
import numpy as np
import folium
from streamlit_folium import st_folium, folium_static
import json
import time
from datetime import timedelta, datetime
from branca.element import Figure
import gradio as gr
from functions import decode_features, get_model, get_weather_df, get_weather_data
project = hopsworks.login()
fs = project.get_feature_store()
feature_view = fs.get_feature_view(
name = 'oslo_air_quality_fv',
version = 1
)
model = get_model(project=project,
model_name="air_quality_model",
evaluation_metric="f1_score",
sort_metrics_by="max",
version_name=3)
def pred(name):
str1 = " "
for i in range(8):
target_date = datetime.today() + timedelta(days=i)
target_date = target_date.strftime('%Y-%m-%d')
data_weather = [get_weather_data('oslo',target_date)]
df_weather = get_weather_df(data_weather)
df_weather['conditions'] = df_weather['conditions'].replace(['Rain','Clear','Snow','Partially cloudy','Overcast','Snow, Partially cloudy',
'Rain, Partially cloudy','Rain, Overcast','Snow, Overcast',
'Snow, Freezing Drizzle/Freezing Rain, Overcast','Snow, Rain',
'Snow, Rain, Freezing Drizzle/Freezing Rain, Ice, Overcast',
'Snow, Rain, Freezing Drizzle/Freezing Rain, Overcast','Snow, Rain, Ice, Overcast',
'Snow, Rain, Overcast','Snow, Rain, Partially cloudy'],[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15])
df_weather = df_weather.drop(columns=["date"]).fillna(0)
df_weather["aqi"] = 0
preds = model.predict(df_weather)
print(preds)
if(i!=0):
str1 += target_date + " predicted aqi:" + str(int(preds))+"\n"
return str1
# next_day_date = datetime.today() + timedelta(days=i)
# next_day = next_day_date.strftime ('%d/%m/%Y')
demo = gr.Interface(fn=pred,title="Predict AQI of Oslo" ,inputs="text", outputs="text")
if __name__ == "__main__":
demo.launch()