kk90ujhun commited on
Commit
99b188c
·
1 Parent(s): 4e187bb

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -0
app.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import hopsworks
3
+ import joblib
4
+ import pandas as pd
5
+ import numpy as np
6
+ import folium
7
+ from streamlit_folium import st_folium, folium_static
8
+ import json
9
+ import time
10
+ from datetime import timedelta, datetime
11
+ from branca.element import Figure
12
+ import gradio as gr
13
+
14
+ from functions import decode_features, get_model, get_weather_df, get_weather_data
15
+
16
+
17
+ project = hopsworks.login()
18
+ fs = project.get_feature_store()
19
+ feature_view = fs.get_feature_view(
20
+ name = 'oslo_air_quality_fv',
21
+ version = 1
22
+ )
23
+
24
+ model = get_model(project=project,
25
+ model_name="air_quality_model",
26
+ evaluation_metric="f1_score",
27
+ sort_metrics_by="max")
28
+
29
+
30
+ def pred(name):
31
+ str1 = " "
32
+ for i in range(8):
33
+ target_date = datetime.today() + timedelta(days=i)
34
+ target_date = target_date.strftime('%Y-%m-%d')
35
+
36
+ data_weather = [get_weather_data('oslo',target_date)]
37
+ df_weather = get_weather_df(data_weather)
38
+ df_weather['conditions'] = df_weather['conditions'].replace(['Rain','Clear','Snow','Partially cloudy','Overcast','Snow, Partially cloudy',
39
+ 'Rain, Partially cloudy','Rain, Overcast','Snow, Overcast',
40
+ 'Snow, Freezing Drizzle/Freezing Rain, Overcast','Snow, Rain',
41
+ 'Snow, Rain, Freezing Drizzle/Freezing Rain, Ice, Overcast',
42
+ 'Snow, Rain, Freezing Drizzle/Freezing Rain, Overcast','Snow, Rain, Ice, Overcast',
43
+ 'Snow, Rain, Overcast','Snow, Rain, Partially cloudy'],[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15])
44
+ df_weather = df_weather.drop(columns=["date"]).fillna(0)
45
+ df_weather["aqi"] = 0
46
+ preds = model.predict(df_weather)
47
+ print(preds)
48
+ if(i!=0):
49
+ str1 += target_date + " predicted aqi:" + str(int(preds))+"\n"
50
+
51
+ return str1
52
+
53
+
54
+ # next_day_date = datetime.today() + timedelta(days=i)
55
+ # next_day = next_day_date.strftime ('%d/%m/%Y')
56
+
57
+ demo = gr.Interface(fn=pred,title="Predict AQI of Oslo" ,inputs="text", outputs="text")
58
+
59
+ if __name__ == "__main__":
60
+ demo.launch()