SebLih commited on
Commit
271428d
·
1 Parent(s): 78b093c

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -0
app.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from datetime import timedelta, datetime
3
+ import hopsworks
4
+ import joblib
5
+ from functions import *
6
+
7
+ #Connect to hopsworks and get feature store
8
+ project = hopsworks.login()
9
+ fs = project.get_feature_store()
10
+
11
+ #Function for the app
12
+ def predict_weather(location):
13
+
14
+ #Get future weather data
15
+ weather_data1 = get_weather_df([get_weather_data(location, (datetime.now() + timedelta(days=1)).strftime("%Y-%m-%d"))])
16
+ weather_data2 = get_weather_df([get_weather_data(location, (datetime.now() + timedelta(days=2)).strftime("%Y-%m-%d"))])
17
+ weather_data3 = get_weather_df([get_weather_data(location, (datetime.now() + timedelta(days=3)).strftime("%Y-%m-%d"))])
18
+ weather_data4 = get_weather_df([get_weather_data(location, (datetime.now() + timedelta(days=4)).strftime("%Y-%m-%d"))])
19
+ weather_data5 = get_weather_df([get_weather_data(location, (datetime.now() + timedelta(days=5)).strftime("%Y-%m-%d"))])
20
+ weather_data6 = get_weather_df([get_weather_data(location, (datetime.now() + timedelta(days=6)).strftime("%Y-%m-%d"))])
21
+ weather_data7 = get_weather_df([get_weather_data(location, (datetime.now() + timedelta(days=7)).strftime("%Y-%m-%d"))])
22
+
23
+ weather_df = pd.concat([weather_data1, weather_data2, weather_data3, weather_data4, weather_data5, weather_data6, weather_data7], axis=0)
24
+
25
+ weather_df = weather_df.drop(columns=["precipprob", "uvindex", "date", "city", "conditions"]).fillna(0)
26
+ weather_df.rename(
27
+ columns={"pressure": "sealevelpressure"}, inplace=True)
28
+ print(weather_df)
29
+
30
+ #Get model
31
+ mr = project.get_model_registry()
32
+ model = mr.get_model("gradient_boost_model5", version=1)
33
+ model_dir = model.download()
34
+ model = joblib.load(model_dir + "/model5.pkl")
35
+
36
+ #Create predictions
37
+ preds = model.predict(weather_df)
38
+ print(preds)
39
+
40
+ list_of_predictions = []
41
+ for x in range(7):
42
+ list_of_predictions.append("Aqi on " + (datetime.now() + timedelta(days=x+1)).strftime('%Y-%m-%d') + ": " + str(int(preds[x])))
43
+
44
+ return list_of_predictions
45
+
46
+ #Gradio interface
47
+ demo = gr.Interface(
48
+ fn=predict_weather,
49
+ title="Future air quality predictor",
50
+ description="Input the name of a location below to get future air quality predictions for that location",
51
+ allow_flagging="never",
52
+ inputs="text",
53
+ outputs="text"
54
+ )
55
+
56
+ demo.launch()