hubtru commited on
Commit ·
4577714
1
Parent(s): 7fb1408
initial
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitignore +12 -0
- README.md +4 -5
- app.py +336 -0
- requirements.txt +7 -0
- results_ltboost/ETTh1_sl336_pl192/1/img_0.png +0 -0
- results_ltboost/ETTh1_sl336_pl192/1/img_100.png +0 -0
- results_ltboost/ETTh1_sl336_pl192/1/img_1000.png +0 -0
- results_ltboost/ETTh1_sl336_pl192/1/img_1100.png +0 -0
- results_ltboost/ETTh1_sl336_pl192/1/img_1200.png +0 -0
- results_ltboost/ETTh1_sl336_pl192/1/img_1300.png +0 -0
- results_ltboost/ETTh1_sl336_pl192/1/img_1400.png +0 -0
- results_ltboost/ETTh1_sl336_pl192/1/img_1500.png +0 -0
- results_ltboost/ETTh1_sl336_pl192/1/img_1600.png +0 -0
- results_ltboost/ETTh1_sl336_pl192/1/img_1700.png +0 -0
- results_ltboost/ETTh1_sl336_pl192/1/img_1800.png +0 -0
- results_ltboost/ETTh1_sl336_pl192/1/img_1900.png +0 -0
- results_ltboost/ETTh1_sl336_pl192/1/img_200.png +0 -0
- results_ltboost/ETTh1_sl336_pl192/1/img_2000.png +0 -0
- results_ltboost/ETTh1_sl336_pl192/1/img_2100.png +0 -0
- results_ltboost/ETTh1_sl336_pl192/1/img_2200.png +0 -0
- results_ltboost/ETTh1_sl336_pl192/1/img_2300.png +0 -0
- results_ltboost/ETTh1_sl336_pl192/1/img_2400.png +0 -0
- results_ltboost/ETTh1_sl336_pl192/1/img_2500.png +0 -0
- results_ltboost/ETTh1_sl336_pl192/1/img_2600.png +0 -0
- results_ltboost/ETTh1_sl336_pl192/1/img_300.png +0 -0
- results_ltboost/ETTh1_sl336_pl192/1/img_400.png +0 -0
- results_ltboost/ETTh1_sl336_pl192/1/img_500.png +0 -0
- results_ltboost/ETTh1_sl336_pl192/1/img_600.png +0 -0
- results_ltboost/ETTh1_sl336_pl192/1/img_700.png +0 -0
- results_ltboost/ETTh1_sl336_pl192/1/img_800.png +0 -0
- results_ltboost/ETTh1_sl336_pl192/1/img_900.png +0 -0
- results_ltboost/ETTh1_sl336_pl192/2/img_0.png +0 -0
- results_ltboost/ETTh1_sl336_pl192/2/img_100.png +0 -0
- results_ltboost/ETTh1_sl336_pl192/2/img_1000.png +0 -0
- results_ltboost/ETTh1_sl336_pl192/2/img_1100.png +0 -0
- results_ltboost/ETTh1_sl336_pl192/2/img_1200.png +0 -0
- results_ltboost/ETTh1_sl336_pl192/2/img_1300.png +0 -0
- results_ltboost/ETTh1_sl336_pl192/2/img_1400.png +0 -0
- results_ltboost/ETTh1_sl336_pl192/2/img_1500.png +0 -0
- results_ltboost/ETTh1_sl336_pl192/2/img_1600.png +0 -0
- results_ltboost/ETTh1_sl336_pl192/2/img_1700.png +0 -0
- results_ltboost/ETTh1_sl336_pl192/2/img_1800.png +0 -0
- results_ltboost/ETTh1_sl336_pl192/2/img_1900.png +0 -0
- results_ltboost/ETTh1_sl336_pl192/2/img_200.png +0 -0
- results_ltboost/ETTh1_sl336_pl192/2/img_2000.png +0 -0
- results_ltboost/ETTh1_sl336_pl192/2/img_2100.png +0 -0
- results_ltboost/ETTh1_sl336_pl192/2/img_2200.png +0 -0
- results_ltboost/ETTh1_sl336_pl192/2/img_2300.png +0 -0
- results_ltboost/ETTh1_sl336_pl192/2/img_2400.png +0 -0
- results_ltboost/ETTh1_sl336_pl192/2/img_2500.png +0 -0
.gitignore
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.idea/
|
| 2 |
+
|
| 3 |
+
# Ignore venv directory
|
| 4 |
+
venv/
|
| 5 |
+
|
| 6 |
+
__pycache__/
|
| 7 |
+
|
| 8 |
+
Models/
|
| 9 |
+
|
| 10 |
+
checkpoints/
|
| 11 |
+
|
| 12 |
+
result.txt
|
README.md
CHANGED
|
@@ -1,13 +1,12 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
colorTo: indigo
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version: 4.
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
-
license: mit
|
| 11 |
---
|
| 12 |
|
| 13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: AI Project
|
| 3 |
+
emoji: 🐨
|
| 4 |
+
colorFrom: red
|
| 5 |
colorTo: indigo
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 4.28.3
|
| 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
|
app.py
ADDED
|
@@ -0,0 +1,336 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import matplotlib.pyplot as plt
|
| 4 |
+
|
| 5 |
+
def toggle_num_variable_visibility(model_choice):
|
| 6 |
+
if model_choice == "LTBoost":
|
| 7 |
+
return gr.update(visible=True)
|
| 8 |
+
else:
|
| 9 |
+
return gr.update(visible=False)
|
| 10 |
+
|
| 11 |
+
def update_num_variable(dataset_choice):
|
| 12 |
+
reset_value = 1
|
| 13 |
+
if not dataset_choice :
|
| 14 |
+
return gr.update(minimum=1, maximum=10, step=1, value=reset_value)
|
| 15 |
+
if dataset_choice in ['Electricity', 'Traffic']:
|
| 16 |
+
num_variable_range = (1,10,1)
|
| 17 |
+
elif dataset_choice in ['ETTh1', 'ETTh2', 'ETTm1', 'ETTm2', 'National_illness']:
|
| 18 |
+
num_variable_range = (1,7,1)
|
| 19 |
+
elif dataset_choice == "Weather":
|
| 20 |
+
num_variable_range = (1,21,1)
|
| 21 |
+
elif dataset_choice == "Exchange":
|
| 22 |
+
num_variable_range = (1,8,1)
|
| 23 |
+
return gr.update(minimum=num_variable_range[0], maximum=num_variable_range[1], step=num_variable_range[2],
|
| 24 |
+
value=reset_value)
|
| 25 |
+
def update_time_horizon(dataset_choice):
|
| 26 |
+
if dataset_choice == "National_illness":
|
| 27 |
+
choices = [24, 36, 48, 60]
|
| 28 |
+
else:
|
| 29 |
+
choices = [96, 192, 336, 720]
|
| 30 |
+
|
| 31 |
+
#default value = maximum choice
|
| 32 |
+
default_value = max(choices)
|
| 33 |
+
|
| 34 |
+
return gr.update(choices=choices, value=default_value)
|
| 35 |
+
|
| 36 |
+
def update_starting_point(model_choice, dataset_choice, time_horizon):
|
| 37 |
+
reset_value = 0
|
| 38 |
+
starting_point_range = (0, 300, 20) # Standardwert
|
| 39 |
+
if not model_choice or not dataset_choice or not time_horizon:
|
| 40 |
+
return gr.update(minimum=0, maximum=300, step=20, value = reset_value)
|
| 41 |
+
|
| 42 |
+
if model_choice == "NLinear":
|
| 43 |
+
if dataset_choice == "Electricity":
|
| 44 |
+
if time_horizon == 96:
|
| 45 |
+
starting_point_range = (0, 160, 20)
|
| 46 |
+
elif time_horizon in [192, 336, 720]:
|
| 47 |
+
starting_point_range = (0, 140, 20)
|
| 48 |
+
elif dataset_choice == "ETTh1":
|
| 49 |
+
if time_horizon in [96, 192]:
|
| 50 |
+
starting_point_range = (0, 80, 20)
|
| 51 |
+
else:
|
| 52 |
+
starting_point_range = (0, 60, 20)
|
| 53 |
+
elif dataset_choice == "ETTh2":
|
| 54 |
+
if time_horizon in [96, 192]:
|
| 55 |
+
starting_point_range = (0, 80, 20)
|
| 56 |
+
else:
|
| 57 |
+
starting_point_range = (0, 60, 20)
|
| 58 |
+
elif dataset_choice == "Traffic":
|
| 59 |
+
if time_horizon in [96, 192]:
|
| 60 |
+
starting_point_range = (0, 100, 20)
|
| 61 |
+
else:
|
| 62 |
+
starting_point_range = (0, 80, 20)
|
| 63 |
+
elif dataset_choice == "Weather":
|
| 64 |
+
if time_horizon in [96, 192]:
|
| 65 |
+
starting_point_range = (0, 320, 20)
|
| 66 |
+
else:
|
| 67 |
+
starting_point_range = (0, 300, 20)
|
| 68 |
+
elif dataset_choice == "Exchange":
|
| 69 |
+
if time_horizon in [96, 192]:
|
| 70 |
+
starting_point_range = (0,40,20)
|
| 71 |
+
else:
|
| 72 |
+
starting_point_range = (0, 20, 20)
|
| 73 |
+
elif dataset_choice == "National_illness":
|
| 74 |
+
starting_point_range = (0, 0, 0)
|
| 75 |
+
elif dataset_choice == "ETTm2":
|
| 76 |
+
if time_horizon == 720:
|
| 77 |
+
starting_point_range = (0, 320, 20)
|
| 78 |
+
else:
|
| 79 |
+
starting_point_range = (0,340,20)
|
| 80 |
+
elif dataset_choice == "ETTm1":
|
| 81 |
+
if time_horizon == 720:
|
| 82 |
+
starting_point_range = (0, 320, 20)
|
| 83 |
+
else:
|
| 84 |
+
starting_point_range = (0,340,20)
|
| 85 |
+
else:
|
| 86 |
+
if dataset_choice == "National_illness":
|
| 87 |
+
if time_horizon == 24:
|
| 88 |
+
starting_point_range = (0, 160, 20)
|
| 89 |
+
elif time_horizon in [36, 48]:
|
| 90 |
+
starting_point_range = (0, 140, 20)
|
| 91 |
+
elif time_horizon == 60:
|
| 92 |
+
starting_point_range = (0, 120, 20)
|
| 93 |
+
elif dataset_choice == "Electricity":
|
| 94 |
+
starting_point_range = (0,4320, 720)
|
| 95 |
+
elif dataset_choice in ["ETTh1", "ETTh2"]:
|
| 96 |
+
if time_horizon == 96:
|
| 97 |
+
starting_point_range = (0, 2700, 100)
|
| 98 |
+
elif time_horizon == 192:
|
| 99 |
+
starting_point_range = (0, 2600, 100)
|
| 100 |
+
elif time_horizon == 336:
|
| 101 |
+
starting_point_range = (0, 2300, 100)
|
| 102 |
+
elif time_horizon == 720:
|
| 103 |
+
starting_point_range = (0, 2100, 100)
|
| 104 |
+
elif dataset_choice in ["ETTm1", "ETTm2"]:
|
| 105 |
+
starting_point_range = (0,10800, 720)
|
| 106 |
+
elif dataset_choice == "Exchange":
|
| 107 |
+
if time_horizon == 96:
|
| 108 |
+
starting_point_range = (0, 1300, 100)
|
| 109 |
+
elif time_horizon == 192:
|
| 110 |
+
starting_point_range = (0, 1100, 100)
|
| 111 |
+
elif time_horizon == 336:
|
| 112 |
+
starting_point_range = (0, 1000, 100)
|
| 113 |
+
elif time_horizon == 720:
|
| 114 |
+
starting_point_range = (0, 700, 100)
|
| 115 |
+
elif dataset_choice == "Traffic":
|
| 116 |
+
if time_horizon == 96:
|
| 117 |
+
starting_point_range = (0, 3300, 100)
|
| 118 |
+
elif time_horizon == 192:
|
| 119 |
+
starting_point_range = (0, 3200, 100)
|
| 120 |
+
elif time_horizon == 336:
|
| 121 |
+
starting_point_range = (0, 3000, 100)
|
| 122 |
+
elif time_horizon == 720:
|
| 123 |
+
starting_point_range = (0, 2100, 100)
|
| 124 |
+
elif dataset_choice == "Weather":
|
| 125 |
+
starting_point_range = (0, 9360, 720)
|
| 126 |
+
else:
|
| 127 |
+
starting_point_range = (0, 300, 20)
|
| 128 |
+
return gr.update(minimum = starting_point_range[0], maximum = starting_point_range[1], step = starting_point_range[2], value = reset_value)
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
def find_csv_file(dataset_choice, time_horizon, look_back_window):
|
| 133 |
+
dir = "Models/LTBoost"
|
| 134 |
+
for root, dirs, files in os.walk(dir):
|
| 135 |
+
for dir_name in dirs:
|
| 136 |
+
if dataset_choice.lower() in dir_name.lower():
|
| 137 |
+
full_dir_path = os.path.join(root, dir_name)
|
| 138 |
+
for file_name in os.listdir(full_dir_path):
|
| 139 |
+
if f"pl_{time_horizon}" in file_name:
|
| 140 |
+
csv_file_path = os.path.join(full_dir_path, file_name)
|
| 141 |
+
if os.path.exists(csv_file_path):
|
| 142 |
+
return csv_file_path
|
| 143 |
+
return None
|
| 144 |
+
|
| 145 |
+
def plot_forecast_vs_ground_truth(df_forecast, df_ground_truth, dataset_choice, model_choice, lookback_window,time_horizon, starting_point, num_variable):
|
| 146 |
+
plt.figure(figsize=(12, 6))
|
| 147 |
+
|
| 148 |
+
plt.plot(df_ground_truth, label='Forecast')
|
| 149 |
+
plt.plot(df_forecast, label='Ground Truth')
|
| 150 |
+
# Marking the transition between look-back window and forecast horizon
|
| 151 |
+
transition_point = lookback_window
|
| 152 |
+
plt.axvline(x=transition_point, color='black', linestyle='-')
|
| 153 |
+
plt.title(f'Forecast vs Ground Truth for {dataset_choice} using {model_choice} Model')
|
| 154 |
+
#plt.xlabel('Time')
|
| 155 |
+
#plt.ylabel('Value')
|
| 156 |
+
plt.legend()
|
| 157 |
+
plt.grid(True)
|
| 158 |
+
# Create directory path based on dataset name, lookback window, and time horizon
|
| 159 |
+
save_dir = f"results_ltboost/{dataset_choice}_sl{lookback_window}_pl{time_horizon}/{num_variable}"
|
| 160 |
+
os.makedirs(save_dir, exist_ok=True) # Ensure directory exists, create if not
|
| 161 |
+
|
| 162 |
+
# Save the plot as PNG file
|
| 163 |
+
path = os.path.join(save_dir, f"img_{starting_point}.png")
|
| 164 |
+
plt.savefig(path)
|
| 165 |
+
|
| 166 |
+
plt.close()
|
| 167 |
+
return path
|
| 168 |
+
|
| 169 |
+
def find_image_path(dataset_choice, model_choice, time_horizon, look_back_window, starting_point):
|
| 170 |
+
directory = "results_nlinear"
|
| 171 |
+
for root, dirs, files in os.walk(directory):
|
| 172 |
+
for dir_name in dirs:
|
| 173 |
+
if dataset_choice.lower() in dir_name.lower() and model_choice in dir_name and f"pl{time_horizon}" in dir_name and f"sl{look_back_window}" in dir_name:
|
| 174 |
+
image_path = os.path.join(root, dir_name, f"{starting_point}.png")
|
| 175 |
+
if os.path.exists(image_path):
|
| 176 |
+
return image_path
|
| 177 |
+
return None
|
| 178 |
+
|
| 179 |
+
def find_image_path_LTBoost(dataset_choice, time_horizon, look_back_window, starting_point, num_variable):
|
| 180 |
+
directory = "results_ltboost"
|
| 181 |
+
for root, dirs, files in os.walk(directory):
|
| 182 |
+
for dir_name in dirs:
|
| 183 |
+
# Check if the folder name contains the desired dataset, time horizon, and look-back window
|
| 184 |
+
if (dataset_choice.lower() in dir_name.lower() and
|
| 185 |
+
f"pl{time_horizon}" in dir_name and
|
| 186 |
+
f"sl{look_back_window}" in dir_name):
|
| 187 |
+
|
| 188 |
+
variable_dir = os.path.join(root, dir_name, str(num_variable))
|
| 189 |
+
|
| 190 |
+
if os.path.exists(variable_dir):
|
| 191 |
+
image_path = os.path.join(variable_dir, f"img_{starting_point}.png")
|
| 192 |
+
|
| 193 |
+
if os.path.exists(image_path):
|
| 194 |
+
return image_path
|
| 195 |
+
|
| 196 |
+
return None
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
def perform_forecasting(dataset_choice, model_choice, time_horizon, starting_point, num_variable):
|
| 200 |
+
if model_choice == "NLinear":
|
| 201 |
+
if dataset_choice == "National_illness":
|
| 202 |
+
look_back_window = 104
|
| 203 |
+
else:
|
| 204 |
+
look_back_window = 336
|
| 205 |
+
else:
|
| 206 |
+
if dataset_choice == "National_illness":
|
| 207 |
+
look_back_window = 104
|
| 208 |
+
elif dataset_choice == "Exchange" or dataset_choice == "ETTh1":
|
| 209 |
+
look_back_window = 336
|
| 210 |
+
else:
|
| 211 |
+
look_back_window = 720
|
| 212 |
+
|
| 213 |
+
if model_choice == "NLinear":
|
| 214 |
+
# check if already have a png image
|
| 215 |
+
img = find_image_path(dataset_choice, model_choice, time_horizon, look_back_window, starting_point)
|
| 216 |
+
if img:
|
| 217 |
+
return img
|
| 218 |
+
else:
|
| 219 |
+
return "No image found"
|
| 220 |
+
|
| 221 |
+
elif model_choice == "LTBoost":
|
| 222 |
+
# check if already have a png image
|
| 223 |
+
img = find_image_path_LTBoost(dataset_choice, time_horizon, look_back_window, starting_point, num_variable)
|
| 224 |
+
if img:
|
| 225 |
+
return img
|
| 226 |
+
else:
|
| 227 |
+
return "Image not found"
|
| 228 |
+
|
| 229 |
+
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+
def main():
|
| 233 |
+
theme = gr.themes.Base(
|
| 234 |
+
primary_hue="blue",
|
| 235 |
+
secondary_hue="blue",
|
| 236 |
+
neutral_hue="gray"
|
| 237 |
+
)
|
| 238 |
+
theme.set(
|
| 239 |
+
body_background_fill="*primary_50",
|
| 240 |
+
body_background_fill_dark="*checkbox_background_color_focus",
|
| 241 |
+
body_text_color_dark="white",
|
| 242 |
+
body_text_color="*neutral_800",
|
| 243 |
+
background_fill_secondary_dark="*checkbox_border_color_hover",
|
| 244 |
+
block_background_fill="*background_fill_primary",
|
| 245 |
+
block_background_fill_dark="*neutral_800",
|
| 246 |
+
block_border_color_dark="*primary_100",
|
| 247 |
+
block_border_width_dark="4px",
|
| 248 |
+
block_border_width="4px",
|
| 249 |
+
block_border_color="*secondary_200"
|
| 250 |
+
)
|
| 251 |
+
with gr.Blocks(theme=theme) as demo:
|
| 252 |
+
gr.Markdown("""
|
| 253 |
+
<h1 style="text-align: center;">Time Series Forecasting DEMO</h1>
|
| 254 |
+
<div style="letter-spacing: 1px; line-height: 1.5;">This is the AI demo with the use of Hugging Face platform with Gradio library interface.
|
| 255 |
+
Users have the ability to choose between the dataset, model, time horizon, and starting point. <br>
|
| 256 |
+
Options: <br>
|
| 257 |
+
- Dataset Choice: 9 LTSF datasets <br>
|
| 258 |
+
- Model choice: NLinear or LTBoost <br>
|
| 259 |
+
- Time horizon: {96, 192, 336, 720} (depends on the dataset)<br>
|
| 260 |
+
- Starting point: {0, 20, 40 ... 300}<br>
|
| 261 |
+
Number of figures for each of the dataset depends on the dataset_trainset length and the model we choose<br></div>
|
| 262 |
+
""")
|
| 263 |
+
with gr.Row():
|
| 264 |
+
with gr.Column():
|
| 265 |
+
dataset_choice = gr.Dropdown(
|
| 266 |
+
["Electricity", "Traffic", "Weather", "Exchange", "National_illness", "ETTh1", "ETTh2", "ETTm1", "ETTm2"],
|
| 267 |
+
label="Dataset Choice"
|
| 268 |
+
)
|
| 269 |
+
model_choice = gr.Dropdown(["NLinear", "LTBoost"], label="Model Choice", value= "LTBoost")
|
| 270 |
+
time_horizon = gr.Dropdown([96, 192, 336, 720], label="Time Horizon")
|
| 271 |
+
starting_point = gr.Slider(minimum=0, maximum=300, step=20, label="Starting Point", value= 0)
|
| 272 |
+
num_variable = gr.Slider(minimum=1,maximum=10,step=1,label="Variable")
|
| 273 |
+
|
| 274 |
+
input_components = [dataset_choice, model_choice, time_horizon, starting_point, num_variable]
|
| 275 |
+
|
| 276 |
+
dataset_choice.change(update_time_horizon, inputs=dataset_choice, outputs=time_horizon)
|
| 277 |
+
|
| 278 |
+
dataset_choice.change(update_starting_point, inputs=[model_choice, dataset_choice, time_horizon],
|
| 279 |
+
outputs=starting_point)
|
| 280 |
+
model_choice.change(update_starting_point, inputs=[model_choice, dataset_choice, time_horizon],
|
| 281 |
+
outputs=starting_point)
|
| 282 |
+
model_choice.change(fn=toggle_num_variable_visibility, inputs=model_choice, outputs=num_variable)
|
| 283 |
+
time_horizon.change(update_starting_point, inputs=[model_choice, dataset_choice, time_horizon],
|
| 284 |
+
outputs=starting_point)
|
| 285 |
+
dataset_choice.change(update_num_variable, inputs = dataset_choice, outputs = num_variable)
|
| 286 |
+
|
| 287 |
+
gr.ClearButton(input_components)
|
| 288 |
+
|
| 289 |
+
with gr.Column():
|
| 290 |
+
# Automatically update the output image whenever any input component changes
|
| 291 |
+
output_png = gr.Image(label="Forecast Results")
|
| 292 |
+
for component in input_components:
|
| 293 |
+
component.change(perform_forecasting, inputs=input_components, outputs=output_png)
|
| 294 |
+
with gr.Row():
|
| 295 |
+
with gr.Column():
|
| 296 |
+
gr.Markdown("Examples for the user input:")
|
| 297 |
+
gr.Examples([
|
| 298 |
+
['ETTh1', 'NLinear', 720, 0],
|
| 299 |
+
|
| 300 |
+
['ETTh2', 'NLinear', 720, 0],
|
| 301 |
+
|
| 302 |
+
['ETTm1', 'NLinear', 720, 0],
|
| 303 |
+
|
| 304 |
+
['ETTm2', 'NLinear', 720, 0],
|
| 305 |
+
|
| 306 |
+
['Weather', 'NLinear', 720, 0],
|
| 307 |
+
|
| 308 |
+
['Traffic', 'NLinear', 720, 0],
|
| 309 |
+
|
| 310 |
+
['Electricity', 'NLinear', 720, 0],
|
| 311 |
+
|
| 312 |
+
['ETTh1', 'LTBoost', 720, 0],
|
| 313 |
+
|
| 314 |
+
['ETTh2', 'LTBoost', 720, 0],
|
| 315 |
+
|
| 316 |
+
['ETTm1', 'LTBoost', 720, 0],
|
| 317 |
+
|
| 318 |
+
['ETTm2', 'LTBoost', 720, 0],
|
| 319 |
+
|
| 320 |
+
['Weather', 'LTBoost', 720, 0],
|
| 321 |
+
|
| 322 |
+
['Traffic', 'LTBoost', 720, 0],
|
| 323 |
+
|
| 324 |
+
['Electricity', 'LTBoost', 720, 0],
|
| 325 |
+
|
| 326 |
+
],
|
| 327 |
+
|
| 328 |
+
inputs=input_components)
|
| 329 |
+
|
| 330 |
+
|
| 331 |
+
|
| 332 |
+
demo.launch()
|
| 333 |
+
|
| 334 |
+
if __name__ == "__main__":
|
| 335 |
+
main()
|
| 336 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
torch
|
| 3 |
+
sklearn
|
| 4 |
+
pandas
|
| 5 |
+
matplotlib.pyplot
|
| 6 |
+
os
|
| 7 |
+
numpy
|
results_ltboost/ETTh1_sl336_pl192/1/img_0.png
ADDED
|
results_ltboost/ETTh1_sl336_pl192/1/img_100.png
ADDED
|
results_ltboost/ETTh1_sl336_pl192/1/img_1000.png
ADDED
|
results_ltboost/ETTh1_sl336_pl192/1/img_1100.png
ADDED
|
results_ltboost/ETTh1_sl336_pl192/1/img_1200.png
ADDED
|
results_ltboost/ETTh1_sl336_pl192/1/img_1300.png
ADDED
|
results_ltboost/ETTh1_sl336_pl192/1/img_1400.png
ADDED
|
results_ltboost/ETTh1_sl336_pl192/1/img_1500.png
ADDED
|
results_ltboost/ETTh1_sl336_pl192/1/img_1600.png
ADDED
|
results_ltboost/ETTh1_sl336_pl192/1/img_1700.png
ADDED
|
results_ltboost/ETTh1_sl336_pl192/1/img_1800.png
ADDED
|
results_ltboost/ETTh1_sl336_pl192/1/img_1900.png
ADDED
|
results_ltboost/ETTh1_sl336_pl192/1/img_200.png
ADDED
|
results_ltboost/ETTh1_sl336_pl192/1/img_2000.png
ADDED
|
results_ltboost/ETTh1_sl336_pl192/1/img_2100.png
ADDED
|
results_ltboost/ETTh1_sl336_pl192/1/img_2200.png
ADDED
|
results_ltboost/ETTh1_sl336_pl192/1/img_2300.png
ADDED
|
results_ltboost/ETTh1_sl336_pl192/1/img_2400.png
ADDED
|
results_ltboost/ETTh1_sl336_pl192/1/img_2500.png
ADDED
|
results_ltboost/ETTh1_sl336_pl192/1/img_2600.png
ADDED
|
results_ltboost/ETTh1_sl336_pl192/1/img_300.png
ADDED
|
results_ltboost/ETTh1_sl336_pl192/1/img_400.png
ADDED
|
results_ltboost/ETTh1_sl336_pl192/1/img_500.png
ADDED
|
results_ltboost/ETTh1_sl336_pl192/1/img_600.png
ADDED
|
results_ltboost/ETTh1_sl336_pl192/1/img_700.png
ADDED
|
results_ltboost/ETTh1_sl336_pl192/1/img_800.png
ADDED
|
results_ltboost/ETTh1_sl336_pl192/1/img_900.png
ADDED
|
results_ltboost/ETTh1_sl336_pl192/2/img_0.png
ADDED
|
results_ltboost/ETTh1_sl336_pl192/2/img_100.png
ADDED
|
results_ltboost/ETTh1_sl336_pl192/2/img_1000.png
ADDED
|
results_ltboost/ETTh1_sl336_pl192/2/img_1100.png
ADDED
|
results_ltboost/ETTh1_sl336_pl192/2/img_1200.png
ADDED
|
results_ltboost/ETTh1_sl336_pl192/2/img_1300.png
ADDED
|
results_ltboost/ETTh1_sl336_pl192/2/img_1400.png
ADDED
|
results_ltboost/ETTh1_sl336_pl192/2/img_1500.png
ADDED
|
results_ltboost/ETTh1_sl336_pl192/2/img_1600.png
ADDED
|
results_ltboost/ETTh1_sl336_pl192/2/img_1700.png
ADDED
|
results_ltboost/ETTh1_sl336_pl192/2/img_1800.png
ADDED
|
results_ltboost/ETTh1_sl336_pl192/2/img_1900.png
ADDED
|
results_ltboost/ETTh1_sl336_pl192/2/img_200.png
ADDED
|
results_ltboost/ETTh1_sl336_pl192/2/img_2000.png
ADDED
|
results_ltboost/ETTh1_sl336_pl192/2/img_2100.png
ADDED
|
results_ltboost/ETTh1_sl336_pl192/2/img_2200.png
ADDED
|
results_ltboost/ETTh1_sl336_pl192/2/img_2300.png
ADDED
|
results_ltboost/ETTh1_sl336_pl192/2/img_2400.png
ADDED
|
results_ltboost/ETTh1_sl336_pl192/2/img_2500.png
ADDED
|