Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import hopsworks
|
3 |
+
import joblib
|
4 |
+
import pandas as pd
|
5 |
+
import numpy as np
|
6 |
+
import json
|
7 |
+
import time
|
8 |
+
from datetime import timedelta, datetime
|
9 |
+
|
10 |
+
|
11 |
+
from functions import *
|
12 |
+
|
13 |
+
|
14 |
+
project = hopsworks.login()
|
15 |
+
fs = project.get_feature_store()
|
16 |
+
|
17 |
+
|
18 |
+
def air_quality(city):
|
19 |
+
weather_df = pd.DataFrame()
|
20 |
+
for i in range(8):
|
21 |
+
weather_data = get_weather_df([get_weather_data((datetime.now() + timedelta(days=i)).strftime("%Y-%m-%d"))])
|
22 |
+
weather_df = weather_df.append(weather_data)
|
23 |
+
|
24 |
+
weather_df = weather_df.drop(columns=["feelslikemin", "feelslikemax", "precipprob", "snowdepth", "uvindex", "date","city","conditions"]).fillna(0)
|
25 |
+
|
26 |
+
mr = project.get_model_registry()
|
27 |
+
model = mr.get_model("gradient_boost_model", version=1)
|
28 |
+
model_dir = model.download()
|
29 |
+
model = joblib.load(model_dir + "/model.pkl")
|
30 |
+
|
31 |
+
preds = model.predict(weather_df)
|
32 |
+
|
33 |
+
predictions = ''
|
34 |
+
for k in range(7):
|
35 |
+
predictions += "Predicted AQI on " + (datetime.now() + timedelta(days=k)).strftime('%Y-%m-%d') + ": " + str(int(preds[k]))+"\n"
|
36 |
+
|
37 |
+
print(predictions)
|
38 |
+
return predictions
|
39 |
+
|
40 |
+
|
41 |
+
demo = gr.Interface(fn=air_quality, title="Air quality predictor",
|
42 |
+
description="Input a value to get next weeks AQI prediction for Malmo", inputs="text", outputs="text")
|
43 |
+
|
44 |
+
|
45 |
+
|
46 |
+
if __name__ == "__main__":
|
47 |
+
demo.launch()
|