Candle commited on
Commit ·
07ef62b
1
Parent(s): 0729203
fixes
Browse files- loop_labeler_ui.py +60 -0
loop_labeler_ui.py
CHANGED
|
@@ -154,6 +154,10 @@ class LoopLabeler(QWidget):
|
|
| 154 |
|
| 155 |
def load_json(self, json_path):
|
| 156 |
self.current_json = json_path
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
try:
|
| 158 |
with open(json_path) as f:
|
| 159 |
self.loop_candidates = json.load(f)
|
|
@@ -196,15 +200,24 @@ class LoopLabeler(QWidget):
|
|
| 196 |
if not self.frames:
|
| 197 |
print(f"No frames found in {webp_path}")
|
| 198 |
|
|
|
|
| 199 |
self.update_candidate()
|
|
|
|
|
|
|
|
|
|
| 200 |
|
| 201 |
def on_file_selected(self, idx):
|
| 202 |
if idx >= 0 and idx < len(self.json_files):
|
|
|
|
|
|
|
|
|
|
| 203 |
self.load_json(self.json_files[idx])
|
| 204 |
|
| 205 |
def on_candidate_changed(self, idx):
|
| 206 |
if 0 <= idx < len(self.loop_candidates):
|
| 207 |
self.current_candidate = idx
|
|
|
|
|
|
|
| 208 |
self.update_candidate()
|
| 209 |
else:
|
| 210 |
self.current_candidate = 0
|
|
@@ -215,6 +228,10 @@ class LoopLabeler(QWidget):
|
|
| 215 |
self.start_spin.setMaximum(nframes-1 if nframes > 0 else 0)
|
| 216 |
self.end_spin.setMaximum(nframes-1 if nframes > 0 else 0)
|
| 217 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 218 |
# Block signals temporarily to avoid triggering callbacks multiple times
|
| 219 |
self.start_spin.blockSignals(True)
|
| 220 |
self.end_spin.blockSignals(True)
|
|
@@ -371,6 +388,49 @@ class LoopLabeler(QWidget):
|
|
| 371 |
hf_file = json_file.with_suffix(".hf.json")
|
| 372 |
return hf_file.exists()
|
| 373 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 374 |
def find_first_unannotated(self):
|
| 375 |
"""Find the index of the first unannotated JSON file"""
|
| 376 |
for idx, json_file in enumerate(self.json_files):
|
|
|
|
| 154 |
|
| 155 |
def load_json(self, json_path):
|
| 156 |
self.current_json = json_path
|
| 157 |
+
|
| 158 |
+
# Start with default loop state as true for new files
|
| 159 |
+
self.loop_checkbox.setChecked(True)
|
| 160 |
+
|
| 161 |
try:
|
| 162 |
with open(json_path) as f:
|
| 163 |
self.loop_candidates = json.load(f)
|
|
|
|
| 200 |
if not self.frames:
|
| 201 |
print(f"No frames found in {webp_path}")
|
| 202 |
|
| 203 |
+
# First update the candidate from the loop detection data
|
| 204 |
self.update_candidate()
|
| 205 |
+
|
| 206 |
+
# Then check if we have human feedback data and override with that
|
| 207 |
+
self.load_human_feedback()
|
| 208 |
|
| 209 |
def on_file_selected(self, idx):
|
| 210 |
if idx >= 0 and idx < len(self.json_files):
|
| 211 |
+
# Reset checkbox to default state before loading new file
|
| 212 |
+
# This will be overridden by load_human_feedback if necessary
|
| 213 |
+
self.loop_checkbox.setChecked(True)
|
| 214 |
self.load_json(self.json_files[idx])
|
| 215 |
|
| 216 |
def on_candidate_changed(self, idx):
|
| 217 |
if 0 <= idx < len(self.loop_candidates):
|
| 218 |
self.current_candidate = idx
|
| 219 |
+
# Default to assuming it is a loop when changing candidates
|
| 220 |
+
self.loop_checkbox.setChecked(True)
|
| 221 |
self.update_candidate()
|
| 222 |
else:
|
| 223 |
self.current_candidate = 0
|
|
|
|
| 228 |
self.start_spin.setMaximum(nframes-1 if nframes > 0 else 0)
|
| 229 |
self.end_spin.setMaximum(nframes-1 if nframes > 0 else 0)
|
| 230 |
|
| 231 |
+
# Set default loop state to true when updating candidate
|
| 232 |
+
# This will be overridden by load_human_feedback if human feedback exists
|
| 233 |
+
self.loop_checkbox.setChecked(True)
|
| 234 |
+
|
| 235 |
# Block signals temporarily to avoid triggering callbacks multiple times
|
| 236 |
self.start_spin.blockSignals(True)
|
| 237 |
self.end_spin.blockSignals(True)
|
|
|
|
| 388 |
hf_file = json_file.with_suffix(".hf.json")
|
| 389 |
return hf_file.exists()
|
| 390 |
|
| 391 |
+
def load_human_feedback(self):
|
| 392 |
+
"""Load the human feedback from .hf.json file if it exists and update UI accordingly"""
|
| 393 |
+
if self.current_json is None:
|
| 394 |
+
return
|
| 395 |
+
|
| 396 |
+
hf_file = self.current_json.with_suffix(".hf.json")
|
| 397 |
+
|
| 398 |
+
if hf_file.exists():
|
| 399 |
+
try:
|
| 400 |
+
with open(hf_file) as f:
|
| 401 |
+
hf_data = json.load(f)
|
| 402 |
+
|
| 403 |
+
# Update the "Is loop" checkbox
|
| 404 |
+
if "loop" in hf_data:
|
| 405 |
+
self.loop_checkbox.setChecked(bool(hf_data["loop"]))
|
| 406 |
+
|
| 407 |
+
# Update the start and end positions if available
|
| 408 |
+
if "best_cut" in hf_data and isinstance(hf_data["best_cut"], list) and len(hf_data["best_cut"]) >= 2:
|
| 409 |
+
start, end = hf_data["best_cut"][0], hf_data["best_cut"][1]
|
| 410 |
+
|
| 411 |
+
# Block signals temporarily to avoid triggering callbacks
|
| 412 |
+
self.start_spin.blockSignals(True)
|
| 413 |
+
self.end_spin.blockSignals(True)
|
| 414 |
+
|
| 415 |
+
# Set spin box values and update our tracking variables
|
| 416 |
+
self.start_spin.setValue(start)
|
| 417 |
+
self.end_spin.setValue(end)
|
| 418 |
+
self.current_start = start
|
| 419 |
+
self.current_end = end
|
| 420 |
+
|
| 421 |
+
# Re-enable signals
|
| 422 |
+
self.start_spin.blockSignals(False)
|
| 423 |
+
self.end_spin.blockSignals(False)
|
| 424 |
+
|
| 425 |
+
# Reset preview
|
| 426 |
+
self.preview_idx = 0
|
| 427 |
+
except (json.JSONDecodeError, IOError) as e:
|
| 428 |
+
print(f"Error loading human feedback file {hf_file}: {e}")
|
| 429 |
+
else:
|
| 430 |
+
# No human feedback file exists, set checkbox to checked
|
| 431 |
+
self.loop_checkbox.setChecked(True)
|
| 432 |
+
print(f"No human feedback file found for {self.current_json.name}, defaulting 'Is loop' to enabled")
|
| 433 |
+
|
| 434 |
def find_first_unannotated(self):
|
| 435 |
"""Find the index of the first unannotated JSON file"""
|
| 436 |
for idx, json_file in enumerate(self.json_files):
|