| 1 | # Copyright (C) 2025 AIDC-AI |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | # Unless required by applicable law or agreed to in writing, software |
| 8 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 | # See the License for the specific language governing permissions and |
| 11 | # limitations under the License. |
| 12 | |
| 13 | """ |
| 14 | Progress event models for video generation |
| 15 | |
| 16 | Provides structured progress events for UI layer to consume and translate. |
| 17 | """ |
| 18 | |
| 19 | from dataclasses import dataclass |
| 20 | from typing import Optional |
| 21 | |
| 22 | |
| 23 | @dataclass |
| 24 | class ProgressEvent: |
| 25 | """ |
| 26 | Structured progress event for video generation |
| 27 | |
| 28 | Attributes: |
| 29 | event_type: Type of event (e.g., "generating_narrations", "frame_step", "concatenating") |
| 30 | progress: Progress value from 0.0 to 1.0 |
| 31 | frame_current: Current frame number (1-based, optional) |
| 32 | frame_total: Total number of frames (optional) |
| 33 | step: Current step within frame (1-4, optional) |
| 34 | action: Action being performed (e.g., "audio", "image", "compose", "video", optional) |
| 35 | |
| 36 | Examples: |
| 37 | # Simple progress event |
| 38 | ProgressEvent(event_type="generating_narrations", progress=0.05) |
| 39 | |
| 40 | # Frame step event |
| 41 | ProgressEvent( |
| 42 | event_type="frame_step", |
| 43 | progress=0.23, |
| 44 | frame_current=1, |
| 45 | frame_total=5, |
| 46 | step=1, |
| 47 | action="audio" |
| 48 | ) |
| 49 | """ |
| 50 | event_type: str |
| 51 | progress: float |
| 52 | |
| 53 | # Optional frame-related fields |
| 54 | frame_current: Optional[int] = None |
| 55 | frame_total: Optional[int] = None |
| 56 | step: Optional[int] = None # 1-4 for frame processing steps |
| 57 | action: Optional[str] = None # "audio", "image", "compose", "video" |
| 58 | extra_info: Optional[str] = None # Additional information (e.g., batch progress) |
| 59 | |
| 60 | def __post_init__(self): |
| 61 | """Validate progress value""" |
| 62 | if not 0.0 <= self.progress <= 1.0: |
| 63 | raise ValueError(f"Progress must be between 0.0 and 1.0, got {self.progress}") |
| 64 | |
| 65 |