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

53 lines
1.4 KiB
Python
Raw Normal View History

from logging import getLogger
2023-11-19 00:13:13 +00:00
from typing import Callable, Optional
2023-02-05 13:53:26 +00:00
from PIL import Image
2023-02-05 13:53:26 +00:00
from ..params import ImageParams, Size, StageParams
2023-02-26 05:49:39 +00:00
from ..server import ServerContext
2023-02-26 20:15:30 +00:00
from ..worker import WorkerContext
from .base import BaseStage
from .result import StageResult
logger = getLogger(__name__)
class SourceNoiseStage(BaseStage):
def run(
self,
_worker: WorkerContext,
_server: ServerContext,
_stage: StageParams,
_params: ImageParams,
sources: StageResult,
*,
size: Size,
noise_source: Callable,
2023-09-15 00:35:48 +00:00
stage_source: Optional[Image.Image] = None,
**kwargs,
) -> StageResult:
logger.info("generating image from noise source")
if len(sources) > 0:
logger.info(
"source images were passed to a source stage, new images will be appended"
)
outputs = []
# TODO: looping over sources and ignoring params does not make much sense for a source stage
for source in sources.as_image():
output = noise_source(source, (size.width, size.height), (0, 0))
logger.info("final output image size: %sx%s", output.width, output.height)
outputs.append(output)
return StageResult(images=outputs)
def outputs(
2023-09-13 00:17:03 +00:00
self,
params: ImageParams,
sources: int,
) -> int:
2023-09-13 00:17:03 +00:00
return sources + 1