Orangefish00 commited on
Commit
3e1025e
1 Parent(s): 67a805d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -0
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import hopsworks
3
+ import joblib
4
+ import pandas as pd
5
+ import numpy as np
6
+ import folium
7
+ import json
8
+ import time
9
+ from datetime import timedelta, datetime
10
+ from branca.element import Figure
11
+
12
+ from functions import decode_features, get_model
13
+
14
+ def greet(name):
15
+
16
+ project = hopsworks.login()
17
+ fs = project.get_feature_store()
18
+ feature_view = fs.get_feature_view(
19
+ name = 'hel_air_fv1',
20
+ version = 1
21
+ )
22
+
23
+ start_time = 1630533600000
24
+
25
+
26
+
27
+ X = feature_view.get_batch_data(start_time=start_time)
28
+ latest_date_unix = str(X.date.values[0])[:10]
29
+ latest_date = time.ctime(int(latest_date_unix))
30
+
31
+ X = X.drop(columns=["date"]).fillna(0)
32
+
33
+
34
+ model = get_model(project=project,
35
+ model_name="gradient_boost_model",
36
+ evaluation_metric="f1_score",
37
+ sort_metrics_by="max")
38
+
39
+ preds = model.predict(X)
40
+
41
+ cities = [city_tuple[0] for city_tuple in cities_coords.keys()]
42
+
43
+ next_day_date = datetime.today() + timedelta(days=1)
44
+ next_day = next_day_date.strftime ('%d/%m/%Y')
45
+ df = pd.DataFrame(data=preds[0], index=cities, columns=[f"AQI Predictions for {next_day}"], dtype=int)
46
+ return df
47
+
48
+
49
+ demo = gr.Interface(fn=greet, inputs="text", outputs="text")
50
+
51
+ if __name__ == "__main__":
52
+ demo.launch()