Spaces:
Running
on
Zero
Running
on
Zero
add imageslider
Browse filesadds image slider over the output for a cool before-after experience (such as in https://huggingface.co/spaces/stepfun-ai/Step1X-Edit)
app.py
CHANGED
@@ -74,7 +74,7 @@ def infer(edit_images,
|
|
74 |
if randomize_seed:
|
75 |
seed = random.randint(0, MAX_SEED)
|
76 |
|
77 |
-
|
78 |
prompt=instruction,
|
79 |
image=combined_image,
|
80 |
mask_image=mask,
|
@@ -85,15 +85,15 @@ def infer(edit_images,
|
|
85 |
generator=torch.Generator().manual_seed(seed),
|
86 |
).images[0]
|
87 |
|
88 |
-
w,h =
|
89 |
-
|
90 |
|
91 |
os.makedirs(args.output_dir, exist_ok=True)
|
92 |
|
93 |
index = len(os.listdir(args.output_dir))
|
94 |
-
|
95 |
|
96 |
-
return image, seed
|
97 |
|
98 |
# 新增的示例,将元组转换为列表
|
99 |
new_examples = [
|
@@ -135,7 +135,7 @@ For more details, check out our [Github Repository](https://github.com/River-Zha
|
|
135 |
)
|
136 |
run_button = gr.Button("Run")
|
137 |
with gr.Column():
|
138 |
-
result = gr.
|
139 |
gr.Markdown("⚠️ If your edit didn't work as desired, **try again with another seed** ! <br> If you use our example, don't forget to uncheck the random seed option. Otherwise, it will still use a random seed.")
|
140 |
with gr.Accordion("Advanced Settings", open=True):
|
141 |
|
|
|
74 |
if randomize_seed:
|
75 |
seed = random.randint(0, MAX_SEED)
|
76 |
|
77 |
+
output_image = pipe(
|
78 |
prompt=instruction,
|
79 |
image=combined_image,
|
80 |
mask_image=mask,
|
|
|
85 |
generator=torch.Generator().manual_seed(seed),
|
86 |
).images[0]
|
87 |
|
88 |
+
w,h = output_image.size
|
89 |
+
output_image = output_image.crop((w//2, 0, w, h))
|
90 |
|
91 |
os.makedirs(args.output_dir, exist_ok=True)
|
92 |
|
93 |
index = len(os.listdir(args.output_dir))
|
94 |
+
output_image.save(f"{args.output_dir}/result_{index}.png")
|
95 |
|
96 |
+
return (image, output_image), seed
|
97 |
|
98 |
# 新增的示例,将元组转换为列表
|
99 |
new_examples = [
|
|
|
135 |
)
|
136 |
run_button = gr.Button("Run")
|
137 |
with gr.Column():
|
138 |
+
result = gr.ImageSlider(label="Result", show_label=False)
|
139 |
gr.Markdown("⚠️ If your edit didn't work as desired, **try again with another seed** ! <br> If you use our example, don't forget to uncheck the random seed option. Otherwise, it will still use a random seed.")
|
140 |
with gr.Accordion("Advanced Settings", open=True):
|
141 |
|