File size: 2,295 Bytes
834fd46
 
 
 
 
 
 
 
760d8b7
 
834fd46
 
 
760d8b7
834fd46
 
 
b2042c8
f4c1fda
b2042c8
834fd46
 
4cfa287
834fd46
db1ef8c
096b29b
 
f6da296
834fd46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
094e146
1ba1adc
303fdf6
 
 
 
 
 
 
834fd46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e6d7d2c
 
 
 
 
 
 
 
 
 
 
834fd46
 
 
 
 
 
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
#!/usr/bin/env python
# coding: utf-8

# In[37]:


import gradio as gr
import hopsworks
import joblib
import pandas as pd
import numpy as np
import folium
import sklearn.preprocessing as proc
import json
import time
from datetime import timedelta, datetime
from branca.element import Figure

from functions import get_weather_by_date

def greet(name):
	X = pd.DataFrame()
	for i in range(8):
		# Get, rename column and rescalef
		target_date = datetime.today() + timedelta(days=i)
		target_date = target_date.strftime('%Y-%m-%d')
		json = get_weather_by_date(target_date)
		X = X.append(json['days'][0], ignore_index=True)


	# In[38]:


	X.head()
	X.columns.values.tolist()


	# In[39]:


	X.drop('preciptype', inplace = True, axis = 1)
	X.drop('severerisk', inplace = True, axis = 1)
	X.drop('stations', inplace = True, axis = 1)
	X.drop('sunrise', inplace = True, axis = 1)
	X.drop('sunset', inplace = True, axis = 1)
	X.drop('moonphase', inplace = True, axis = 1)
	X.drop('description', inplace = True, axis = 1)
	X.drop('icon', inplace = True, axis = 1)
	X.drop('datetime', inplace = True, axis = 1)


	# In[40]:


	X.head()


	# In[41]:


	X = X.rename(columns={'sunriseEpoch':'pm25'})
	X = X.rename(columns={'sunsetEpoch':'pm10'})
	X = X.rename(columns={'source':'o3'})
	X = X.rename(columns={'normal':'aqi'})
	X = X.rename(columns={'datetimeEpoch':'city'})


	# In[42]:


	X.head()


	# In[43]:


	# X = X.drop(columns = ['conditions', "pm25", "pm10", "o3", "aqi"])
	X = X.drop(columns = ['conditions', "pm25", "pm10", "o3"])
	X.insert(0,"aqi",0)
	X.insert(0,"o3",0)
	X.insert(0,"pm10",0)
	X.insert(0,"pm25",0)



	X.insert(27,"conditions",0)


	# In[44]:


	X.head()


	# In[46]:


	preds = model.predict(X)


	# In[51]:


	print(preds)


	# In[53]:


	str1 = ""
	for x in range(8):
	  if(x != 0):
	     str1 += (datetime.now() + timedelta(days=x)).strftime('%Y-%m-%d') + " predicted aqi:      " + str(int(preds[x]))+"\n"

	print(str1)
	return str1


# In[ ]:


project = hopsworks.login()
mr = project.get_model_registry()


	# In[50]:


model = mr.get_model("gradient_boost_model",version = 4)
model_dir = model.download() 
model = joblib.load(model_dir + "/model.pkl")

demo = gr.Interface(fn=greet, inputs="text", outputs="text")


    
if __name__ == "__main__":
    demo.launch()