rscolati commited on
Commit
ee3256e
β€’
1 Parent(s): 8a5ef42

Upload 3 files

Browse files
Files changed (3) hide show
  1. README.md +5 -4
  2. app.py +64 -0
  3. requirements.txt +3 -0
README.md CHANGED
@@ -1,12 +1,13 @@
1
  ---
2
  title: Electricity
3
- emoji: πŸ’»
4
- colorFrom: green
5
- colorTo: gray
6
  sdk: gradio
7
- sdk_version: 3.16.0
8
  app_file: app.py
9
  pinned: false
 
10
  ---
11
 
12
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
  title: Electricity
3
+ emoji: πŸ”Œ
4
+ colorFrom: purple
5
+ colorTo: yellow
6
  sdk: gradio
7
+ sdk_version: 3.5
8
  app_file: app.py
9
  pinned: false
10
+ license: apache-2.0
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ from pandas.tseries.holiday import USFederalHolidayCalendar as calendar
4
+
5
+ import hopsworks
6
+ import joblib
7
+ import datetime
8
+ import os
9
+ import requests
10
+
11
+ project = hopsworks.login()
12
+ fs = project.get_feature_store()
13
+
14
+ mr = project.get_model_registry()
15
+ model = mr.get_model("ny_elec_model", version=1)
16
+ model_dir = model.download()
17
+ model = joblib.load(model_dir + "/ny_elec_model.pkl")
18
+
19
+
20
+ def predict():
21
+ today = get_date()
22
+ temp = get_temp(today)
23
+ df = pd.DataFrame({"date": [today], "temperature": [temp]})
24
+ df['date'] = pd.to_datetime(df['date'], infer_datetime_format=True)
25
+ df['day'] = df['date'].dt.dayofweek
26
+ df['month'] = df['date'].dt.month
27
+ holidays = calendar().holidays(start=df['date'].min(), end=df['date'].max())
28
+ df['holiday'] = df['date'].isin(holidays).astype(int)
29
+
30
+ demand = model.predict(df.drop(columns=['date']))[0]
31
+ return [today, temp, demand]
32
+
33
+
34
+ def get_date():
35
+ today = datetime.datetime.today()
36
+ return today.date()
37
+
38
+
39
+ def get_temp(date):
40
+ weather_api_key = os.environ.get('WEATHER_API_KEY')
41
+ weather_url = ('http://api.weatherapi.com/v1/history.json'
42
+ '?key={}'
43
+ '&q=New%20York,%20USA'
44
+ '&dt={}').format(weather_api_key, date)
45
+ return requests.get(weather_url).json()['forecast']['forecastday'][0]['day']['avgtemp_c']
46
+
47
+
48
+ demo = gr.Interface(
49
+ fn = predict,
50
+ title = "NY Electricity Demand Prediction",
51
+ description ="Daily NY Electricity Demand Prediction",
52
+ allow_flagging = "never",
53
+ inputs = [],
54
+ outputs = [
55
+ gr.Textbox(label="Date"),
56
+ gr.Textbox(label="Temperature forecast [℃]"),
57
+ gr.Textbox(label="Predicted demand [MWh]"),
58
+ ]
59
+ )
60
+
61
+ # TODO: we have only the demand predictions for two days ago, so we have two options
62
+ # - skip EIA demand forecast (no comparison)
63
+ # - show prediction for two days ago
64
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ hopsworks
2
+ joblib
3
+ pandas