Campfireman commited on
Commit
d47d510
1 Parent(s): 9e5f3ef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +78 -1
app.py CHANGED
@@ -11,6 +11,81 @@ from branca.element import Figure
11
 
12
  from functions import decode_features, get_model, get_model1, get_model2
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  def greet(total_pred_days):
15
 
16
  project = hopsworks.login()
@@ -86,4 +161,6 @@ demo = gr.Interface(
86
 
87
 
88
  if __name__ == "__main__":
89
- demo.launch()
 
 
 
11
 
12
  from functions import decode_features, get_model, get_model1, get_model2
13
 
14
+
15
+ def greet(total_pred_days):
16
+
17
+ project = hopsworks.login()
18
+ #api = project.get_dataset_api()
19
+ fs = project.get_feature_store()
20
+ feature_view = fs.get_feature_view(
21
+ name = 'weather_fv',
22
+ version = 1
23
+ )
24
+
25
+ # The latest available data timestamp
26
+ start_time = 1635112800000
27
+
28
+ #start_date = datetime.now() - timedelta(days=1)
29
+ #start_time = int(start_date.timestamp()) * 1000
30
+
31
+
32
+ X = feature_view.get_batch_data(start_time=start_time)
33
+ latest_date_unix = str(X.datetime.values[0])[:10]
34
+ latest_date = time.ctime(int(latest_date_unix))
35
+ model = get_model(project=project,
36
+ model_name="temp_model",
37
+ evaluation_metric="f1_score",
38
+ sort_metrics_by="max")
39
+ model1 = get_model1(project=project,
40
+ model_name="tempmax_model",
41
+ evaluation_metric="f1_score",
42
+ sort_metrics_by="max")
43
+ model2 = get_model2(project=project,
44
+ model_name="tempmin_model",
45
+ evaluation_metric="f1_score",
46
+ sort_metrics_by="max")
47
+ X = X.drop(columns=["datetime"]).fillna(0)
48
+
49
+ preds = model.predict(X)
50
+
51
+ preds1= model1.predict(X)
52
+
53
+ preds2= model2.predict(X)
54
+
55
+
56
+ # cities = [city_tuple[0] for city_tuple in cities_coords.keys()]
57
+
58
+ next_day_date = datetime.today() + timedelta(days=1)
59
+ next_day = next_day_date.strftime ('%d/%m/%Y')
60
+ str1 = ""
61
+
62
+ if(total_pred_days == ""):
63
+ return "Empty input"
64
+
65
+ count = int(total_pred_days)
66
+ if count > 20:
67
+ str1 += "Warning: 20 days at most. " + '\n'
68
+ count = 20
69
+ if count <0:
70
+ str1 = "Invalid input."
71
+ return str1
72
+
73
+ for x in range(count):
74
+ if (x != 0):
75
+ str1 += (datetime.now() + timedelta(days=x)).strftime('%Y-%m-%d') + " predicted temperature: " +str(int(preds[len(preds) - count + x]))+ " predicted max temperature: " +str(int(preds1[len(preds1) - count + x]))+ " predicted min temperature: " +str(int(preds2[len(preds2) - count + x]))+"\n"
76
+
77
+ #print(str1)
78
+ return str1
79
+
80
+
81
+ demo = gr.Interface(fn=greet, inputs = "text", outputs="text")
82
+
83
+
84
+
85
+ if __name__ == "__main__":
86
+ demo.launch()
87
+
88
+ '''
89
  def greet(total_pred_days):
90
 
91
  project = hopsworks.login()
 
161
 
162
 
163
  if __name__ == "__main__":
164
+ demo.launch()
165
+
166
+ '''