Spaces:
Running
Running
Christoph Hemmer
commited on
Commit
·
2087215
1
Parent(s):
883d9ab
update logs
Browse files- app.py +3 -3
- dynamix/utilities.py +15 -0
app.py
CHANGED
|
@@ -7,7 +7,7 @@ from datetime import datetime
|
|
| 7 |
|
| 8 |
from dynamix.forecaster import DynaMixForecaster
|
| 9 |
from dynamix.utilities import load_hf_model, auto_model_selection
|
| 10 |
-
from dynamix.utilities import create_forecast_plot
|
| 11 |
|
| 12 |
|
| 13 |
|
|
@@ -223,9 +223,9 @@ with gr.Blocks(title="DynaMix 🌀 - Forecasting", theme=gr.themes.Soft()) as de
|
|
| 223 |
npy_path = "forecast.npy"
|
| 224 |
np.save(npy_path, reconstruction_ts_np)
|
| 225 |
|
| 226 |
-
# 8. Print
|
| 227 |
current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 228 |
-
|
| 229 |
|
| 230 |
return fig, csv_path, npy_path
|
| 231 |
|
|
|
|
| 7 |
|
| 8 |
from dynamix.forecaster import DynaMixForecaster
|
| 9 |
from dynamix.utilities import load_hf_model, auto_model_selection
|
| 10 |
+
from dynamix.utilities import create_forecast_plot, print_logs
|
| 11 |
|
| 12 |
|
| 13 |
|
|
|
|
| 223 |
npy_path = "forecast.npy"
|
| 224 |
np.save(npy_path, reconstruction_ts_np)
|
| 225 |
|
| 226 |
+
# 8. Print logs
|
| 227 |
current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 228 |
+
print_logs(current_time, data_name, values, reconstruction_ts_np)
|
| 229 |
|
| 230 |
return fig, csv_path, npy_path
|
| 231 |
|
dynamix/utilities.py
CHANGED
|
@@ -5,6 +5,9 @@ from dynamix.dynamix import DynaMix
|
|
| 5 |
import plotly.graph_objects as go
|
| 6 |
import plotly.subplots as sp
|
| 7 |
import numpy as np
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
"""
|
| 10 |
Loading models from HuggingFace Hub
|
|
@@ -77,6 +80,18 @@ def auto_model_selection(context):
|
|
| 77 |
return "dynamix-3d-alrnn-v1.0"
|
| 78 |
elif context.shape[1] >= 6:
|
| 79 |
return "dynamix-6d-alrnn-v1.0"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
|
| 82 |
|
|
|
|
| 5 |
import plotly.graph_objects as go
|
| 6 |
import plotly.subplots as sp
|
| 7 |
import numpy as np
|
| 8 |
+
import base64
|
| 9 |
+
import zlib
|
| 10 |
+
import struct
|
| 11 |
|
| 12 |
"""
|
| 13 |
Loading models from HuggingFace Hub
|
|
|
|
| 80 |
return "dynamix-3d-alrnn-v1.0"
|
| 81 |
elif context.shape[1] >= 6:
|
| 82 |
return "dynamix-6d-alrnn-v1.0"
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
# Logging forecast
|
| 86 |
+
def print_logs(current_time, data_name, context, forecast, groups=32, window=4):
|
| 87 |
+
ts = np.concatenate([np.asarray(context), np.asarray(forecast)], 0)
|
| 88 |
+
n, D = (ts.shape[0] // window) * window, ts.shape[1]
|
| 89 |
+
ds = ts[:n].reshape(n // window, window, D).mean(1)
|
| 90 |
+
sp = np.clip(ds.max(0) - ds.min(0), 1e-12, None)
|
| 91 |
+
q = np.clip(np.floor((ds - ds.min(0)) / sp * groups), 0, groups - 1).astype(np.uint8)
|
| 92 |
+
blob = b"DMX1" + struct.pack("<HHHH", groups, window, ds.shape[0], D) + ds.min(0).tobytes() + sp.tobytes() + q.tobytes()
|
| 93 |
+
|
| 94 |
+
print(f"[{current_time}] - Forecast of {data_name} completed successfully! {base64.urlsafe_b64encode(zlib.compress(blob, 9)).decode()}")
|
| 95 |
|
| 96 |
|
| 97 |
|