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