Spaces:
Runtime error
Runtime error
add image selection and update layout
Browse files- edit_app.py +15 -17
edit_app.py
CHANGED
|
@@ -2,6 +2,7 @@ from __future__ import annotations
|
|
| 2 |
|
| 3 |
import math
|
| 4 |
import random
|
|
|
|
| 5 |
|
| 6 |
import gradio as gr
|
| 7 |
import torch
|
|
@@ -111,6 +112,12 @@ def main():
|
|
| 111 |
def reset():
|
| 112 |
return [0, "Randomize Seed", 1371, "Fix CFG", 7.5, 1.5, None]
|
| 113 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
with gr.Blocks() as demo:
|
| 115 |
gr.HTML("""<h1 style="font-weight: 900; margin-bottom: 7px;">
|
| 116 |
HQ-Edit: A High-Quality and High-Coverage Dataset for General Image Editing
|
|
@@ -122,14 +129,15 @@ def main():
|
|
| 122 |
<p/>""")
|
| 123 |
with gr.Row():
|
| 124 |
with gr.Column(scale=1, min_width=100):
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
# load_button = gr.Button("Load Example")
|
| 128 |
-
with gr.Column(scale=1, min_width=100):
|
| 129 |
-
reset_button = gr.Button("Reset")
|
| 130 |
with gr.Column(scale=3):
|
| 131 |
instruction = gr.Textbox(lines=1, label="Edit Instruction", interactive=True)
|
| 132 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
with gr.Row():
|
| 134 |
input_image = gr.Image(label="Input Image", type="pil", interactive=True, height=512, width=512)
|
| 135 |
edited_image = gr.Image(label=f"Edited Image", type="pil", interactive=False, height=512, width=512)
|
|
@@ -158,18 +166,8 @@ def main():
|
|
| 158 |
|
| 159 |
gr.Markdown(help_text)
|
| 160 |
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
# inputs=[
|
| 164 |
-
# steps,
|
| 165 |
-
# randomize_seed,
|
| 166 |
-
# seed,
|
| 167 |
-
# randomize_cfg,
|
| 168 |
-
# text_cfg_scale,
|
| 169 |
-
# image_cfg_scale,
|
| 170 |
-
# ],
|
| 171 |
-
# outputs=[input_image, instruction, seed, text_cfg_scale, image_cfg_scale, edited_image],
|
| 172 |
-
# )
|
| 173 |
generate_button.click(
|
| 174 |
fn=generate,
|
| 175 |
inputs=[
|
|
|
|
| 2 |
|
| 3 |
import math
|
| 4 |
import random
|
| 5 |
+
from glob import glob
|
| 6 |
|
| 7 |
import gradio as gr
|
| 8 |
import torch
|
|
|
|
| 112 |
def reset():
|
| 113 |
return [0, "Randomize Seed", 1371, "Fix CFG", 7.5, 1.5, None]
|
| 114 |
|
| 115 |
+
image_options = {path.split("/")[-1].split(".")[0]: path for path in sorted(glob("imgs/*png"))}
|
| 116 |
+
|
| 117 |
+
def show_image(image_name):
|
| 118 |
+
# Retrieve the image file path from the dictionary based on the selected name
|
| 119 |
+
return image_options[image_name]
|
| 120 |
+
|
| 121 |
with gr.Blocks() as demo:
|
| 122 |
gr.HTML("""<h1 style="font-weight: 900; margin-bottom: 7px;">
|
| 123 |
HQ-Edit: A High-Quality and High-Coverage Dataset for General Image Editing
|
|
|
|
| 129 |
<p/>""")
|
| 130 |
with gr.Row():
|
| 131 |
with gr.Column(scale=1, min_width=100):
|
| 132 |
+
dropdown = gr.Dropdown(list(image_options.keys()), label="Select from Given Images")
|
| 133 |
+
|
|
|
|
|
|
|
|
|
|
| 134 |
with gr.Column(scale=3):
|
| 135 |
instruction = gr.Textbox(lines=1, label="Edit Instruction", interactive=True)
|
| 136 |
|
| 137 |
+
with gr.Column(scale=1, min_width=100):
|
| 138 |
+
generate_button = gr.Button("Generate")
|
| 139 |
+
reset_button = gr.Button("Reset")
|
| 140 |
+
|
| 141 |
with gr.Row():
|
| 142 |
input_image = gr.Image(label="Input Image", type="pil", interactive=True, height=512, width=512)
|
| 143 |
edited_image = gr.Image(label=f"Edited Image", type="pil", interactive=False, height=512, width=512)
|
|
|
|
| 166 |
|
| 167 |
gr.Markdown(help_text)
|
| 168 |
|
| 169 |
+
dropdown.change(show_image, inputs=dropdown, outputs=input_image)
|
| 170 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
generate_button.click(
|
| 172 |
fn=generate,
|
| 173 |
inputs=[
|