Spaces:
Running
on
Zero
Running
on
Zero
Refactor logging in run_training function of app.py to accumulate log messages in a buffer before yielding, improving output consistency and readability during training execution.
Browse files
app.py
CHANGED
|
@@ -444,6 +444,7 @@ def run_training(
|
|
| 444 |
save_every: int,
|
| 445 |
) -> Iterable[tuple]:
|
| 446 |
# Basic validation
|
|
|
|
| 447 |
if not output_name.strip():
|
| 448 |
yield ("[ERROR] OUTPUT NAME is required.", None)
|
| 449 |
return
|
|
@@ -470,7 +471,8 @@ def run_training(
|
|
| 470 |
yield ("[ERROR] No images uploaded for IMAGE_FOLDER.", None)
|
| 471 |
return
|
| 472 |
base_filenames = _copy_uploads(base_files, img_dir)
|
| 473 |
-
|
|
|
|
| 474 |
|
| 475 |
# Prepare control sets
|
| 476 |
control_upload_sets = [
|
|
@@ -499,7 +501,8 @@ def run_training(
|
|
| 499 |
# Simply copy; name matching will be handled by create_image_caption_json.py
|
| 500 |
_copy_uploads(uploads, cdir)
|
| 501 |
control_dirs.append(folder_name)
|
| 502 |
-
|
|
|
|
| 503 |
|
| 504 |
# Metadata.jsonl will be generated by create_image_caption_json.py in train_QIE.sh
|
| 505 |
|
|
@@ -540,8 +543,9 @@ def run_training(
|
|
| 540 |
|
| 541 |
|
| 542 |
shell = _pick_shell()
|
| 543 |
-
|
| 544 |
-
|
|
|
|
| 545 |
|
| 546 |
# Run and stream output
|
| 547 |
proc = subprocess.Popen(
|
|
@@ -555,7 +559,8 @@ def run_training(
|
|
| 555 |
try:
|
| 556 |
assert proc.stdout is not None
|
| 557 |
for line in proc.stdout:
|
| 558 |
-
|
|
|
|
| 559 |
finally:
|
| 560 |
code = proc.wait()
|
| 561 |
# Try to locate latest LoRA file for download
|
|
@@ -574,7 +579,8 @@ def run_training(
|
|
| 574 |
lora_path = cand[-1][1]
|
| 575 |
except Exception:
|
| 576 |
pass
|
| 577 |
-
|
|
|
|
| 578 |
|
| 579 |
|
| 580 |
def build_ui() -> gr.Blocks:
|
|
|
|
| 444 |
save_every: int,
|
| 445 |
) -> Iterable[tuple]:
|
| 446 |
# Basic validation
|
| 447 |
+
log_buf = ""
|
| 448 |
if not output_name.strip():
|
| 449 |
yield ("[ERROR] OUTPUT NAME is required.", None)
|
| 450 |
return
|
|
|
|
| 471 |
yield ("[ERROR] No images uploaded for IMAGE_FOLDER.", None)
|
| 472 |
return
|
| 473 |
base_filenames = _copy_uploads(base_files, img_dir)
|
| 474 |
+
log_buf += f"[QIE] Copied {len(base_filenames)} base images to {img_dir}\n"
|
| 475 |
+
yield (log_buf, None)
|
| 476 |
|
| 477 |
# Prepare control sets
|
| 478 |
control_upload_sets = [
|
|
|
|
| 501 |
# Simply copy; name matching will be handled by create_image_caption_json.py
|
| 502 |
_copy_uploads(uploads, cdir)
|
| 503 |
control_dirs.append(folder_name)
|
| 504 |
+
log_buf += f"[QIE] Copied {len(uploads)} control_{i} images to {cdir}\n"
|
| 505 |
+
yield (log_buf, None)
|
| 506 |
|
| 507 |
# Metadata.jsonl will be generated by create_image_caption_json.py in train_QIE.sh
|
| 508 |
|
|
|
|
| 543 |
|
| 544 |
|
| 545 |
shell = _pick_shell()
|
| 546 |
+
log_buf += f"[QIE] Using shell: {shell}\n"
|
| 547 |
+
log_buf += f"[QIE] Running script: {tmp_script}\n"
|
| 548 |
+
yield (log_buf, None)
|
| 549 |
|
| 550 |
# Run and stream output
|
| 551 |
proc = subprocess.Popen(
|
|
|
|
| 559 |
try:
|
| 560 |
assert proc.stdout is not None
|
| 561 |
for line in proc.stdout:
|
| 562 |
+
log_buf += line
|
| 563 |
+
yield (log_buf, None)
|
| 564 |
finally:
|
| 565 |
code = proc.wait()
|
| 566 |
# Try to locate latest LoRA file for download
|
|
|
|
| 579 |
lora_path = cand[-1][1]
|
| 580 |
except Exception:
|
| 581 |
pass
|
| 582 |
+
log_buf += f"[QIE] Exit code: {code}\n"
|
| 583 |
+
yield (log_buf, lora_path)
|
| 584 |
|
| 585 |
|
| 586 |
def build_ui() -> gr.Blocks:
|