[diffusion] apps: support I2I tasks in webui (#15778)
This commit is contained in:
@@ -22,6 +22,7 @@ def add_webui_args(parser: argparse.ArgumentParser):
|
||||
|
||||
def run_sgl_diffusion_webui(server_args: ServerArgs):
|
||||
# import gradio in function to avoid CI crash
|
||||
|
||||
import gradio as gr
|
||||
|
||||
# init client
|
||||
@@ -31,6 +32,7 @@ def run_sgl_diffusion_webui(server_args: ServerArgs):
|
||||
def gradio_generate(
|
||||
prompt,
|
||||
negative_prompt,
|
||||
reference_image_paths_str,
|
||||
seed,
|
||||
num_frames,
|
||||
frames_per_second,
|
||||
@@ -45,9 +47,23 @@ def run_sgl_diffusion_webui(server_args: ServerArgs):
|
||||
So we use global variable sampling_params_kwargs to avoid pass this param, because gradio does not support this.
|
||||
return [ np.ndarray, None ] | [None, np.ndarray]
|
||||
"""
|
||||
if (
|
||||
reference_image_paths_str is not ""
|
||||
and reference_image_paths_str is not None
|
||||
):
|
||||
if "," in reference_image_paths_str:
|
||||
print(
|
||||
f"Warning: please use English comma to separate the reference image paths, and the reference image paths is: {reference_image_paths_str}"
|
||||
)
|
||||
reference_image_paths_str = reference_image_paths_str.replace(",", ",")
|
||||
image_path = [path.strip() for path in reference_image_paths_str.split(",")]
|
||||
else:
|
||||
image_path = None
|
||||
|
||||
sampling_params_kwargs = dict(
|
||||
prompt=prompt,
|
||||
negative_prompt=negative_prompt,
|
||||
image_path=image_path,
|
||||
seed=seed,
|
||||
num_frames=num_frames,
|
||||
fps=frames_per_second,
|
||||
@@ -68,6 +84,11 @@ def run_sgl_diffusion_webui(server_args: ServerArgs):
|
||||
)
|
||||
result = sync_scheduler_client.forward([batch])
|
||||
save_file_path = str(os.path.join(batch.output_path, batch.output_file_name))
|
||||
if result.output is None:
|
||||
raise ValueError(
|
||||
f"No output is generated by client, and their sampling params is: \n{ '\n'.join([f'{key}: {value}' for key, value in sampling_params_kwargs.items()])}"
|
||||
)
|
||||
|
||||
frames = post_process_sample(
|
||||
result.output[0],
|
||||
batch.data_type,
|
||||
@@ -104,6 +125,10 @@ def run_sgl_diffusion_webui(server_args: ServerArgs):
|
||||
frames_per_second = gr.Slider(
|
||||
minimum=4, maximum=60, value=16, step=1, label="frames_per_second"
|
||||
)
|
||||
reference_image_paths_str = gr.Textbox(
|
||||
label="reference images",
|
||||
placeholder="Examples: 'image1.png, image2.png' or 'https://example.com/image1.png, https://example.com/image2.png'",
|
||||
)
|
||||
width = gr.Number(label="width", precision=0, value=720)
|
||||
height = gr.Number(label="height", precision=0, value=480)
|
||||
num_inference_steps = gr.Slider(
|
||||
@@ -127,6 +152,7 @@ def run_sgl_diffusion_webui(server_args: ServerArgs):
|
||||
inputs=[
|
||||
prompt,
|
||||
negative_prompt,
|
||||
reference_image_paths_str,
|
||||
seed,
|
||||
num_frames,
|
||||
frames_per_second,
|
||||
@@ -143,6 +169,7 @@ def run_sgl_diffusion_webui(server_args: ServerArgs):
|
||||
server_port=server_args.webui_port,
|
||||
quiet=True,
|
||||
prevent_thread_lock=True,
|
||||
show_error=True,
|
||||
)
|
||||
|
||||
# print banner
|
||||
|
||||
Reference in New Issue
Block a user