Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -62,20 +62,16 @@ def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
|
| 62 |
return seed
|
| 63 |
|
| 64 |
|
| 65 |
-
@spaces.GPU(duration=
|
| 66 |
def generate_img(
|
| 67 |
-
|
| 68 |
edit_prompt: str,
|
| 69 |
sample_steps,
|
| 70 |
scale,
|
| 71 |
image_guidance_scale,
|
| 72 |
seed,
|
| 73 |
progress=gr.Progress(track_tqdm=True),
|
| 74 |
-
):
|
| 75 |
-
# pipeline.pipe.to("cuda").to(pipeline.weight_dtype)
|
| 76 |
-
|
| 77 |
-
pil_image = PILImage.fromarray(np_image)
|
| 78 |
-
|
| 79 |
edited_image = pipeline.generate_edited_image(
|
| 80 |
instruction=edit_prompt,
|
| 81 |
conditioning_image=pil_image,
|
|
@@ -84,9 +80,8 @@ def generate_img(
|
|
| 84 |
guidance_scale=scale,
|
| 85 |
image_guidance_scale=image_guidance_scale,
|
| 86 |
seed=seed,
|
| 87 |
-
)
|
| 88 |
-
|
| 89 |
-
return result_image
|
| 90 |
|
| 91 |
|
| 92 |
if __name__ == "__main__":
|
|
@@ -96,15 +91,10 @@ if __name__ == "__main__":
|
|
| 96 |
image_dir = pathlib.Path('images')
|
| 97 |
examples = [[path.as_posix(), "let this case swim in the river", 20, 4.5, 1.2, 42] for path in sorted(image_dir.glob('*.png'))]
|
| 98 |
|
| 99 |
-
# generate_fn = partial(
|
| 100 |
-
# generate_img,
|
| 101 |
-
# pipeline=editor_pipeline
|
| 102 |
-
# )
|
| 103 |
-
|
| 104 |
demo = gr.Interface(
|
| 105 |
fn=generate_img,
|
| 106 |
inputs=[
|
| 107 |
-
gr.Image(label="Input", type="
|
| 108 |
Textbox(label="Prompt", placeholder="Please enter your prompt. \n"),
|
| 109 |
gr.Slider(label="Sample Steps", minimum=1, maximum=100, value=20, step=1),
|
| 110 |
gr.Slider(
|
|
@@ -125,12 +115,10 @@ if __name__ == "__main__":
|
|
| 125 |
value=42,
|
| 126 |
),
|
| 127 |
],
|
| 128 |
-
outputs=[
|
| 129 |
-
Image(type="numpy", label="Img"),
|
| 130 |
-
],
|
| 131 |
title="",
|
| 132 |
description=DESCRIPTION,
|
| 133 |
examples=examples,
|
| 134 |
)
|
| 135 |
|
| 136 |
-
demo.queue(max_size=
|
|
|
|
| 62 |
return seed
|
| 63 |
|
| 64 |
|
| 65 |
+
@spaces.GPU(duration=180)
|
| 66 |
def generate_img(
|
| 67 |
+
pil_image,
|
| 68 |
edit_prompt: str,
|
| 69 |
sample_steps,
|
| 70 |
scale,
|
| 71 |
image_guidance_scale,
|
| 72 |
seed,
|
| 73 |
progress=gr.Progress(track_tqdm=True),
|
| 74 |
+
):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
edited_image = pipeline.generate_edited_image(
|
| 76 |
instruction=edit_prompt,
|
| 77 |
conditioning_image=pil_image,
|
|
|
|
| 80 |
guidance_scale=scale,
|
| 81 |
image_guidance_scale=image_guidance_scale,
|
| 82 |
seed=seed,
|
| 83 |
+
)
|
| 84 |
+
return edited_image
|
|
|
|
| 85 |
|
| 86 |
|
| 87 |
if __name__ == "__main__":
|
|
|
|
| 91 |
image_dir = pathlib.Path('images')
|
| 92 |
examples = [[path.as_posix(), "let this case swim in the river", 20, 4.5, 1.2, 42] for path in sorted(image_dir.glob('*.png'))]
|
| 93 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
demo = gr.Interface(
|
| 95 |
fn=generate_img,
|
| 96 |
inputs=[
|
| 97 |
+
gr.Image(label="Input", type="pil"),
|
| 98 |
Textbox(label="Prompt", placeholder="Please enter your prompt. \n"),
|
| 99 |
gr.Slider(label="Sample Steps", minimum=1, maximum=100, value=20, step=1),
|
| 100 |
gr.Slider(
|
|
|
|
| 115 |
value=42,
|
| 116 |
),
|
| 117 |
],
|
| 118 |
+
outputs = [gr.Gallery(label="Result", show_label=False, type="pil")]
|
|
|
|
|
|
|
| 119 |
title="",
|
| 120 |
description=DESCRIPTION,
|
| 121 |
examples=examples,
|
| 122 |
)
|
| 123 |
|
| 124 |
+
demo.queue(max_size=100).launch()
|