1
0
Fork 0
onnx-web/api/onnx_web/chain/edit_metadata.py

55 lines
1.4 KiB
Python
Raw Normal View History

2024-01-07 14:16:13 +00:00
from typing import Optional
from ..params import (
HighresParams,
ImageParams,
Size,
SizeChart,
StageParams,
UpscaleParams,
)
2024-01-06 23:20:37 +00:00
from ..server import ServerContext
from ..worker import ProgressCallback, WorkerContext
2024-01-06 23:40:36 +00:00
from .base import BaseStage
2024-01-06 23:20:37 +00:00
from .result import StageResult
2024-01-06 23:40:36 +00:00
class EditMetadataStage(BaseStage):
2024-01-07 02:32:38 +00:00
max_tile = SizeChart.max
2024-01-06 23:20:37 +00:00
def run(
self,
_worker: WorkerContext,
_server: ServerContext,
_stage: StageParams,
_params: ImageParams,
source: StageResult,
*,
callback: Optional[ProgressCallback] = None,
2024-01-06 23:40:36 +00:00
size: Optional[Size] = None,
upscale: Optional[UpscaleParams] = None,
highres: Optional[HighresParams] = None,
note: Optional[str] = None,
replace_params: Optional[ImageParams] = None,
2024-01-06 23:20:37 +00:00
**kwargs,
2024-01-07 14:16:13 +00:00
) -> StageResult:
2024-01-06 23:20:37 +00:00
# Modify the source image's metadata using the provided parameters
for metadata in source.metadata:
if note is not None:
metadata.note = note
2024-01-06 23:40:36 +00:00
if replace_params is not None:
metadata.params = replace_params
2024-01-06 23:20:37 +00:00
if size is not None:
metadata.size = size
if upscale is not None:
metadata.upscale = upscale
if highres is not None:
metadata.highres = highres
# Return the modified source image
return source