Orangefish commited on
Commit
760d8b7
1 Parent(s): 238a5c0

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -0
app.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 = 1668985200000
24
+ #start_date = datetime.now() - timedelta(days=1)
25
+ #start_time = int(start_date.timestamp()) * 1000
26
+
27
+
28
+ X = feature_view.get_batch_data(start_time=start_time)
29
+ latest_date_unix = str(X.date.values[0])[:10]
30
+ latest_date = time.ctime(int(latest_date_unix))
31
+
32
+ X = X.drop(columns=["date"]).fillna(0)
33
+
34
+
35
+ model = get_model(project=project,
36
+ model_name="gradient_boost_model",
37
+ evaluation_metric="f1_score",
38
+ sort_metrics_by="max")
39
+
40
+ preds = model.predict(X)
41
+
42
+ # cities = [city_tuple[0] for city_tuple in cities_coords.keys()]
43
+
44
+ next_day_date = datetime.today() + timedelta(days=1)
45
+ next_day = next_day_date.strftime ('%d/%m/%Y')
46
+ # df = pd.DataFrame(data=preds[0], columns=[f"AQI Predictions for {next_day}"], dtype=int)
47
+ str1 = ""
48
+ # return int(preds[0])
49
+
50
+
51
+ for x in range(8):
52
+ if(x != 0):
53
+ str1 += (datetime.now() + timedelta(days=x)).strftime('%Y-%m-%d') + " predicted aqi: " + str(int(preds[len(preds) - 8 + x]))+"\n"
54
+
55
+ print(str1)
56
+ return str1
57
+
58
+
59
+ demo = gr.Interface(fn=greet, inputs="text", outputs="text")
60
+
61
+
62
+
63
+ if __name__ == "__main__":
64
+ demo.launch()