Spaces:
Running on Zero
Running on Zero
File size: 1,491 Bytes
ee69ab7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | from __future__ import annotations
from dataclasses import dataclass, field
from pathlib import Path
from typing import Any
import torch
@dataclass
class InferenceRequest:
input_path: str | Path | None = None
lq_video: torch.Tensor | None = None
output_path: str | Path | None = None
context: torch.Tensor | None = None
height: int | None = None
width: int | None = None
max_frames: int | None = None
fps: float | None = None
def validate(self) -> None:
if (self.input_path is None) == (self.lq_video is None):
raise ValueError("Provide exactly one of input_path or lq_video")
if self.lq_video is not None and self.lq_video.ndim != 5:
raise ValueError("lq_video must be [B,C,F,H,W] or [B,F,C,H,W]")
if self.lq_video is not None and self.lq_video.shape[0] != 1:
raise ValueError("inference currently supports exactly one video (batch size 1)")
if self.max_frames is not None and self.max_frames <= 0:
raise ValueError("max_frames must be positive")
if self.fps is not None and self.fps <= 0:
raise ValueError("fps must be positive")
if (self.height is None) != (self.width is None):
raise ValueError("height and width must be provided together")
@dataclass
class InferenceResult:
video: torch.Tensor | None
output_path: str | None
frames: int
fps: float
metadata: dict[str, Any] = field(default_factory=dict)
|