media.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. Media generation result models
  14. """
  15. from typing import Literal, Optional
  16. from pydantic import BaseModel, Field
  17. class MediaResult(BaseModel):
  18. """
  19. Media generation result from workflow execution
  20. Supports both image and video outputs from ComfyUI workflows.
  21. The media_type indicates what kind of media was generated.
  22. Attributes:
  23. media_type: Type of media generated ("image" or "video")
  24. url: URL or path to the generated media
  25. duration: Duration in seconds (only for video, None for image)
  26. Examples:
  27. # Image result
  28. MediaResult(media_type="image", url="http://example.com/image.png")
  29. # Video result
  30. MediaResult(media_type="video", url="http://example.com/video.mp4", duration=5.2)
  31. """
  32. media_type: Literal["image", "video"] = Field(
  33. description="Type of generated media"
  34. )
  35. url: str = Field(
  36. description="URL or path to the generated media file"
  37. )
  38. duration: Optional[float] = Field(
  39. None,
  40. description="Duration in seconds (only applicable for video)"
  41. )
  42. @property
  43. def is_image(self) -> bool:
  44. """Check if this is an image result"""
  45. return self.media_type == "image"
  46. @property
  47. def is_video(self) -> bool:
  48. """Check if this is a video result"""
  49. return self.media_type == "video"