Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -49,6 +49,23 @@ CONCEPTS_MAP={
|
|
49 |
"season": "season_descriptions.npy",
|
50 |
"material": "material_descriptions_with_gems.npy"
|
51 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
concept_options = list(CONCEPTS_MAP.keys())
|
53 |
|
54 |
|
@@ -58,6 +75,9 @@ def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
|
58 |
seed = random.randint(0, MAX_SEED)
|
59 |
return seed
|
60 |
|
|
|
|
|
|
|
61 |
@spaces.GPU
|
62 |
def get_image_embeds(pil_image, model=clip_model, preproc=preprocess, dev=device):
|
63 |
"""Get CLIP image embeddings for a given PIL image"""
|
@@ -196,34 +216,38 @@ following the algorithm proposed in [*IP-Composer: Semantic Composition of Visua
|
|
196 |
|
197 |
with gr.Row():
|
198 |
with gr.Column():
|
199 |
-
base_image = gr.Image(label="Base Image", type="numpy")
|
200 |
-
with gr.Tab("concepts
|
201 |
with gr.Row():
|
202 |
with gr.Group():
|
203 |
-
concept_image1 = gr.Image(label="Concept Image 1", type="numpy")
|
204 |
-
concept_name1 = gr.Dropdown(concept_options, label="concept
|
205 |
-
|
206 |
with gr.Group():
|
207 |
concept_image2 = gr.Image(label="Concept Image 2 (Optional)", type="numpy")
|
208 |
-
concept_name2 = gr.Dropdown(concept_options, label="concept
|
209 |
-
|
210 |
-
with gr.Tab("optional -
|
211 |
with gr.Group():
|
212 |
concept_image3 = gr.Image(label="Concept Image 3 (Optional)", type="numpy")
|
213 |
-
concept_name3 = gr.Dropdown(concept_options, label="concept
|
214 |
-
|
215 |
-
|
|
|
216 |
|
217 |
with gr.Accordion("Advanced options", open=False):
|
218 |
prompt = gr.Textbox(label="Guidance Prompt (Optional)", placeholder="Optional text prompt to guide generation")
|
219 |
with gr.Row():
|
220 |
scale = gr.Slider(minimum=0.1, maximum=2.0, value=1.0, step=0.1, label="Scale")
|
221 |
randomize_seed = gr.Checkbox(value=True, label="Randomize seed")
|
222 |
-
seed = gr.Number(value=0, label="Seed", precision=0)
|
|
|
|
|
|
|
|
|
223 |
|
224 |
with gr.Column():
|
225 |
-
output_image = gr.Image(label="
|
226 |
-
submit_btn = gr.Button("Generate")
|
227 |
|
228 |
|
229 |
submit_btn.click(
|
@@ -241,6 +265,22 @@ following the algorithm proposed in [*IP-Composer: Semantic Composition of Visua
|
|
241 |
],
|
242 |
outputs=[output_image]
|
243 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
244 |
|
245 |
|
246 |
|
|
|
49 |
"season": "season_descriptions.npy",
|
50 |
"material": "material_descriptions_with_gems.npy"
|
51 |
}
|
52 |
+
RANKS_MAP={
|
53 |
+
"age": 30,
|
54 |
+
"animal fur": 80,
|
55 |
+
"dogs": 30,
|
56 |
+
"emotions": 30,
|
57 |
+
"flowers": 30,
|
58 |
+
"fruit/vegtable": 30,
|
59 |
+
"outfit type": 30,
|
60 |
+
"outfit pattern (including color)": 80,
|
61 |
+
"patterns": 80,
|
62 |
+
"patterns (including color)": 80,
|
63 |
+
"vehicle": 30,
|
64 |
+
"daytime": 30,
|
65 |
+
"pose": 30,
|
66 |
+
"season": 30,
|
67 |
+
"material": 80,
|
68 |
+
}
|
69 |
concept_options = list(CONCEPTS_MAP.keys())
|
70 |
|
71 |
|
|
|
75 |
seed = random.randint(0, MAX_SEED)
|
76 |
return seed
|
77 |
|
78 |
+
def change_rank_default(concept_name):
|
79 |
+
return RANKS_MAP.get(concept_name, 30)
|
80 |
+
|
81 |
@spaces.GPU
|
82 |
def get_image_embeds(pil_image, model=clip_model, preproc=preprocess, dev=device):
|
83 |
"""Get CLIP image embeddings for a given PIL image"""
|
|
|
216 |
|
217 |
with gr.Row():
|
218 |
with gr.Column():
|
219 |
+
base_image = gr.Image(label="Base Image (Required)", type="numpy")
|
220 |
+
with gr.Tab("concepts"):
|
221 |
with gr.Row():
|
222 |
with gr.Group():
|
223 |
+
concept_image1 = gr.Image(label="Concept Image 1 (Required)", type="numpy")
|
224 |
+
concept_name1 = gr.Dropdown(concept_options, label="concept 1", value=None, info="concept type")
|
225 |
+
|
226 |
with gr.Group():
|
227 |
concept_image2 = gr.Image(label="Concept Image 2 (Optional)", type="numpy")
|
228 |
+
concept_name2 = gr.Dropdown(concept_options, label="concept 2", value=None, info="concept type")
|
229 |
+
|
230 |
+
with gr.Tab("optional - 3rd concept"):
|
231 |
with gr.Group():
|
232 |
concept_image3 = gr.Image(label="Concept Image 3 (Optional)", type="numpy")
|
233 |
+
concept_name3 = gr.Dropdown(concept_options, label="concept 3", value= None, info="concept type")
|
234 |
+
|
235 |
+
|
236 |
+
submit_btn = gr.Button("Generate")
|
237 |
|
238 |
with gr.Accordion("Advanced options", open=False):
|
239 |
prompt = gr.Textbox(label="Guidance Prompt (Optional)", placeholder="Optional text prompt to guide generation")
|
240 |
with gr.Row():
|
241 |
scale = gr.Slider(minimum=0.1, maximum=2.0, value=1.0, step=0.1, label="Scale")
|
242 |
randomize_seed = gr.Checkbox(value=True, label="Randomize seed")
|
243 |
+
seed = gr.Number(value=0, label="Seed", precision=0)
|
244 |
+
with gr.Row():
|
245 |
+
rank1 = gr.Slider(minimum=1, maximum=50, value=30, step=1, label="rank concept 1", info="rank of projection matrix")
|
246 |
+
rank2 = gr.Slider(minimum=1, maximum=50, value=30, step=1, label="rank concept 2")
|
247 |
+
rank3 = gr.Slider(minimum=1, maximum=50, value=30, step=1, label="rank concept 3")
|
248 |
|
249 |
with gr.Column():
|
250 |
+
output_image = gr.Image(label="composed output", show_label=True)
|
|
|
251 |
|
252 |
|
253 |
submit_btn.click(
|
|
|
265 |
],
|
266 |
outputs=[output_image]
|
267 |
)
|
268 |
+
|
269 |
+
concept_name1.select(
|
270 |
+
fn= change_rank_default,
|
271 |
+
inputs=[concept_name1],
|
272 |
+
outputs=[rank1]
|
273 |
+
)
|
274 |
+
concept_name2.select(
|
275 |
+
fn= change_rank_default,
|
276 |
+
inputs=[concept_name2],
|
277 |
+
outputs=[rank2]
|
278 |
+
)
|
279 |
+
concept_name3.select(
|
280 |
+
fn= change_rank_default,
|
281 |
+
inputs=[concept_name3],
|
282 |
+
outputs=[rank3]
|
283 |
+
)
|
284 |
|
285 |
|
286 |
|