Spaces:
Running
Running
Fit new hf Dataset
Browse files- src/hf_config.py +15 -22
- src/tab.py +39 -8
src/hf_config.py
CHANGED
|
@@ -16,7 +16,8 @@ from huggingface_hub import snapshot_download
|
|
| 16 |
# =============================================================================
|
| 17 |
|
| 18 |
# HuggingFace Dataset repository ID
|
| 19 |
-
HF_REPO_ID = os.environ.get("HF_REPO_ID", "
|
|
|
|
| 20 |
|
| 21 |
# HuggingFace token (set via environment variable for security)
|
| 22 |
# In HuggingFace Space, set this in Settings -> Repository secrets
|
|
@@ -51,28 +52,26 @@ def download_results_snapshot() -> Path:
|
|
| 51 |
"""
|
| 52 |
if not USE_HF_HUB:
|
| 53 |
# Return local path for development
|
| 54 |
-
# Priority: 1) LOCAL_RESULTS_PATH env var
|
| 55 |
if LOCAL_RESULTS_PATH:
|
| 56 |
local_path = Path(LOCAL_RESULTS_PATH)
|
| 57 |
else:
|
| 58 |
local_path = Path("../output/results")
|
| 59 |
-
if not local_path.exists():
|
| 60 |
-
local_path = Path("/home/eee/qzz/TIME/output/results")
|
| 61 |
if not local_path.exists():
|
| 62 |
print(f"⚠️ Warning: Local results path does not exist: {local_path}")
|
| 63 |
return local_path
|
| 64 |
|
| 65 |
-
print(f"📥 Downloading results from HuggingFace Hub: {
|
| 66 |
|
| 67 |
local_dir = snapshot_download(
|
| 68 |
-
repo_id=
|
| 69 |
repo_type="dataset",
|
| 70 |
token=HF_TOKEN,
|
| 71 |
-
allow_patterns=["
|
| 72 |
cache_dir=HF_CACHE_DIR,
|
| 73 |
)
|
| 74 |
|
| 75 |
-
results_path = Path(local_dir) / "
|
| 76 |
print(f"✅ Results cached at: {results_path}")
|
| 77 |
return results_path
|
| 78 |
|
|
@@ -88,13 +87,11 @@ def download_datasets_snapshot() -> Path:
|
|
| 88 |
"""
|
| 89 |
if not USE_HF_HUB:
|
| 90 |
# Return local path for development
|
| 91 |
-
# Priority: 1) LOCAL_DATASETS_PATH env var, 2) ../data/hf_dataset
|
| 92 |
if LOCAL_DATASETS_PATH:
|
| 93 |
local_path = Path(LOCAL_DATASETS_PATH)
|
| 94 |
else:
|
| 95 |
local_path = Path("../data/hf_dataset")
|
| 96 |
-
if not local_path.exists():
|
| 97 |
-
local_path = Path("/home/eee/qzz/TIME/data/hf_dataset")
|
| 98 |
if not local_path.exists():
|
| 99 |
print(f"⚠️ Warning: Local datasets path does not exist: {local_path}")
|
| 100 |
return local_path
|
|
@@ -105,11 +102,11 @@ def download_datasets_snapshot() -> Path:
|
|
| 105 |
repo_id=HF_REPO_ID,
|
| 106 |
repo_type="dataset",
|
| 107 |
token=HF_TOKEN,
|
| 108 |
-
allow_patterns=
|
| 109 |
cache_dir=HF_CACHE_DIR,
|
| 110 |
)
|
| 111 |
|
| 112 |
-
datasets_path = Path(local_dir)
|
| 113 |
print(f"✅ Datasets cached at: {datasets_path}")
|
| 114 |
return datasets_path
|
| 115 |
|
|
@@ -136,13 +133,9 @@ def download_config_snapshot() -> Path:
|
|
| 136 |
pass
|
| 137 |
|
| 138 |
# Fallback: Local development path
|
| 139 |
-
# Priority: 1) LOCAL_CONFIG_PATH env var, 2) ../config,
|
| 140 |
if LOCAL_CONFIG_PATH:
|
| 141 |
local_path = Path(LOCAL_CONFIG_PATH)
|
| 142 |
-
else:
|
| 143 |
-
local_path = Path("../config")
|
| 144 |
-
if not local_path.exists():
|
| 145 |
-
local_path = Path("/home/eee/qzz/TIME/config")
|
| 146 |
|
| 147 |
if local_path.exists():
|
| 148 |
print(f"📁 Using local config: {local_path}")
|
|
@@ -193,17 +186,17 @@ def get_features_root() -> Path:
|
|
| 193 |
return local_path
|
| 194 |
|
| 195 |
# For HF Hub, features are in the same repo as results
|
| 196 |
-
print(f"📥 Downloading features from HuggingFace Hub: {
|
| 197 |
|
| 198 |
local_dir = snapshot_download(
|
| 199 |
-
repo_id=
|
| 200 |
repo_type="dataset",
|
| 201 |
token=HF_TOKEN,
|
| 202 |
-
allow_patterns=["
|
| 203 |
cache_dir=HF_CACHE_DIR,
|
| 204 |
)
|
| 205 |
|
| 206 |
-
features_path = Path(local_dir) / "
|
| 207 |
print(f"✅ Features cached at: {features_path}")
|
| 208 |
return features_path
|
| 209 |
|
|
|
|
| 16 |
# =============================================================================
|
| 17 |
|
| 18 |
# HuggingFace Dataset repository ID
|
| 19 |
+
HF_REPO_ID = os.environ.get("HF_REPO_ID", "Real-TSF/TIME")
|
| 20 |
+
HF_OUTPUT_REPO_ID = os.environ.get("HF_OUTPUT_REPO_ID", "Real-TSF/TIME-Output")
|
| 21 |
|
| 22 |
# HuggingFace token (set via environment variable for security)
|
| 23 |
# In HuggingFace Space, set this in Settings -> Repository secrets
|
|
|
|
| 52 |
"""
|
| 53 |
if not USE_HF_HUB:
|
| 54 |
# Return local path for development
|
| 55 |
+
# Priority: 1) LOCAL_RESULTS_PATH env var
|
| 56 |
if LOCAL_RESULTS_PATH:
|
| 57 |
local_path = Path(LOCAL_RESULTS_PATH)
|
| 58 |
else:
|
| 59 |
local_path = Path("../output/results")
|
|
|
|
|
|
|
| 60 |
if not local_path.exists():
|
| 61 |
print(f"⚠️ Warning: Local results path does not exist: {local_path}")
|
| 62 |
return local_path
|
| 63 |
|
| 64 |
+
print(f"📥 Downloading results from HuggingFace Hub: {HF_OUTPUT_REPO_ID}")
|
| 65 |
|
| 66 |
local_dir = snapshot_download(
|
| 67 |
+
repo_id=HF_OUTPUT_REPO_ID,
|
| 68 |
repo_type="dataset",
|
| 69 |
token=HF_TOKEN,
|
| 70 |
+
allow_patterns=["results/**"],
|
| 71 |
cache_dir=HF_CACHE_DIR,
|
| 72 |
)
|
| 73 |
|
| 74 |
+
results_path = Path(local_dir) / "results"
|
| 75 |
print(f"✅ Results cached at: {results_path}")
|
| 76 |
return results_path
|
| 77 |
|
|
|
|
| 87 |
"""
|
| 88 |
if not USE_HF_HUB:
|
| 89 |
# Return local path for development
|
| 90 |
+
# Priority: 1) LOCAL_DATASETS_PATH env var, 2) ../data/hf_dataset
|
| 91 |
if LOCAL_DATASETS_PATH:
|
| 92 |
local_path = Path(LOCAL_DATASETS_PATH)
|
| 93 |
else:
|
| 94 |
local_path = Path("../data/hf_dataset")
|
|
|
|
|
|
|
| 95 |
if not local_path.exists():
|
| 96 |
print(f"⚠️ Warning: Local datasets path does not exist: {local_path}")
|
| 97 |
return local_path
|
|
|
|
| 102 |
repo_id=HF_REPO_ID,
|
| 103 |
repo_type="dataset",
|
| 104 |
token=HF_TOKEN,
|
| 105 |
+
allow_patterns=None,
|
| 106 |
cache_dir=HF_CACHE_DIR,
|
| 107 |
)
|
| 108 |
|
| 109 |
+
datasets_path = Path(local_dir)
|
| 110 |
print(f"✅ Datasets cached at: {datasets_path}")
|
| 111 |
return datasets_path
|
| 112 |
|
|
|
|
| 133 |
pass
|
| 134 |
|
| 135 |
# Fallback: Local development path
|
| 136 |
+
# Priority: 1) LOCAL_CONFIG_PATH env var, 2) ../config,
|
| 137 |
if LOCAL_CONFIG_PATH:
|
| 138 |
local_path = Path(LOCAL_CONFIG_PATH)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
|
| 140 |
if local_path.exists():
|
| 141 |
print(f"📁 Using local config: {local_path}")
|
|
|
|
| 186 |
return local_path
|
| 187 |
|
| 188 |
# For HF Hub, features are in the same repo as results
|
| 189 |
+
print(f"📥 Downloading features from HuggingFace Hub: {HF_OUTPUT_REPO_ID}")
|
| 190 |
|
| 191 |
local_dir = snapshot_download(
|
| 192 |
+
repo_id=HF_OUTPUT_REPO_ID,
|
| 193 |
repo_type="dataset",
|
| 194 |
token=HF_TOKEN,
|
| 195 |
+
allow_patterns=["features/**"],
|
| 196 |
cache_dir=HF_CACHE_DIR,
|
| 197 |
)
|
| 198 |
|
| 199 |
+
features_path = Path(local_dir) / "features"
|
| 200 |
print(f"✅ Features cached at: {features_path}")
|
| 201 |
return features_path
|
| 202 |
|
src/tab.py
CHANGED
|
@@ -221,6 +221,26 @@ def update_horizon_choices(display_name):
|
|
| 221 |
return gr.Radio(choices=choices, value=current_value)
|
| 222 |
|
| 223 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 224 |
def update_series_variate_and_window(display_name, horizon):
|
| 225 |
"""
|
| 226 |
根据 dataset display_name 和 horizon 更新 series, variate, window 的下拉选项
|
|
@@ -697,7 +717,7 @@ def plot_window_series(display_name, series, variate, window_id, horizon, select
|
|
| 697 |
yaxis=dict(showgrid=True, gridcolor='lightgray', gridwidth=1)
|
| 698 |
)
|
| 699 |
|
| 700 |
-
|
| 701 |
# Create info message for prediction window
|
| 702 |
if timestamps is not None and test_window_start_idx is not None and test_window_end_idx is not None:
|
| 703 |
pred_start_ts = timestamps[test_window_start_idx]
|
|
@@ -889,23 +909,26 @@ def init_per_dataset_tab(demo):
|
|
| 889 |
elem_classes="markdown-text"
|
| 890 |
)
|
| 891 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 892 |
with gr.Row():
|
| 893 |
with gr.Column(scale=1):
|
| 894 |
horizons = gr.CheckboxGroup(
|
| 895 |
-
choices=
|
| 896 |
-
value=
|
| 897 |
label="Horizons"
|
| 898 |
)
|
| 899 |
|
| 900 |
dataset_dropdown = gr.Dropdown(
|
| 901 |
choices=DATASET_CHOICES,
|
| 902 |
-
value=
|
| 903 |
label="Dataset",
|
| 904 |
interactive=True
|
| 905 |
)
|
| 906 |
|
| 907 |
# Initialize series and variate dropdowns
|
| 908 |
-
initial_dataset = DATASET_CHOICES[0]
|
| 909 |
series_dropdown, variate_dropdown = update_series_and_variate(
|
| 910 |
initial_dataset
|
| 911 |
)
|
|
@@ -913,15 +936,23 @@ def init_per_dataset_tab(demo):
|
|
| 913 |
msg = gr.Textbox(label="Message", interactive=False)
|
| 914 |
table = gr.DataFrame(elem_classes="custom-table", interactive=False)
|
| 915 |
|
| 916 |
-
# Update series and variate dropdowns when dataset changes
|
| 917 |
dataset_dropdown.change(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 918 |
fn=update_series_and_variate,
|
| 919 |
inputs=[dataset_dropdown],
|
| 920 |
outputs=[series_dropdown, variate_dropdown],
|
|
|
|
|
|
|
|
|
|
|
|
|
| 921 |
)
|
| 922 |
|
| 923 |
-
# Update leaderboard when
|
| 924 |
-
for comp in [
|
| 925 |
comp.change(
|
| 926 |
fn=get_dataset_multilevel_leaderboard,
|
| 927 |
inputs=[dataset_dropdown, series_dropdown, variate_dropdown, horizons],
|
|
|
|
| 221 |
return gr.Radio(choices=choices, value=current_value)
|
| 222 |
|
| 223 |
|
| 224 |
+
def update_horizon_checkbox_choices(display_name):
|
| 225 |
+
"""
|
| 226 |
+
根据数据集更新horizon CheckboxGroup组件的choices和value
|
| 227 |
+
用于 Per Dataset tab
|
| 228 |
+
|
| 229 |
+
Args:
|
| 230 |
+
display_name: Dataset display name from UI dropdown
|
| 231 |
+
|
| 232 |
+
Returns:
|
| 233 |
+
gr.CheckboxGroup: 更新后的CheckboxGroup组件
|
| 234 |
+
"""
|
| 235 |
+
available_horizons = get_available_horizons(display_name)
|
| 236 |
+
|
| 237 |
+
# 创建choices列表,只包含可用的horizons
|
| 238 |
+
choices = [h for h in ALL_HORIZONS if h in available_horizons]
|
| 239 |
+
|
| 240 |
+
# 默认全部选中
|
| 241 |
+
return gr.CheckboxGroup(choices=choices, value=choices)
|
| 242 |
+
|
| 243 |
+
|
| 244 |
def update_series_variate_and_window(display_name, horizon):
|
| 245 |
"""
|
| 246 |
根据 dataset display_name 和 horizon 更新 series, variate, window 的下拉选项
|
|
|
|
| 717 |
yaxis=dict(showgrid=True, gridcolor='lightgray', gridwidth=1)
|
| 718 |
)
|
| 719 |
|
| 720 |
+
|
| 721 |
# Create info message for prediction window
|
| 722 |
if timestamps is not None and test_window_start_idx is not None and test_window_end_idx is not None:
|
| 723 |
pred_start_ts = timestamps[test_window_start_idx]
|
|
|
|
| 909 |
elem_classes="markdown-text"
|
| 910 |
)
|
| 911 |
|
| 912 |
+
# Initialize horizon choices based on first dataset
|
| 913 |
+
initial_dataset = DATASET_CHOICES[0]
|
| 914 |
+
initial_horizons = get_available_horizons(initial_dataset)
|
| 915 |
+
|
| 916 |
with gr.Row():
|
| 917 |
with gr.Column(scale=1):
|
| 918 |
horizons = gr.CheckboxGroup(
|
| 919 |
+
choices=initial_horizons,
|
| 920 |
+
value=initial_horizons,
|
| 921 |
label="Horizons"
|
| 922 |
)
|
| 923 |
|
| 924 |
dataset_dropdown = gr.Dropdown(
|
| 925 |
choices=DATASET_CHOICES,
|
| 926 |
+
value=initial_dataset,
|
| 927 |
label="Dataset",
|
| 928 |
interactive=True
|
| 929 |
)
|
| 930 |
|
| 931 |
# Initialize series and variate dropdowns
|
|
|
|
| 932 |
series_dropdown, variate_dropdown = update_series_and_variate(
|
| 933 |
initial_dataset
|
| 934 |
)
|
|
|
|
| 936 |
msg = gr.Textbox(label="Message", interactive=False)
|
| 937 |
table = gr.DataFrame(elem_classes="custom-table", interactive=False)
|
| 938 |
|
| 939 |
+
# Update horizons, series, and variate dropdowns when dataset changes
|
| 940 |
dataset_dropdown.change(
|
| 941 |
+
fn=update_horizon_checkbox_choices,
|
| 942 |
+
inputs=[dataset_dropdown],
|
| 943 |
+
outputs=[horizons],
|
| 944 |
+
).then(
|
| 945 |
fn=update_series_and_variate,
|
| 946 |
inputs=[dataset_dropdown],
|
| 947 |
outputs=[series_dropdown, variate_dropdown],
|
| 948 |
+
).then(
|
| 949 |
+
fn=get_dataset_multilevel_leaderboard,
|
| 950 |
+
inputs=[dataset_dropdown, series_dropdown, variate_dropdown, horizons],
|
| 951 |
+
outputs=[msg, table]
|
| 952 |
)
|
| 953 |
|
| 954 |
+
# Update leaderboard when series, variate, or horizons change
|
| 955 |
+
for comp in [series_dropdown, variate_dropdown, horizons]:
|
| 956 |
comp.change(
|
| 957 |
fn=get_dataset_multilevel_leaderboard,
|
| 958 |
inputs=[dataset_dropdown, series_dropdown, variate_dropdown, horizons],
|