diff options
| -rwxr-xr-x | fanfictioner | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/fanfictioner b/fanfictioner index 4386f57..cbf5bda 100755 --- a/fanfictioner +++ b/fanfictioner @@ -368,12 +368,14 @@ def mem_available_kb(meminfo): def progress(start, log): - """One self-overwriting status line: elapsed time and sd-cli's latest progress output.""" - with open(log, "rb") as f: - f.seek(max(0, os.path.getsize(log) - 4096)) - last = next((x for x in reversed(re.split(r"[\r\n]", f.read().decode(errors="replace"))) if x.strip()), "") + """One self-overwriting status line: elapsed time, candidate and sd-cli's latest progress bar. + Never raw log lines: recovered [ERROR lines there read like a crash.""" + text = Path(log).read_text(errors="replace") + cand = re.findall(r"generating image: (\d+/\d+)", text) + bar = re.findall(r"\|[=>\s]*\|[^\r\n\x1b]*", text[text.rfind("generating image"):]) # sampling, not loading + status = f"candidate {cand[-1]} {bar[-1] if bar else 'preparing'}" if cand else "loading models" width = shutil.get_terminal_size().columns - 1 - print(f"\r{int(time.time() - start):4d}s {last.strip()}"[:width].ljust(width), end="", flush=True) + print(f"\r{int(time.time() - start):4d}s {status}"[:width].ljust(width), end="", flush=True) def scale_preview(src, dst): |
