|
import time |
|
import json |
|
from pathlib import Path |
|
|
|
def load_messages() -> list: |
|
"""Load status messages from JSON file.""" |
|
with open('loading_messages.json', 'r') as f: |
|
return json.load(f)['messages'] |
|
|
|
class StatusTracker: |
|
""" |
|
Track and display progress status for video generation. |
|
""" |
|
def __init__(self, progress, status_box=None): |
|
self.progress = progress |
|
self.status_box = status_box |
|
self.steps = [] |
|
self.current_message = "" |
|
self._status_markdown = "" |
|
|
|
def add_step(self, message: str, progress_value: float): |
|
""" |
|
Add a permanent step to the progress display. |
|
|
|
Args: |
|
message: Step description |
|
progress_value: Progress value between 0 and 1 |
|
""" |
|
self.steps.append(message) |
|
self._update_display(progress_value) |
|
|
|
def update_message(self, message: str, progress_value: float): |
|
""" |
|
Update the current working message. |
|
|
|
Args: |
|
message: Current status message |
|
progress_value: Progress value between 0 and 1 |
|
""" |
|
self.current_message = message |
|
self._update_display(progress_value) |
|
|
|
def _update_display(self, progress_value: float): |
|
""" |
|
Update the status display with current progress. |
|
|
|
Args: |
|
progress_value: Progress value between 0 and 1 |
|
""" |
|
|
|
status_md = "### π¬ Generation Progress\n\n" |
|
|
|
|
|
if self.steps: |
|
for step in self.steps: |
|
status_md += f"β {step}\n" |
|
status_md += "\n" |
|
|
|
|
|
if self.current_message: |
|
status_md += f"### π {self.current_message}\n" |
|
|
|
self._status_markdown = status_md |
|
self.progress(progress_value) |
|
|
|
|
|
if self.status_box is not None: |
|
try: |
|
self.status_box.update(value=self._status_markdown) |
|
except: |
|
pass |
|
|
|
def get_status(self) -> str: |
|
"""Get the current status markdown.""" |
|
return self._status_markdown |
|
|