Spaces:
Runtime error
Runtime error
File size: 5,068 Bytes
8062140 3fc38c0 8062140 d47d510 6d82468 d47d510 6d82468 d47d510 f2e2963 d47d510 f2e2963 d47d510 c3fc79b d47d510 784a9c4 d47d510 10083a0 d47d510 c52c6cb 3fc38c0 5430a2b 21d542a 6d82468 3fc38c0 5430a2b 21d542a 3fc38c0 5430a2b 21d542a 3fc38c0 10083a0 d47d510 ac158aa 8062140 3ddbf9f ac158aa 3ddbf9f 8062140 ac158aa 8062140 ac158aa 8062140 ac158aa 8062140 ac158aa 8062140 dec008f b67094f dec008f 8062140 d47d510 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
import gradio as gr
import hopsworks
import joblib
import pandas as pd
import numpy as np
import folium
import json
import time
from datetime import timedelta, datetime
from branca.element import Figure
from functions import decode_features
def greet(total_pred_days):
print("hi")
project = hopsworks.login()
print("connected")
#api = project.get_dataset_api()
fs = project.get_feature_store()
print("get the store")
feature_view = fs.get_feature_view(
name = 'weather_fv',
version = 1
)
print("get the fv")
# The latest available data timestamp
start_time = 1635112800000
end_time = 1670972400000
#start_date = datetime.now() - timedelta(days=1)
#start_time = int(start_date.timestamp()) * 1000
print("Time Stamp Set. ")
latest_date_unix = str(X.datetime.values[0])[:10]
latest_date = time.ctime(int(latest_date_unix))
print("latest_date")
model = get_model("temp_model", version=2)
model_dir =model.download()
model =joblib.load(model_dir+"/temp_model.pkl")
print("temp_model is now right")
model1 = get_model("tempmax_model", version=2)
model_dir1 =model1.download()
model1 =joblib.load(model_dir1+"/tempmax_model.pkl")
model2 = get_model("tempmin_model", version=2)
model_dir2 =model2.download()
model2 =joblib.load(model_dir2+"/tempmin_model.pkl")
X = feature_view.get_batch_data(start_time=start_time, end_time=end_time)
print("Data batched")
X = X.drop(columns=["datetime"]).fillna(0)
preds = model.predict(X)
preds1= model1.predict(X)
preds2= model2.predict(X)
# cities = [city_tuple[0] for city_tuple in cities_coords.keys()]
next_day_date = datetime.today() + timedelta(days=1)
next_day = next_day_date.strftime ('%d/%m/%Y')
str1 = ""
if(total_pred_days == ""):
return "Empty input"
count = int(total_pred_days)
if count > 20:
str1 += "Warning: 20 days at most. " + '\n'
count = 20
if count <0:
str1 = "Invalid input."
return str1
for x in range(count):
if (x != 0):
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"
#print(str1)
return str1
demo = gr.Interface(fn=greet, inputs = "text", outputs="text")
if __name__ == "__main__":
demo.launch()
'''
def greet(total_pred_days):
project = hopsworks.login()
#api = project.get_dataset_api()
fs = project.get_feature_store()
feature_view = fs.get_feature_view(
name = 'weather_fv',
version = 1
)
# The latest available data timestamp
start_time = 1635112800000
#start_date = datetime.now() - timedelta(days=1)
#start_time = int(start_date.timestamp()) * 1000
X = feature_view.get_batch_data(start_time=start_time)
latest_date_unix = str(X.datetime.values[0])[:10]
latest_date = time.ctime(int(latest_date_unix))
model = get_model(project=project,
model_name="temp_model",
evaluation_metric="f1_score",
sort_metrics_by="max")
model1 = get_model1(project=project,
model_name="tempmax_model",
evaluation_metric="f1_score",
sort_metrics_by="max")
model2 = get_model2(project=project,
model_name="tempmin_model",
evaluation_metric="f1_score",
sort_metrics_by="max")
X = X.drop(columns=["datetime"]).fillna(0)
preds = model.predict(X)
preds1= model1.predict(X)
preds2= model2.predict(X)
# cities = [city_tuple[0] for city_tuple in cities_coords.keys()]
next_day_date = datetime.today() + timedelta(days=1)
next_day = next_day_date.strftime ('%d/%m/%Y')
str1 = ""
if(total_pred_days == ""):
return "Empty input"
count = int(total_pred_days)
if count > 20:
str1 += "Warning: 20 days at most. " + '\n'
count = 20
if count <0:
str1 = "Invalid input."
return str1
for x in range(count):
if (x != 0):
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"
#print(str1)
return str1
demo = gr.Interface(
fn=greet,
inputs=gr.Slider(label="Days of prediction (start from tomorrow)", value=1, minimum=1, maximum=20, step=1),
outputs=gr.outputs.Textbox(label="Prediction results"),
)
if __name__ == "__main__":
demo.launch()
''' |