CoolFace
Apppublic

Orangefish/project

sourceHugging Faceupdated 4y agoView on Hugging Face
0likes
app.py139 linesDownload Raw Back to root
1#!/usr/bin/env python2# coding: utf-83 4# In[37]:5 6 7import gradio as gr8import hopsworks9import joblib10import pandas as pd11import numpy as np12import folium13import sklearn.preprocessing as proc14import json15import time16from datetime import timedelta, datetime17from branca.element import Figure18 19from functions import get_weather_by_date20 21def greet(name):22	X = pd.DataFrame()23	for i in range(8):24		# Get, rename column and rescalef25		target_date = datetime.today() + timedelta(days=i)26		target_date = target_date.strftime('%Y-%m-%d')27		json = get_weather_by_date(target_date)28		X = X.append(json['days'][0], ignore_index=True)29 30 31	# In[38]:32 33 34	X.head()35	X.columns.values.tolist()36 37 38	# In[39]:39 40 41	X.drop('preciptype', inplace = True, axis = 1)42	X.drop('severerisk', inplace = True, axis = 1)43	X.drop('stations', inplace = True, axis = 1)44	X.drop('sunrise', inplace = True, axis = 1)45	X.drop('sunset', inplace = True, axis = 1)46	X.drop('moonphase', inplace = True, axis = 1)47	X.drop('description', inplace = True, axis = 1)48	X.drop('icon', inplace = True, axis = 1)49	X.drop('datetime', inplace = True, axis = 1)50 51 52	# In[40]:53 54 55	X.head()56 57 58	# In[41]:59 60 61	X = X.rename(columns={'sunriseEpoch':'pm25'})62	X = X.rename(columns={'sunsetEpoch':'pm10'})63	X = X.rename(columns={'source':'o3'})64	X = X.rename(columns={'normal':'aqi'})65	X = X.rename(columns={'datetimeEpoch':'city'})66 67 68	# In[42]:69 70 71	X.head()72 73 74	# In[43]:75 76 77	# X = X.drop(columns = ['conditions', "pm25", "pm10", "o3", "aqi"])78	X = X.drop(columns = ['conditions', "pm25", "pm10", "o3"])79	X.insert(0,"aqi",0)80	X.insert(0,"o3",0)81	X.insert(0,"pm10",0)82	X.insert(0,"pm25",0)83 84 85 86	X.insert(27,"conditions",0)87 88 89	# In[44]:90 91 92	X.head()93 94 95	# In[46]:96 97 98	preds = model.predict(X)99 100 101	# In[51]:102 103 104	print(preds)105 106 107	# In[53]:108 109 110	str1 = ""111	for x in range(8):112	  if(x != 0):113	     str1 += (datetime.now() + timedelta(days=x)).strftime('%Y-%m-%d') + " predicted aqi:      " + str(int(preds[x]))+"\n"114 115	print(str1)116	return str1117 118 119# In[ ]:120 121 122project = hopsworks.login()123mr = project.get_model_registry()124 125 126	# In[50]:127 128 129model = mr.get_model("gradient_boost_model",version = 4)130model_dir = model.download() 131model = joblib.load(model_dir + "/model.pkl")132 133demo = gr.Interface(fn=greet, inputs="text", outputs="text")134 135 136    137if __name__ == "__main__":138    demo.launch()139