progress.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. Progress event models for video generation
  14. Provides structured progress events for UI layer to consume and translate.
  15. """
  16. from dataclasses import dataclass
  17. from typing import Optional
  18. @dataclass
  19. class ProgressEvent:
  20. """
  21. Structured progress event for video generation
  22. Attributes:
  23. event_type: Type of event (e.g., "generating_narrations", "frame_step", "concatenating")
  24. progress: Progress value from 0.0 to 1.0
  25. frame_current: Current frame number (1-based, optional)
  26. frame_total: Total number of frames (optional)
  27. step: Current step within frame (1-4, optional)
  28. action: Action being performed (e.g., "audio", "image", "compose", "video", optional)
  29. Examples:
  30. # Simple progress event
  31. ProgressEvent(event_type="generating_narrations", progress=0.05)
  32. # Frame step event
  33. ProgressEvent(
  34. event_type="frame_step",
  35. progress=0.23,
  36. frame_current=1,
  37. frame_total=5,
  38. step=1,
  39. action="audio"
  40. )
  41. """
  42. event_type: str
  43. progress: float
  44. # Optional frame-related fields
  45. frame_current: Optional[int] = None
  46. frame_total: Optional[int] = None
  47. step: Optional[int] = None # 1-4 for frame processing steps
  48. action: Optional[str] = None # "audio", "image", "compose", "video"
  49. extra_info: Optional[str] = None # Additional information (e.g., batch progress)
  50. def __post_init__(self):
  51. """Validate progress value"""
  52. if not 0.0 <= self.progress <= 1.0:
  53. raise ValueError(f"Progress must be between 0.0 and 1.0, got {self.progress}")