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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import time
|
| 3 |
+
import threading
|
| 4 |
+
import tkinter as tk
|
| 5 |
+
from tkinter import ttk, messagebox, filedialog
|
| 6 |
+
from huggingface_hub import HfApi, hf_hub_download
|
| 7 |
+
|
| 8 |
+
# ============================================================
|
| 9 |
+
# CONFIG
|
| 10 |
+
# ============================================================
|
| 11 |
+
|
| 12 |
+
DATASET_ID = "IGNF/FLAIR-HUB"
|
| 13 |
+
DEFAULT_DOWNLOAD_DIR = "./FLAIR-HUB_download"
|
| 14 |
+
|
| 15 |
+
os.environ["HF_HUB_DISABLE_PROGRESS_BARS"] = "1"
|
| 16 |
+
|
| 17 |
+
api = HfApi()
|
| 18 |
+
|
| 19 |
+
checkbox_state = {}
|
| 20 |
+
file_sizes = {}
|
| 21 |
+
stop_flag = threading.Event()
|
| 22 |
+
dataset_files = []
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
# ============================================================
|
| 26 |
+
# HELPER FUNCTIONS
|
| 27 |
+
# ============================================================
|
| 28 |
+
|
| 29 |
+
def human_bytes(num):
|
| 30 |
+
if num is None:
|
| 31 |
+
return "unknown"
|
| 32 |
+
for unit in ["B", "KB", "MB", "GB", "TB"]:
|
| 33 |
+
if num < 1024:
|
| 34 |
+
return f"{num:.1f} {unit}"
|
| 35 |
+
num /= 1024
|
| 36 |
+
return f"{num:.1f} PB"
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def parse_zip_metadata(path: str):
|
| 40 |
+
"""
|
| 41 |
+
Parse data ZIP filename of the form:
|
| 42 |
+
DOMAIN-YEAR_MODALITY_DATATYPE.zip
|
| 43 |
+
|
| 44 |
+
Example:
|
| 45 |
+
data/D004-2021_AERIAL_RGBI_IMS.zip
|
| 46 |
+
-> domain=D004, year=2021, modality=AERIAL_RGBI, datatype=IMS
|
| 47 |
+
"""
|
| 48 |
+
name = os.path.basename(path)
|
| 49 |
+
if not name.lower().endswith(".zip"):
|
| 50 |
+
return None
|
| 51 |
+
|
| 52 |
+
if name == "GLOBAL_ALL_MTD.zip":
|
| 53 |
+
return None
|
| 54 |
+
|
| 55 |
+
stem = name[:-4]
|
| 56 |
+
if "-" not in stem:
|
| 57 |
+
return None
|
| 58 |
+
|
| 59 |
+
domain, rest = stem.split("-", 1)
|
| 60 |
+
parts = rest.split("_")
|
| 61 |
+
year = parts[0] if parts and parts[0].isdigit() else None
|
| 62 |
+
|
| 63 |
+
modality = None
|
| 64 |
+
datatype = None
|
| 65 |
+
|
| 66 |
+
if len(parts) >= 2:
|
| 67 |
+
if len(parts) >= 3:
|
| 68 |
+
datatype = parts[-1]
|
| 69 |
+
modality = "_".join(parts[1:-1])
|
| 70 |
+
else:
|
| 71 |
+
modality = parts[1]
|
| 72 |
+
|
| 73 |
+
return {
|
| 74 |
+
"path": path,
|
| 75 |
+
"name": name,
|
| 76 |
+
"domain": domain,
|
| 77 |
+
"year": year,
|
| 78 |
+
"modality": modality,
|
| 79 |
+
"datatype": datatype,
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
# ============================================================
|
| 84 |
+
# MAIN WINDOW & STYLES
|
| 85 |
+
# ============================================================
|
| 86 |
+
|
| 87 |
+
root = tk.Tk()
|
| 88 |
+
root.title("FLAIR-HUB Dataset Download Tool")
|
| 89 |
+
root.geometry("1100x780")
|
| 90 |
+
root.minsize(860, 620)
|
| 91 |
+
|
| 92 |
+
BG_MAIN = "#020617"
|
| 93 |
+
BG_CARD = "#111827"
|
| 94 |
+
ACCENT = "#98c220"
|
| 95 |
+
ACCENT_H = "#b4de34"
|
| 96 |
+
FG_TEXT = "#e5e7eb"
|
| 97 |
+
FG_MUTED = "#9ca3af"
|
| 98 |
+
BORDER = "#1f2937"
|
| 99 |
+
|
| 100 |
+
LIST_BG = "#f9fafb"
|
| 101 |
+
LIST_FG = "#111827"
|
| 102 |
+
LIST_SEL_BG = "#d1fae5"
|
| 103 |
+
LIST_SEL_FG = "#065f46"
|
| 104 |
+
|
| 105 |
+
style = ttk.Style()
|
| 106 |
+
if "clam" in style.theme_names():
|
| 107 |
+
style.theme_use("clam")
|
| 108 |
+
|
| 109 |
+
BASE_FONT = ("Segoe UI", 10)
|
| 110 |
+
INFO_FONT = ("Consolas", 9)
|
| 111 |
+
LOG_FONT = ("Consolas", 9)
|
| 112 |
+
|
| 113 |
+
root.option_add("*Font", BASE_FONT)
|
| 114 |
+
root.configure(bg=BG_MAIN)
|
| 115 |
+
|
| 116 |
+
style.configure("TFrame", background=BG_MAIN)
|
| 117 |
+
style.configure("Card.TFrame", background=BG_CARD)
|
| 118 |
+
|
| 119 |
+
style.configure(
|
| 120 |
+
"Treeview",
|
| 121 |
+
background=LIST_BG,
|
| 122 |
+
fieldbackground=LIST_BG,
|
| 123 |
+
foreground=LIST_FG,
|
| 124 |
+
rowheight=24,
|
| 125 |
+
borderwidth=0,
|
| 126 |
+
highlightthickness=0,
|
| 127 |
+
)
|
| 128 |
+
style.map(
|
| 129 |
+
"Treeview",
|
| 130 |
+
background=[("selected", LIST_SEL_BG)],
|
| 131 |
+
foreground=[("selected", LIST_SEL_FG)],
|
| 132 |
+
)
|
| 133 |
+
|
| 134 |
+
style.configure(
|
| 135 |
+
"Accent.TButton",
|
| 136 |
+
background="#111827",
|
| 137 |
+
foreground=FG_TEXT,
|
| 138 |
+
padding=(10, 4),
|
| 139 |
+
relief="flat",
|
| 140 |
+
borderwidth=1,
|
| 141 |
+
)
|
| 142 |
+
style.map(
|
| 143 |
+
"Accent.TButton",
|
| 144 |
+
background=[
|
| 145 |
+
("active", "#1f2937"),
|
| 146 |
+
("pressed", "#111827"),
|
| 147 |
+
("disabled", "#111827"),
|
| 148 |
+
],
|
| 149 |
+
foreground=[
|
| 150 |
+
("disabled", FG_MUTED),
|
| 151 |
+
],
|
| 152 |
+
)
|
| 153 |
+
|
| 154 |
+
style.configure(
|
| 155 |
+
"Primary.TButton",
|
| 156 |
+
background=ACCENT,
|
| 157 |
+
foreground="#030712",
|
| 158 |
+
padding=(12, 5),
|
| 159 |
+
relief="flat",
|
| 160 |
+
borderwidth=0,
|
| 161 |
+
font=("Segoe UI", 10, "bold"),
|
| 162 |
+
)
|
| 163 |
+
style.map(
|
| 164 |
+
"Primary.TButton",
|
| 165 |
+
background=[
|
| 166 |
+
("active", ACCENT_H),
|
| 167 |
+
("pressed", ACCENT),
|
| 168 |
+
("disabled", "#4b5563"),
|
| 169 |
+
],
|
| 170 |
+
foreground=[
|
| 171 |
+
("disabled", "#111827"),
|
| 172 |
+
],
|
| 173 |
+
)
|
| 174 |
+
|
| 175 |
+
style.configure(
|
| 176 |
+
"Accent.Horizontal.TProgressbar",
|
| 177 |
+
troughcolor=BG_MAIN,
|
| 178 |
+
bordercolor=BG_MAIN,
|
| 179 |
+
background=ACCENT,
|
| 180 |
+
lightcolor=ACCENT,
|
| 181 |
+
darkcolor=ACCENT,
|
| 182 |
+
)
|
| 183 |
+
|
| 184 |
+
root.update_idletasks()
|
| 185 |
+
w = root.winfo_width()
|
| 186 |
+
h = root.winfo_height()
|
| 187 |
+
x = (root.winfo_screenwidth() // 2) - (w // 2)
|
| 188 |
+
y = (root.winfo_screenheight() // 2) - (h // 2)
|
| 189 |
+
root.geometry(f"{w}x{h}+{x}+{y}")
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
# ============================================================
|
| 193 |
+
# LAYOUT
|
| 194 |
+
# ============================================================
|
| 195 |
+
|
| 196 |
+
main_paned = ttk.Panedwindow(root, orient=tk.VERTICAL)
|
| 197 |
+
main_paned.pack(fill=tk.BOTH, expand=True, padx=10, pady=(8, 4))
|
| 198 |
+
|
| 199 |
+
info_outer = tk.Frame(
|
| 200 |
+
main_paned,
|
| 201 |
+
bg=BG_MAIN,
|
| 202 |
+
)
|
| 203 |
+
info_frame = tk.Frame(
|
| 204 |
+
info_outer,
|
| 205 |
+
bg=BG_CARD,
|
| 206 |
+
highlightbackground=BORDER,
|
| 207 |
+
highlightthickness=1,
|
| 208 |
+
bd=0,
|
| 209 |
+
)
|
| 210 |
+
info_frame.pack(fill=tk.BOTH, expand=True)
|
| 211 |
+
main_paned.add(info_outer, weight=1)
|
| 212 |
+
|
| 213 |
+
info_label = tk.Label(
|
| 214 |
+
info_frame,
|
| 215 |
+
text="Dataset Information",
|
| 216 |
+
font=("Segoe UI", 11, "bold"),
|
| 217 |
+
bg=BG_CARD,
|
| 218 |
+
fg=FG_TEXT,
|
| 219 |
+
)
|
| 220 |
+
info_label.pack(anchor="w", pady=(8, 4), padx=8)
|
| 221 |
+
|
| 222 |
+
info_text = tk.Text(
|
| 223 |
+
info_frame,
|
| 224 |
+
height=7,
|
| 225 |
+
wrap="word",
|
| 226 |
+
font=INFO_FONT,
|
| 227 |
+
bg=BG_MAIN,
|
| 228 |
+
fg=FG_TEXT,
|
| 229 |
+
bd=0,
|
| 230 |
+
relief="flat",
|
| 231 |
+
)
|
| 232 |
+
info_text.pack(fill=tk.BOTH, expand=True, padx=8, pady=(0, 8))
|
| 233 |
+
|
| 234 |
+
|
| 235 |
+
# ============================================================
|
| 236 |
+
# FILES AREA (filters + two-column panel)
|
| 237 |
+
# ============================================================
|
| 238 |
+
|
| 239 |
+
files_outer = tk.Frame(root, bg=BG_MAIN)
|
| 240 |
+
files_card = tk.Frame(
|
| 241 |
+
files_outer,
|
| 242 |
+
bg=BG_CARD,
|
| 243 |
+
highlightbackground=BORDER,
|
| 244 |
+
highlightthickness=1,
|
| 245 |
+
bd=0,
|
| 246 |
+
)
|
| 247 |
+
files_card.pack(fill=tk.BOTH, expand=True)
|
| 248 |
+
main_paned.add(files_outer, weight=3)
|
| 249 |
+
|
| 250 |
+
tree_frame = ttk.Frame(files_card, style="Card.TFrame")
|
| 251 |
+
tree_frame.pack(fill=tk.BOTH, expand=True, padx=6, pady=6)
|
| 252 |
+
|
| 253 |
+
filter_bar = ttk.Frame(tree_frame, padding=(4, 4), style="Card.TFrame")
|
| 254 |
+
filter_bar.pack(side=tk.TOP, fill=tk.X)
|
| 255 |
+
|
| 256 |
+
filter_title = ttk.Label(
|
| 257 |
+
filter_bar,
|
| 258 |
+
text="Filters",
|
| 259 |
+
font=("Segoe UI", 10, "bold"),
|
| 260 |
+
background=BG_CARD,
|
| 261 |
+
foreground=FG_TEXT,
|
| 262 |
+
)
|
| 263 |
+
filter_title.grid(row=0, column=0, padx=(0, 8), sticky="w")
|
| 264 |
+
|
| 265 |
+
domain_var = tk.StringVar(value="All")
|
| 266 |
+
year_var = tk.StringVar(value="All")
|
| 267 |
+
modality_var = tk.StringVar(value="All")
|
| 268 |
+
datatype_var = tk.StringVar(value="All")
|
| 269 |
+
|
| 270 |
+
domain_label = ttk.Label(filter_bar, text="Domain", background=BG_CARD, foreground=FG_MUTED)
|
| 271 |
+
year_label = ttk.Label(filter_bar, text="Year", background=BG_CARD, foreground=FG_MUTED)
|
| 272 |
+
modality_label = ttk.Label(filter_bar, text="Modality", background=BG_CARD, foreground=FG_MUTED)
|
| 273 |
+
datatype_label = ttk.Label(filter_bar, text="Data type", background=BG_CARD, foreground=FG_MUTED)
|
| 274 |
+
|
| 275 |
+
domain_cb = ttk.Combobox(filter_bar, textvariable=domain_var, state="readonly", width=12, values=["All"])
|
| 276 |
+
year_cb = ttk.Combobox(filter_bar, textvariable=year_var, state="readonly", width=8, values=["All"])
|
| 277 |
+
modality_cb = ttk.Combobox(filter_bar, textvariable=modality_var, state="readonly", width=14, values=["All"])
|
| 278 |
+
datatype_cb = ttk.Combobox(filter_bar, textvariable=datatype_var, state="readonly", width=10, values=["All"])
|
| 279 |
+
|
| 280 |
+
domain_label.grid(row=0, column=1, sticky="w", padx=(0, 2))
|
| 281 |
+
domain_cb.grid(row=0, column=2, padx=(2, 8))
|
| 282 |
+
|
| 283 |
+
year_label.grid(row=0, column=3, sticky="w", padx=(0, 2))
|
| 284 |
+
year_cb.grid(row=0, column=4, padx=(2, 8))
|
| 285 |
+
|
| 286 |
+
modality_label.grid(row=0, column=5, sticky="w", padx=(0, 2))
|
| 287 |
+
modality_cb.grid(row=0, column=6, padx=(2, 8))
|
| 288 |
+
|
| 289 |
+
datatype_label.grid(row=0, column=7, sticky="w", padx=(0, 2))
|
| 290 |
+
datatype_cb.grid(row=0, column=8, padx=(2, 8))
|
| 291 |
+
|
| 292 |
+
|
| 293 |
+
def reset_filters():
|
| 294 |
+
domain_var.set("All")
|
| 295 |
+
year_var.set("All")
|
| 296 |
+
modality_var.set("All")
|
| 297 |
+
datatype_var.set("All")
|
| 298 |
+
apply_filters()
|
| 299 |
+
|
| 300 |
+
|
| 301 |
+
def show_metadata_only():
|
| 302 |
+
domain_var.set("GLOBAL")
|
| 303 |
+
year_var.set("All")
|
| 304 |
+
modality_var.set("GLOBAL")
|
| 305 |
+
datatype_var.set("MTD")
|
| 306 |
+
apply_filters()
|
| 307 |
+
|
| 308 |
+
|
| 309 |
+
metadata_btn = ttk.Button(filter_bar, text="Metadata", style="Accent.TButton", command=show_metadata_only)
|
| 310 |
+
metadata_btn.grid(row=0, column=9, padx=(4, 0), sticky="w")
|
| 311 |
+
|
| 312 |
+
reset_btn = ttk.Button(filter_bar, text="Reset", style="Accent.TButton", command=reset_filters)
|
| 313 |
+
reset_btn.grid(row=0, column=10, padx=(4, 0), sticky="w")
|
| 314 |
+
|
| 315 |
+
for col in range(11):
|
| 316 |
+
filter_bar.columnconfigure(col, weight=0)
|
| 317 |
+
|
| 318 |
+
files_split = ttk.Panedwindow(tree_frame, orient=tk.HORIZONTAL)
|
| 319 |
+
files_split.pack(side=tk.TOP, fill=tk.BOTH, expand=True, pady=(4, 0))
|
| 320 |
+
|
| 321 |
+
left_files_frame = ttk.Frame(files_split, padding=(0, 4), style="Card.TFrame")
|
| 322 |
+
files_split.add(left_files_frame, weight=3)
|
| 323 |
+
|
| 324 |
+
left_label = ttk.Label(
|
| 325 |
+
left_files_frame,
|
| 326 |
+
text="Available files",
|
| 327 |
+
font=("Segoe UI", 10, "bold"),
|
| 328 |
+
background=BG_CARD,
|
| 329 |
+
foreground=FG_TEXT,
|
| 330 |
+
)
|
| 331 |
+
left_label.pack(anchor="w", padx=(2, 0))
|
| 332 |
+
|
| 333 |
+
left_container = ttk.Frame(left_files_frame, style="Card.TFrame")
|
| 334 |
+
left_container.pack(fill=tk.BOTH, expand=True, pady=(2, 0))
|
| 335 |
+
|
| 336 |
+
left_scroll = ttk.Scrollbar(left_container, orient=tk.VERTICAL)
|
| 337 |
+
left_scroll.pack(side=tk.RIGHT, fill=tk.Y)
|
| 338 |
+
|
| 339 |
+
file_tree = ttk.Treeview(left_container, yscrollcommand=left_scroll.set, selectmode="none")
|
| 340 |
+
file_tree.pack(fill=tk.BOTH, expand=True)
|
| 341 |
+
left_scroll.config(command=file_tree.yview)
|
| 342 |
+
|
| 343 |
+
file_tree["columns"] = ()
|
| 344 |
+
file_tree.column("#0", anchor=tk.W, stretch=True)
|
| 345 |
+
file_tree["show"] = "tree"
|
| 346 |
+
|
| 347 |
+
right_selected_frame = ttk.Frame(files_split, padding=(8, 4), style="Card.TFrame")
|
| 348 |
+
files_split.add(right_selected_frame, weight=2)
|
| 349 |
+
|
| 350 |
+
right_title_bar = tk.Frame(right_selected_frame, bg=BG_CARD)
|
| 351 |
+
right_title_bar.pack(fill=tk.X, pady=(0, 2))
|
| 352 |
+
|
| 353 |
+
right_label = tk.Label(
|
| 354 |
+
right_title_bar,
|
| 355 |
+
text="Selected files",
|
| 356 |
+
font=("Segoe UI", 10, "bold"),
|
| 357 |
+
bg=BG_CARD,
|
| 358 |
+
fg=FG_TEXT,
|
| 359 |
+
)
|
| 360 |
+
right_label.pack(side=tk.LEFT)
|
| 361 |
+
|
| 362 |
+
badge_label = tk.Label(
|
| 363 |
+
right_title_bar,
|
| 364 |
+
text="[ 0 file — 0 ]",
|
| 365 |
+
font=("Segoe UI", 9, "bold"),
|
| 366 |
+
bg=ACCENT,
|
| 367 |
+
fg="#111827",
|
| 368 |
+
padx=8,
|
| 369 |
+
pady=2,
|
| 370 |
+
)
|
| 371 |
+
badge_label.pack(side=tk.RIGHT, padx=4)
|
| 372 |
+
|
| 373 |
+
|
| 374 |
+
selected_container = ttk.Frame(right_selected_frame, style="Card.TFrame")
|
| 375 |
+
selected_container.pack(fill=tk.BOTH, expand=True, pady=(2, 0))
|
| 376 |
+
|
| 377 |
+
selected_scroll = ttk.Scrollbar(selected_container, orient=tk.VERTICAL)
|
| 378 |
+
selected_scroll.pack(side=tk.RIGHT, fill=tk.Y)
|
| 379 |
+
|
| 380 |
+
selected_listbox = tk.Listbox(
|
| 381 |
+
selected_container,
|
| 382 |
+
height=10,
|
| 383 |
+
font=LOG_FONT,
|
| 384 |
+
bg=LIST_BG,
|
| 385 |
+
fg=LIST_FG,
|
| 386 |
+
bd=0,
|
| 387 |
+
relief="flat",
|
| 388 |
+
selectbackground=LIST_SEL_BG,
|
| 389 |
+
selectforeground=LIST_SEL_FG,
|
| 390 |
+
)
|
| 391 |
+
selected_listbox.pack(fill=tk.BOTH, expand=True)
|
| 392 |
+
selected_listbox.config(yscrollcommand=selected_scroll.set)
|
| 393 |
+
selected_scroll.config(command=selected_listbox.yview)
|
| 394 |
+
|
| 395 |
+
def update_selected_panel():
|
| 396 |
+
"""Refresh the right-hand 'selected files' list and the badge."""
|
| 397 |
+
selected_listbox.delete(0, tk.END)
|
| 398 |
+
|
| 399 |
+
total_bytes = 0
|
| 400 |
+
selected_items = [m for m in dataset_files if checkbox_state.get(m["path"], False)]
|
| 401 |
+
|
| 402 |
+
for meta in sorted(selected_items, key=lambda m: m["name"]):
|
| 403 |
+
selected_listbox.insert(tk.END, meta["name"])
|
| 404 |
+
if meta.get("size_bytes") is not None:
|
| 405 |
+
total_bytes += meta["size_bytes"]
|
| 406 |
+
|
| 407 |
+
count = len(selected_items)
|
| 408 |
+
size_str = human_bytes(total_bytes) if total_bytes > 0 else "0"
|
| 409 |
+
|
| 410 |
+
badge_label.config(
|
| 411 |
+
text=f"[ {count} file{'s' if count != 1 else ''} — {size_str} ]"
|
| 412 |
+
)
|
| 413 |
+
|
| 414 |
+
|
| 415 |
+
# ============================================================
|
| 416 |
+
# BOTTOM CONTROLS / LOGS
|
| 417 |
+
# ============================================================
|
| 418 |
+
|
| 419 |
+
bottom_outer = tk.Frame(root, bg=BG_MAIN)
|
| 420 |
+
bottom_card = tk.Frame(
|
| 421 |
+
bottom_outer,
|
| 422 |
+
bg=BG_CARD,
|
| 423 |
+
highlightbackground=BORDER,
|
| 424 |
+
highlightthickness=1,
|
| 425 |
+
bd=0,
|
| 426 |
+
)
|
| 427 |
+
bottom_card.pack(fill=tk.X, padx=10, pady=(2, 0))
|
| 428 |
+
bottom_outer.pack(fill=tk.X)
|
| 429 |
+
|
| 430 |
+
bottom_frame = ttk.Frame(bottom_card, padding=(10, 8), style="Card.TFrame")
|
| 431 |
+
bottom_frame.pack(fill=tk.X)
|
| 432 |
+
|
| 433 |
+
path_label = ttk.Label(bottom_frame, text="Download to:", background=BG_CARD, foreground=FG_MUTED)
|
| 434 |
+
path_label.grid(row=0, column=0, sticky="w")
|
| 435 |
+
|
| 436 |
+
download_path = ttk.Entry(bottom_frame)
|
| 437 |
+
download_path.insert(0, DEFAULT_DOWNLOAD_DIR)
|
| 438 |
+
download_path.grid(row=0, column=1, sticky="ew", padx=(6, 6))
|
| 439 |
+
|
| 440 |
+
|
| 441 |
+
def choose_folder():
|
| 442 |
+
folder = filedialog.askdirectory()
|
| 443 |
+
if folder:
|
| 444 |
+
download_path.delete(0, tk.END)
|
| 445 |
+
download_path.insert(0, folder)
|
| 446 |
+
|
| 447 |
+
|
| 448 |
+
browse_btn = ttk.Button(bottom_frame, text="📂 Browse…", style="Accent.TButton", command=choose_folder)
|
| 449 |
+
browse_btn.grid(row=0, column=2, sticky="ew")
|
| 450 |
+
|
| 451 |
+
btn_frame = ttk.Frame(bottom_frame, style="Card.TFrame")
|
| 452 |
+
btn_frame.grid(row=0, column=3, sticky="e", padx=(10, 0))
|
| 453 |
+
|
| 454 |
+
select_all_btn = ttk.Button(btn_frame, text="Select All", style="Accent.TButton")
|
| 455 |
+
unselect_all_btn = ttk.Button(btn_frame, text="Unselect All", style="Accent.TButton")
|
| 456 |
+
download_btn = ttk.Button(btn_frame, text="⬇ Download", style="Primary.TButton")
|
| 457 |
+
stop_btn = ttk.Button(btn_frame, text="⛔ Stop", style="Accent.TButton", state="disabled")
|
| 458 |
+
|
| 459 |
+
select_all_btn.pack(side=tk.LEFT, padx=(0, 4))
|
| 460 |
+
unselect_all_btn.pack(side=tk.LEFT, padx=(0, 4))
|
| 461 |
+
download_btn.pack(side=tk.LEFT, padx=(0, 4))
|
| 462 |
+
stop_btn.pack(side=tk.LEFT)
|
| 463 |
+
|
| 464 |
+
bottom_frame.columnconfigure(1, weight=1)
|
| 465 |
+
|
| 466 |
+
status_outer = tk.Frame(root, bg=BG_MAIN)
|
| 467 |
+
status_card = tk.Frame(
|
| 468 |
+
status_outer,
|
| 469 |
+
bg=BG_CARD,
|
| 470 |
+
highlightbackground=BORDER,
|
| 471 |
+
highlightthickness=1,
|
| 472 |
+
bd=0,
|
| 473 |
+
)
|
| 474 |
+
status_card.pack(fill=tk.X, padx=10, pady=(4, 0))
|
| 475 |
+
status_outer.pack(fill=tk.X)
|
| 476 |
+
|
| 477 |
+
status_frame = ttk.Frame(status_card, padding=(10, 4), style="Card.TFrame")
|
| 478 |
+
status_frame.pack(fill=tk.X)
|
| 479 |
+
|
| 480 |
+
status_label = ttk.Label(status_frame, text="Ready.", background=BG_CARD, foreground=FG_MUTED)
|
| 481 |
+
status_label.pack(side=tk.LEFT)
|
| 482 |
+
|
| 483 |
+
progress = ttk.Progressbar(status_frame, mode="indeterminate", length=220, style="Accent.Horizontal.TProgressbar")
|
| 484 |
+
progress.pack(side=tk.RIGHT)
|
| 485 |
+
|
| 486 |
+
log_outer = tk.Frame(root, bg=BG_MAIN)
|
| 487 |
+
log_card = tk.Frame(
|
| 488 |
+
log_outer,
|
| 489 |
+
bg=BG_CARD,
|
| 490 |
+
highlightbackground=BORDER,
|
| 491 |
+
highlightthickness=1,
|
| 492 |
+
bd=0,
|
| 493 |
+
)
|
| 494 |
+
log_card.pack(fill=tk.BOTH, expand=True, padx=10, pady=(4, 8))
|
| 495 |
+
log_outer.pack(fill=tk.BOTH, expand=True)
|
| 496 |
+
|
| 497 |
+
log_frame = ttk.Frame(log_card, padding=4, style="Card.TFrame")
|
| 498 |
+
log_frame.pack(fill=tk.BOTH, expand=True)
|
| 499 |
+
|
| 500 |
+
log_scroll = ttk.Scrollbar(log_frame, orient=tk.VERTICAL)
|
| 501 |
+
log_scroll.pack(side=tk.RIGHT, fill=tk.Y)
|
| 502 |
+
|
| 503 |
+
log_text = tk.Text(
|
| 504 |
+
log_frame,
|
| 505 |
+
height=10,
|
| 506 |
+
wrap="none",
|
| 507 |
+
font=LOG_FONT,
|
| 508 |
+
bg=BG_MAIN,
|
| 509 |
+
fg=FG_TEXT,
|
| 510 |
+
bd=0,
|
| 511 |
+
relief="flat",
|
| 512 |
+
)
|
| 513 |
+
log_text.pack(fill=tk.BOTH, expand=True)
|
| 514 |
+
log_text.config(state="disabled")
|
| 515 |
+
log_scroll.config(command=log_text.yview)
|
| 516 |
+
log_text.config(yscrollcommand=log_scroll.set)
|
| 517 |
+
|
| 518 |
+
|
| 519 |
+
def append_log(line: str):
|
| 520 |
+
log_text.config(state="normal")
|
| 521 |
+
log_text.insert("end", line + "\n")
|
| 522 |
+
log_text.see("end")
|
| 523 |
+
log_text.config(state="disabled")
|
| 524 |
+
|
| 525 |
+
|
| 526 |
+
def clear_log():
|
| 527 |
+
log_text.config(state="normal")
|
| 528 |
+
log_text.delete("1.0", "end")
|
| 529 |
+
log_text.config(state="disabled")
|
| 530 |
+
|
| 531 |
+
|
| 532 |
+
# ============================================================
|
| 533 |
+
# TREE / CHECKBOX LOGIC
|
| 534 |
+
# ============================================================
|
| 535 |
+
|
| 536 |
+
def refresh_checkboxes():
|
| 537 |
+
"""Update tree item text based on checkbox_state."""
|
| 538 |
+
for iid in file_tree.get_children(""):
|
| 539 |
+
checked = checkbox_state.get(iid, False)
|
| 540 |
+
meta = next((f for f in dataset_files if f["path"] == iid), None)
|
| 541 |
+
if meta is None:
|
| 542 |
+
continue
|
| 543 |
+
prefix = "☑ " if checked else "☐ "
|
| 544 |
+
file_tree.item(iid, text=f"{prefix}{meta['name']}")
|
| 545 |
+
update_selected_panel()
|
| 546 |
+
|
| 547 |
+
|
| 548 |
+
def apply_filters(*_):
|
| 549 |
+
"""Rebuild the left tree based on current filter values."""
|
| 550 |
+
file_tree.delete(*file_tree.get_children(""))
|
| 551 |
+
|
| 552 |
+
d_filter = domain_var.get()
|
| 553 |
+
y_filter = year_var.get()
|
| 554 |
+
m_filter = modality_var.get()
|
| 555 |
+
t_filter = datatype_var.get()
|
| 556 |
+
|
| 557 |
+
for meta in dataset_files:
|
| 558 |
+
if d_filter != "All" and meta["domain"] != d_filter:
|
| 559 |
+
continue
|
| 560 |
+
if y_filter != "All" and meta["year"] != y_filter:
|
| 561 |
+
continue
|
| 562 |
+
if m_filter != "All" and meta["modality"] != m_filter:
|
| 563 |
+
continue
|
| 564 |
+
if t_filter != "All" and meta["datatype"] != t_filter:
|
| 565 |
+
continue
|
| 566 |
+
|
| 567 |
+
path = meta["path"]
|
| 568 |
+
if path not in checkbox_state:
|
| 569 |
+
checkbox_state[path] = False
|
| 570 |
+
|
| 571 |
+
checked = checkbox_state[path]
|
| 572 |
+
prefix = "☑ " if checked else "☐ "
|
| 573 |
+
file_tree.insert("", "end", iid=path, text=f"{prefix}{meta['name']}")
|
| 574 |
+
|
| 575 |
+
update_selected_panel()
|
| 576 |
+
|
| 577 |
+
|
| 578 |
+
def toggle_all(state: bool):
|
| 579 |
+
"""Select/unselect only currently visible (filtered) files."""
|
| 580 |
+
for iid in file_tree.get_children(""):
|
| 581 |
+
checkbox_state[iid] = state
|
| 582 |
+
refresh_checkboxes()
|
| 583 |
+
status_label.config(text=f"{'Selected' if state else 'Unselected'} filtered files.")
|
| 584 |
+
|
| 585 |
+
|
| 586 |
+
def on_tree_click(event):
|
| 587 |
+
region = file_tree.identify("region", event.x, event.y)
|
| 588 |
+
column = file_tree.identify_column(event.x)
|
| 589 |
+
row = file_tree.identify_row(event.y)
|
| 590 |
+
|
| 591 |
+
if region == "tree" and column == "#0" and row:
|
| 592 |
+
bbox = file_tree.bbox(row)
|
| 593 |
+
if bbox and event.x > bbox[0] + 20:
|
| 594 |
+
current = checkbox_state.get(row, False)
|
| 595 |
+
checkbox_state[row] = not current
|
| 596 |
+
refresh_checkboxes()
|
| 597 |
+
|
| 598 |
+
|
| 599 |
+
file_tree.bind("<Button-1>", on_tree_click)
|
| 600 |
+
|
| 601 |
+
|
| 602 |
+
# ============================================================
|
| 603 |
+
# DATASET LOAD
|
| 604 |
+
# ============================================================
|
| 605 |
+
|
| 606 |
+
def load_dataset():
|
| 607 |
+
global file_sizes, dataset_files
|
| 608 |
+
info_text.delete(1.0, tk.END)
|
| 609 |
+
file_tree.delete(*file_tree.get_children(""))
|
| 610 |
+
checkbox_state.clear()
|
| 611 |
+
file_sizes = {}
|
| 612 |
+
dataset_files = []
|
| 613 |
+
|
| 614 |
+
status_label.config(text="Contacting Hugging Face API…")
|
| 615 |
+
root.update_idletasks()
|
| 616 |
+
|
| 617 |
+
try:
|
| 618 |
+
info = api.dataset_info(DATASET_ID, files_metadata=True)
|
| 619 |
+
except Exception as e:
|
| 620 |
+
messagebox.showerror("Error", f"Failed to load: {e}")
|
| 621 |
+
status_label.config(text="Failed to load dataset.")
|
| 622 |
+
return
|
| 623 |
+
|
| 624 |
+
created = info.created_at.strftime("%Y-%m-%d %H:%M") if info.created_at else "N/A"
|
| 625 |
+
modified = info.lastModified.strftime("%Y-%m-%d %H:%M") if info.lastModified else "N/A"
|
| 626 |
+
size = getattr(info, "usedStorage", 0) or 0
|
| 627 |
+
size_str = f"{size/1e9:.2f} GB" if size > 1e9 else f"{size/1e6:.2f} MB"
|
| 628 |
+
|
| 629 |
+
meta_info = f"""
|
| 630 |
+
ID : {info.id}
|
| 631 |
+
Author : {info.author or 'Unknown'}
|
| 632 |
+
Created : {created}
|
| 633 |
+
Modified : {modified}
|
| 634 |
+
Size : {size_str}
|
| 635 |
+
Downloads : {info.downloads or 0}
|
| 636 |
+
Likes : {info.likes or 0}
|
| 637 |
+
Tags : {', '.join(info.tags or [])}
|
| 638 |
+
Tasks : {', '.join((info.cardData or {}).get('task_categories', []))}
|
| 639 |
+
""".rstrip()
|
| 640 |
+
|
| 641 |
+
info_text.insert(tk.END, meta_info)
|
| 642 |
+
|
| 643 |
+
for s in info.siblings:
|
| 644 |
+
path = s.rfilename
|
| 645 |
+
|
| 646 |
+
if path.endswith("GLOBAL_ALL_MTD.zip"):
|
| 647 |
+
size_attr = getattr(s, "size", None)
|
| 648 |
+
m = {
|
| 649 |
+
"path": path,
|
| 650 |
+
"name": os.path.basename(path),
|
| 651 |
+
"domain": "GLOBAL",
|
| 652 |
+
"year": None,
|
| 653 |
+
"modality": "GLOBAL",
|
| 654 |
+
"datatype": "MTD",
|
| 655 |
+
"size_bytes": size_attr,
|
| 656 |
+
}
|
| 657 |
+
dataset_files.append(m)
|
| 658 |
+
if size_attr is not None:
|
| 659 |
+
file_sizes[path] = size_attr
|
| 660 |
+
continue
|
| 661 |
+
|
| 662 |
+
if not path.startswith("data/"):
|
| 663 |
+
continue
|
| 664 |
+
if not path.lower().endswith(".zip"):
|
| 665 |
+
continue
|
| 666 |
+
|
| 667 |
+
m = parse_zip_metadata(path)
|
| 668 |
+
if m is None:
|
| 669 |
+
continue
|
| 670 |
+
|
| 671 |
+
size_attr = getattr(s, "size", None)
|
| 672 |
+
m["size_bytes"] = size_attr
|
| 673 |
+
dataset_files.append(m)
|
| 674 |
+
|
| 675 |
+
if size_attr is not None:
|
| 676 |
+
file_sizes[path] = size_attr
|
| 677 |
+
|
| 678 |
+
domains = sorted({f["domain"] for f in dataset_files if f["domain"]})
|
| 679 |
+
years = sorted({f["year"] for f in dataset_files if f["year"]})
|
| 680 |
+
modalities = sorted({f["modality"] for f in dataset_files if f["modality"]})
|
| 681 |
+
datatypes = sorted({f["datatype"] for f in dataset_files if f["datatype"]})
|
| 682 |
+
|
| 683 |
+
domain_cb["values"] = ["All"] + domains
|
| 684 |
+
year_cb["values"] = ["All"] + years
|
| 685 |
+
modality_cb["values"] = ["All"] + modalities
|
| 686 |
+
datatype_cb["values"] = ["All"] + datatypes
|
| 687 |
+
|
| 688 |
+
domain_var.set("All")
|
| 689 |
+
year_var.set("All")
|
| 690 |
+
modality_var.set("All")
|
| 691 |
+
datatype_var.set("All")
|
| 692 |
+
|
| 693 |
+
apply_filters()
|
| 694 |
+
|
| 695 |
+
status_label.config(text=f"Loaded {len(dataset_files)} ZIP files from FLAIR-HUB (tiles + metadata).")
|
| 696 |
+
append_log("=== Dataset loaded: FLAIR-HUB (data/*.zip + GLOBAL_ALL_MTD.zip) ===")
|
| 697 |
+
|
| 698 |
+
|
| 699 |
+
# ============================================================
|
| 700 |
+
# DOWNLOAD LOGIC
|
| 701 |
+
# ============================================================
|
| 702 |
+
|
| 703 |
+
def stop_download():
|
| 704 |
+
stop_flag.set()
|
| 705 |
+
status_label.config(text="⏹ Stop requested. Finishing current file…")
|
| 706 |
+
stop_btn.config(state="disabled")
|
| 707 |
+
append_log("⛔ Stop requested by user.")
|
| 708 |
+
|
| 709 |
+
|
| 710 |
+
def download_selected():
|
| 711 |
+
folder = download_path.get().strip()
|
| 712 |
+
os.makedirs(folder, exist_ok=True)
|
| 713 |
+
|
| 714 |
+
files_to_download = [
|
| 715 |
+
iid for iid in file_tree.get_children("")
|
| 716 |
+
if checkbox_state.get(iid, False)
|
| 717 |
+
]
|
| 718 |
+
|
| 719 |
+
if not files_to_download:
|
| 720 |
+
messagebox.showinfo("No Selection", "No files selected (in current filter).")
|
| 721 |
+
return
|
| 722 |
+
|
| 723 |
+
total = len(files_to_download)
|
| 724 |
+
stop_flag.clear()
|
| 725 |
+
|
| 726 |
+
download_btn.config(state="disabled")
|
| 727 |
+
select_all_btn.config(state="disabled")
|
| 728 |
+
unselect_all_btn.config(state="disabled")
|
| 729 |
+
browse_btn.config(state="disabled")
|
| 730 |
+
stop_btn.config(state="normal")
|
| 731 |
+
|
| 732 |
+
progress["mode"] = "indeterminate"
|
| 733 |
+
progress.start(15)
|
| 734 |
+
status_label.config(text=f"🚀 Launching download: {total} file(s)…")
|
| 735 |
+
append_log(f"=== Download session started: {total} file(s) ===")
|
| 736 |
+
|
| 737 |
+
def worker():
|
| 738 |
+
t_session = time.time()
|
| 739 |
+
processed = 0
|
| 740 |
+
|
| 741 |
+
for index, fid in enumerate(files_to_download, start=1):
|
| 742 |
+
if stop_flag.is_set():
|
| 743 |
+
append_log("⛔ Download stopped by user.")
|
| 744 |
+
break
|
| 745 |
+
|
| 746 |
+
processed += 1
|
| 747 |
+
|
| 748 |
+
meta = next((f for f in dataset_files if f["path"] == fid), None)
|
| 749 |
+
name = meta["name"] if meta else fid
|
| 750 |
+
planned = meta["size_bytes"] if meta else None
|
| 751 |
+
size_info = human_bytes(planned) if planned else "unknown"
|
| 752 |
+
|
| 753 |
+
def set_label(f=name, i=index):
|
| 754 |
+
status_label.config(text=f"({i}/{total}) Downloading: {f}")
|
| 755 |
+
root.after(0, set_label)
|
| 756 |
+
|
| 757 |
+
root.after(
|
| 758 |
+
0,
|
| 759 |
+
lambda f=name, i=index, s=size_info: append_log(
|
| 760 |
+
f"▶ [{i}/{total}] {f} :: size ~ {s}"
|
| 761 |
+
),
|
| 762 |
+
)
|
| 763 |
+
|
| 764 |
+
t0 = time.time()
|
| 765 |
+
local_path = None
|
| 766 |
+
error = None
|
| 767 |
+
|
| 768 |
+
try:
|
| 769 |
+
local_path = hf_hub_download(
|
| 770 |
+
repo_id=DATASET_ID,
|
| 771 |
+
repo_type="dataset",
|
| 772 |
+
filename=fid,
|
| 773 |
+
local_dir=folder,
|
| 774 |
+
force_download=True,
|
| 775 |
+
)
|
| 776 |
+
except Exception as e:
|
| 777 |
+
error = e
|
| 778 |
+
|
| 779 |
+
elapsed = max(time.time() - t0, 1e-3)
|
| 780 |
+
|
| 781 |
+
size_bytes = planned
|
| 782 |
+
if size_bytes is None and local_path and os.path.exists(local_path):
|
| 783 |
+
try:
|
| 784 |
+
size_bytes = os.path.getsize(local_path)
|
| 785 |
+
except OSError:
|
| 786 |
+
size_bytes = None
|
| 787 |
+
|
| 788 |
+
if size_bytes and elapsed > 0:
|
| 789 |
+
speed_mbps = (size_bytes / elapsed) / (1024 * 1024)
|
| 790 |
+
else:
|
| 791 |
+
speed_mbps = None
|
| 792 |
+
|
| 793 |
+
if error is None:
|
| 794 |
+
size_h = human_bytes(size_bytes)
|
| 795 |
+
if speed_mbps is not None:
|
| 796 |
+
summary = f" ✅ Avg speed: {speed_mbps:.1f} MB/s | {size_h} in {elapsed:.1f}s"
|
| 797 |
+
else:
|
| 798 |
+
summary = f" ✅ {size_h} in {elapsed:.1f}s"
|
| 799 |
+
else:
|
| 800 |
+
summary = f" ❌ ERROR: {error}"
|
| 801 |
+
|
| 802 |
+
def push_summary(line=summary):
|
| 803 |
+
append_log(line)
|
| 804 |
+
append_log("")
|
| 805 |
+
root.after(0, push_summary)
|
| 806 |
+
|
| 807 |
+
def finish():
|
| 808 |
+
progress.stop()
|
| 809 |
+
stop_btn.config(state="disabled")
|
| 810 |
+
download_btn.config(state="normal")
|
| 811 |
+
select_all_btn.config(state="normal")
|
| 812 |
+
unselect_all_btn.config(state="normal")
|
| 813 |
+
browse_btn.config(state="normal")
|
| 814 |
+
|
| 815 |
+
session_time = time.time() - t_session
|
| 816 |
+
append_log(f"=== Download session ended :: {session_time:.1f}s ===")
|
| 817 |
+
|
| 818 |
+
if stop_flag.is_set():
|
| 819 |
+
status_label.config(text="⛔ Download stopped.")
|
| 820 |
+
messagebox.showinfo("Stopped", "Downloads were stopped.")
|
| 821 |
+
else:
|
| 822 |
+
status_label.config(text=f"✅ Completed. Processed {processed} file(s).")
|
| 823 |
+
messagebox.showinfo(
|
| 824 |
+
"Download Complete",
|
| 825 |
+
f"Download finished.\nProcessed {processed} file(s) in {session_time:.1f}s.",
|
| 826 |
+
)
|
| 827 |
+
|
| 828 |
+
root.after(0, finish)
|
| 829 |
+
|
| 830 |
+
threading.Thread(target=worker, daemon=True).start()
|
| 831 |
+
|
| 832 |
+
|
| 833 |
+
# ============================================================
|
| 834 |
+
# WIRING
|
| 835 |
+
# ============================================================
|
| 836 |
+
|
| 837 |
+
select_all_btn.config(command=lambda: toggle_all(True))
|
| 838 |
+
unselect_all_btn.config(command=lambda: toggle_all(False))
|
| 839 |
+
download_btn.config(command=download_selected)
|
| 840 |
+
stop_btn.config(command=stop_download)
|
| 841 |
+
|
| 842 |
+
domain_cb.bind("<<ComboboxSelected>>", apply_filters)
|
| 843 |
+
year_cb.bind("<<ComboboxSelected>>", apply_filters)
|
| 844 |
+
modality_cb.bind("<<ComboboxSelected>>", apply_filters)
|
| 845 |
+
datatype_cb.bind("<<ComboboxSelected>>", apply_filters)
|
| 846 |
+
|
| 847 |
+
load_dataset()
|
| 848 |
+
|
| 849 |
+
root.mainloop()
|