Campfireman commited on
Commit
ac158aa
1 Parent(s): 067618e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -13
app.py CHANGED
@@ -9,9 +9,9 @@ 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()
@@ -22,39 +22,62 @@ def greet(name):
22
  )
23
 
24
  # The latest available data timestamp
25
- start_time = 1670972400000
 
26
  #start_date = datetime.now() - timedelta(days=1)
27
  #start_time = int(start_date.timestamp()) * 1000
28
 
29
 
30
  X = feature_view.get_batch_data(start_time=start_time)
31
- latest_date_unix = str(X.date.values[0])[:10]
32
  latest_date = time.ctime(int(latest_date_unix))
33
- print(X)
34
-
35
  model = get_model(project=project,
36
  model_name="temp_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
  str1 = ""
47
-
48
-
49
- for x in range(8):
50
- if(x != 0):
51
- str1 += (datetime.now() + timedelta(days=x)).strftime('%Y-%m-%d') + " predicted temperature: " + str(int(preds[len(preds) - 8 + x]))+"\n"
52
 
53
- print(str1)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  return str1
55
 
56
 
57
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
58
 
59
 
60
 
 
9
  from datetime import timedelta, datetime
10
  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()
17
  #api = project.get_dataset_api()
 
22
  )
23
 
24
  # The latest available data timestamp
25
+ start_time = 1635112800000
26
+
27
  #start_date = datetime.now() - timedelta(days=1)
28
  #start_time = int(start_date.timestamp()) * 1000
29
 
30
 
31
  X = feature_view.get_batch_data(start_time=start_time)
32
+ latest_date_unix = str(X.datetime.values[0])[:10]
33
  latest_date = time.ctime(int(latest_date_unix))
 
 
34
  model = get_model(project=project,
35
  model_name="temp_model",
36
  evaluation_metric="f1_score",
37
  sort_metrics_by="max")
38
+ model1 = get_model1(project=project,
39
+ model_name="tempmax_model",
40
+ evaluation_metric="f1_score",
41
+ sort_metrics_by="max")
42
+ model2 = get_model2(project=project,
43
+ model_name="tempmin_model",
44
+ evaluation_metric="f1_score",
45
+ sort_metrics_by="max")
46
+ X = X.drop(columns=["datetime"]).fillna(0)
47
 
48
  preds = model.predict(X)
49
+
50
+ preds1= model1.predict(X)
51
+
52
+ preds2= model2.predict(X)
53
+
54
 
55
  # cities = [city_tuple[0] for city_tuple in cities_coords.keys()]
56
 
57
  next_day_date = datetime.today() + timedelta(days=1)
58
  next_day = next_day_date.strftime ('%d/%m/%Y')
59
  str1 = ""
 
 
 
 
 
60
 
61
+ if(total_pred_days == ""):
62
+ return "Empty input"
63
+
64
+ count = int(total_pred_days)
65
+ if count > 20:
66
+ str1 += "Warning: 20 days at most. " + '\n'
67
+ count = 20
68
+ if count <0:
69
+ str1 = "Invalid input."
70
+ return str1
71
+
72
+ for x in range(count):
73
+ if (x != 0):
74
+ 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"
75
+
76
+ #print(str1)
77
  return str1
78
 
79
 
80
+ demo = gr.Interface(fn=greet, inputs = "text", outputs="text")
81
 
82
 
83