Spaces:
Running
on
Zero
Running
on
Zero
initial ui changes
#2
by
linoyts
HF Staff
- opened
app.py
CHANGED
@@ -37,6 +37,13 @@ CONCEPTS_MAP = {'age':'age','animal fur':'animal_fur', 'deterioration': 'deterio
|
|
37 |
|
38 |
concept_options = list(CONCEPTS_MAP.keys())
|
39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
@spaces.GPU
|
41 |
def get_image_embeds(pil_image, model=clip_model, preproc=preprocess, dev=device):
|
42 |
"""Get CLIP image embeddings for a given PIL image"""
|
@@ -157,11 +164,21 @@ def process_and_display(
|
|
157 |
|
158 |
return modified_images
|
159 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
160 |
|
|
|
|
|
|
|
|
|
161 |
|
162 |
-
|
163 |
-
|
164 |
-
gr.Markdown("")
|
165 |
|
166 |
with gr.Row():
|
167 |
with gr.Column():
|
@@ -188,19 +205,25 @@ with gr.Blocks(title="Image Concept Composition") as demo:
|
|
188 |
concept_name3 = gr.Dropdown(concept_options, label="concept 3", value= None, info="concept type")
|
189 |
rank3 = gr.Slider(minimum=1, maximum=50, value=30, step=1, label="Rank 3")
|
190 |
|
191 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
192 |
|
193 |
-
with gr.Row():
|
194 |
-
scale = gr.Slider(minimum=0.1, maximum=2.0, value=1.0, step=0.1, label="Scale")
|
195 |
-
seed = gr.Number(value=420, label="Seed", precision=0)
|
196 |
|
197 |
-
submit_btn = gr.Button("Generate")
|
198 |
|
199 |
with gr.Column():
|
200 |
output_image = gr.Image(label="composed output", show_label=True)
|
201 |
|
202 |
submit_btn.click(
|
203 |
-
fn=
|
|
|
|
|
|
|
204 |
inputs=[
|
205 |
base_image,
|
206 |
concept_image1, concept_name1,
|
|
|
37 |
|
38 |
concept_options = list(CONCEPTS_MAP.keys())
|
39 |
|
40 |
+
|
41 |
+
MAX_SEED = np.iinfo(np.int32).max
|
42 |
+
def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
43 |
+
if randomize_seed:
|
44 |
+
seed = random.randint(0, MAX_SEED)
|
45 |
+
return seed
|
46 |
+
|
47 |
@spaces.GPU
|
48 |
def get_image_embeds(pil_image, model=clip_model, preproc=preprocess, dev=device):
|
49 |
"""Get CLIP image embeddings for a given PIL image"""
|
|
|
164 |
|
165 |
return modified_images
|
166 |
|
167 |
+
# UI CSS
|
168 |
+
css = """
|
169 |
+
#col-container {
|
170 |
+
margin: 0 auto;
|
171 |
+
max-width: 960px;
|
172 |
+
}
|
173 |
+
"""
|
174 |
|
175 |
+
with gr.Blocks(css=css) as demo:
|
176 |
+
gr.Markdown(f"""# IP Composer π
βποΈ
|
177 |
+
### compose new images with visual concepts
|
178 |
+
following the algorithm proposed in [*Stable Flow: Vital Layers for Training-Free Image Editing* by Avrahami et al.](https://arxiv.org/pdf/2502.13951)
|
179 |
|
180 |
+
[[project page](https://ip-composer.github.io/IP-Composer/) [[arxiv](https://arxiv.org/pdf/2502.13951)]
|
181 |
+
""")
|
|
|
182 |
|
183 |
with gr.Row():
|
184 |
with gr.Column():
|
|
|
205 |
concept_name3 = gr.Dropdown(concept_options, label="concept 3", value= None, info="concept type")
|
206 |
rank3 = gr.Slider(minimum=1, maximum=50, value=30, step=1, label="Rank 3")
|
207 |
|
208 |
+
submit_btn = gr.Button("Generate")
|
209 |
+
|
210 |
+
with gr.Accordion("Advanced options", open=False):
|
211 |
+
prompt = gr.Textbox(label="Guidance Prompt (Optional)", placeholder="Optional text prompt to guide generation")
|
212 |
+
with gr.Row():
|
213 |
+
scale = gr.Slider(minimum=0.1, maximum=2.0, value=1.0, step=0.1, label="Scale")
|
214 |
+
randomize_seed = gr,Checkbox(value=True, label="Randomize seed")
|
215 |
+
seed = gr.Number(value=0, label="Seed", precision=0)
|
216 |
|
|
|
|
|
|
|
217 |
|
|
|
218 |
|
219 |
with gr.Column():
|
220 |
output_image = gr.Image(label="composed output", show_label=True)
|
221 |
|
222 |
submit_btn.click(
|
223 |
+
fn=randomize_seed_fn,
|
224 |
+
inputs=[seed, randomize_seed],
|
225 |
+
outputs=seed,
|
226 |
+
).then(fn=process_and_display,
|
227 |
inputs=[
|
228 |
base_image,
|
229 |
concept_image1, concept_name1,
|