Spaces:
Running
Running
File size: 1,289 Bytes
fba6023 | 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 44 45 46 47 48 49 50 51 52 53 | from __future__ import annotations
from enum import Enum
from pathlib import Path
from typing import Any
from pydantic import BaseModel, ConfigDict, Field
class MediaSource(str, Enum):
MULTIPART = "multipart"
JSON_URL = "json_url"
JSON_BASE64 = "json_base64"
N8N_BINARY = "n8n_binary"
OCTET_STREAM = "octet_stream"
YTDLP = "yt_dlp"
LOCAL_PATH = "local_path"
class InputMedia(BaseModel):
"""Source-agnostic media passed to all processing operations."""
model_config = ConfigDict(arbitrary_types_allowed=True)
source: MediaSource
filename: str
mime_type: str
temp_path: Path
size: int = Field(ge=0)
duration: float | None = None
metadata: dict[str, Any] = Field(default_factory=dict)
class ResolvedRequest(BaseModel):
model_config = ConfigDict(arbitrary_types_allowed=True)
request_id: str
inputs: list[InputMedia]
params: dict[str, Any] = Field(default_factory=dict)
@property
def primary(self) -> InputMedia:
return self.inputs[0]
class OperationResult(BaseModel):
model_config = ConfigDict(arbitrary_types_allowed=True)
path: Path | None = None
filename: str | None = None
mime_type: str | None = None
metadata: dict[str, Any] = Field(default_factory=dict)
|