Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -155,9 +155,10 @@ example_prompts = [
|
|
155 |
|
156 |
examples = {
|
157 |
"A person reaching for stars":[
|
|
|
158 |
"examples/A person reaching fo_1.png",
|
159 |
"examples/A person reaching fo_2.png",
|
160 |
-
"examples/A person reaching fo_3.png",
|
161 |
"examples/A person reaching fo_4.png",
|
162 |
"examples/A person reaching fo_5.png",
|
163 |
"examples/A person reaching fo_6.png",
|
@@ -166,9 +167,10 @@ examples = {
|
|
166 |
"examples/A person reaching fo_10.png",
|
167 |
],
|
168 |
"Abandoned robot at the depth of the sea":[
|
|
|
169 |
"examples/Abandoned robot at t_1.png",
|
170 |
"examples/Abandoned robot at t_2.png",
|
171 |
-
"examples/Abandoned robot at t_3.png",
|
172 |
"examples/Abandoned robot at t_4.png",
|
173 |
"examples/Abandoned robot at t_5.png",
|
174 |
"examples/Abandoned robot at t_6.png",
|
@@ -177,9 +179,10 @@ examples = {
|
|
177 |
"examples/Abandoned robot at t_10.png",
|
178 |
],
|
179 |
"Cityscape during a thunderstorm":[
|
|
|
180 |
"examples/Cityscape during a t_1.png",
|
181 |
"examples/Cityscape during a t_2.png",
|
182 |
-
"examples/Cityscape during a t_3.png",
|
183 |
"examples/Cityscape during a t_4.png",
|
184 |
"examples/Cityscape during a t_5.png",
|
185 |
"examples/Cityscape during a t_6.png",
|
@@ -188,9 +191,10 @@ examples = {
|
|
188 |
"examples/Cityscape during a t_10.png",
|
189 |
],
|
190 |
"Human in a frame":[
|
|
|
191 |
"examples/Human in a frame_1.png",
|
192 |
"examples/Human in a frame_2.png",
|
193 |
-
"examples/Human in a frame_3.png",
|
194 |
"examples/Human in a frame_4.png",
|
195 |
"examples/Human in a frame_5.png",
|
196 |
"examples/Human in a frame_6.png",
|
@@ -199,9 +203,10 @@ examples = {
|
|
199 |
"examples/Human in a frame_10.png",
|
200 |
],
|
201 |
"Inside an abondoned train, window view":[
|
|
|
202 |
"examples/Inside an abondoned _1.png",
|
203 |
"examples/Inside an abondoned _2.png",
|
204 |
-
"examples/Inside an abondoned _3.png",
|
205 |
"examples/Inside an abondoned _4.png",
|
206 |
"examples/Inside an abondoned _5.png",
|
207 |
"examples/Inside an abondoned _6.png",
|
@@ -210,9 +215,10 @@ examples = {
|
|
210 |
"examples/Inside an abondoned _10.png",
|
211 |
],
|
212 |
"Lonely astronaut in abyss":[
|
|
|
213 |
"examples/Lonely astronaut in _1.png",
|
214 |
"examples/Lonely astronaut in _2.png",
|
215 |
-
"examples/Lonely astronaut in _3.png",
|
216 |
"examples/Lonely astronaut in _4.png",
|
217 |
"examples/Lonely astronaut in _5.png",
|
218 |
"examples/Lonely astronaut in _6.png",
|
@@ -221,9 +227,10 @@ examples = {
|
|
221 |
"examples/Lonely astronaut in _10.png",
|
222 |
],
|
223 |
"Painting of a lady":[
|
|
|
224 |
"examples/Painting of a lady_1.png",
|
225 |
"examples/Painting of a lady_2.png",
|
226 |
-
"examples/Painting of a lady_3.png",
|
227 |
"examples/Painting of a lady_4.png",
|
228 |
"examples/Painting of a lady_5.png",
|
229 |
"examples/Painting of a lady_6.png",
|
@@ -258,8 +265,8 @@ def submit_comment(comment):
|
|
258 |
clear_botton = gr.Button("Clear comments", interactive=len(comments) != 0)
|
259 |
|
260 |
return (gr.Image(value=comment_images[0], label=f"image {image_index+1}/{len(comment_images)}", show_label=True),
|
261 |
-
gr.Text(label="Comment", show_label=False, lines=2, max_lines=3, placeholder="Enter your comment", value=next_comment, container=False),
|
262 |
-
gr.Button(f"Extract visual preference from {len(comments)} comments", interactive=len(comments) != 0),
|
263 |
clear_botton
|
264 |
)
|
265 |
|
@@ -275,7 +282,7 @@ def next_image():
|
|
275 |
|
276 |
image_index = (image_index + 1) % len(comment_images)
|
277 |
|
278 |
-
return gr.Image(value=comment_images[0], label=f"image {image_index+1}/{len(comment_images)}", show_label=True), gr.Text(label="Comment", show_label=False, lines=2, max_lines=3, placeholder="Enter your comment", value=next_comment, container=False)
|
279 |
|
280 |
def previous_image():
|
281 |
global comment_images, image_index
|
@@ -291,17 +298,19 @@ def previous_image():
|
|
291 |
|
292 |
image_index = (image_index - 1) % len(comment_images)
|
293 |
|
294 |
-
return gr.Image(value=comment_images[0], label=f"image {image_index+1}/{len(comment_images)}", show_label=True), gr.Text(label="Comment", show_label=False, lines=2, max_lines=3, placeholder="Enter your comment", value=next_comment, container=False)
|
295 |
|
296 |
def clear_comments():
|
297 |
comments.clear()
|
298 |
-
extract_vp_botton = gr.Button(f"Extract visual preference from {len(comments)} comments", interactive=len(comments) != 0)
|
299 |
clear_botton = gr.Button("Clear comments", interactive=len(comments) != 0)
|
300 |
return extract_vp_botton, clear_botton
|
301 |
|
302 |
@spaces.GPU(duration=120)
|
303 |
def extract_vp_from_vpe():
|
304 |
global comments
|
|
|
|
|
305 |
|
306 |
prompt = """I will provide a set of artworks along with accompanying comments from a person. Analyze these artworks and the comments on them and identify artistic features such as present or mentioned colors, style, composition, mood, medium, texture, brushwork, lighting, shadow effects, perspective, and other noteworthy elements.
|
307 |
Your task is to extract the artistic features the person likes and dislikes based on both the artworks' features and the person's comments. Focus solely on artistic aspects and refrain from considering subject matter.
|
@@ -345,6 +354,7 @@ Here are the images and their corresponding comments:
|
|
345 |
return positive_vp, negative_vp
|
346 |
|
347 |
def extract_vp():
|
|
|
348 |
if valid_api == "":
|
349 |
positive_vp, negative_vp = extract_vp_from_vpe()
|
350 |
|
@@ -439,7 +449,7 @@ Follow the example format and ensure that your output consists of two lists of k
|
|
439 |
|
440 |
gr.Info("Visual preference successfully extracted.")
|
441 |
|
442 |
-
return gr.Textbox(label="Liked visual attributes", lines=3, value=positive_vp, interactive=True), gr.Textbox(label="Disliked visual attributes", lines=1, value=negative_vp, interactive=True), gr.Button("Run", scale=0, interactive=True)
|
443 |
|
444 |
def api_fn(api):
|
445 |
global valid_api
|
@@ -465,8 +475,9 @@ def api_fn(api):
|
|
465 |
|
466 |
|
467 |
@spaces.GPU(duration=45)
|
468 |
-
def generate(prompt, vp_pos, vp_neg, slider, example_prompt, gallery):
|
469 |
if vp_pos == "" and vp_neg == "":
|
|
|
470 |
slider = 0
|
471 |
|
472 |
for filter in word_list:
|
@@ -474,14 +485,20 @@ def generate(prompt, vp_pos, vp_neg, slider, example_prompt, gallery):
|
|
474 |
raise gr.Error("Please try again with a different prompt")
|
475 |
if re.search(rf"\b{filter}\b", vp_pos) or re.search(rf"\b{filter}\b", vp_neg):
|
476 |
raise gr.Error("Please try again with a different visual preference")
|
|
|
|
|
|
|
|
|
|
|
477 |
|
478 |
-
print(f"
|
479 |
image = pipe(prompt=prompt,
|
480 |
-
num_inference_steps=
|
481 |
vp_pos=vp_pos,
|
482 |
vp_neg=vp_neg,
|
483 |
vp_degree_pos=slider,
|
484 |
-
vp_degree_neg=slider
|
|
|
485 |
).images[0]
|
486 |
|
487 |
global example_prompts, examples
|
@@ -490,7 +507,7 @@ def generate(prompt, vp_pos, vp_neg, slider, example_prompt, gallery):
|
|
490 |
example_prompts.append(example_prompts[0])
|
491 |
example_prompts = example_prompts[1:]
|
492 |
|
493 |
-
example_prompt = gr.Markdown(f"
|
494 |
if len(examples[example_prompts[0]]) == 10:
|
495 |
examples[example_prompts[0]] = examples[example_prompts[0]][:-1]
|
496 |
|
@@ -517,14 +534,14 @@ def upload_file(files):
|
|
517 |
comment_images = [file_path] + comment_images
|
518 |
|
519 |
next_comment = ""
|
520 |
-
return gr.Image(value=comment_images[0], label=f"image {image_index+1}/{len(comment_images)}", show_label=True), gr.Text(label="Comment", show_label=False, lines=2, max_lines=3, placeholder="Enter your comment", value=next_comment, container=False)
|
521 |
|
522 |
def next_prompt():
|
523 |
global example_prompts, examples
|
524 |
example_prompts.append(example_prompts[0])
|
525 |
example_prompts = example_prompts[1:]
|
526 |
|
527 |
-
example_prompt = gr.Markdown(f"
|
528 |
gallery = gr.Gallery(
|
529 |
value=examples[example_prompts[0]],
|
530 |
label="",
|
@@ -543,7 +560,7 @@ def previous_prompt():
|
|
543 |
example_prompts = example_prompts[1:]
|
544 |
example_prompts = example_prompts[::-1]
|
545 |
|
546 |
-
example_prompt = gr.Markdown(f"
|
547 |
gallery = gr.Gallery(
|
548 |
value=examples[example_prompts[0]],
|
549 |
label="",
|
@@ -596,21 +613,22 @@ with gr.Blocks(css=css, title="ViPer Demo", theme=gr.themes.Base()) as demo:
|
|
596 |
show_label=False,
|
597 |
lines=2,
|
598 |
max_lines=3,
|
599 |
-
placeholder="Enter your comment",
|
600 |
container=False,
|
601 |
)
|
602 |
|
603 |
with gr.Row():
|
|
|
604 |
submit_comment_button = gr.Button("Submit comment", scale=0)
|
605 |
-
|
606 |
-
next_image_botton = gr.Button("Next Image", scale=0)
|
607 |
|
608 |
file_output = gr.File(visible=False)
|
609 |
-
upload_button = gr.UploadButton("Click to upload images", file_types=["image"], file_count="multiple")
|
610 |
-
|
611 |
-
clear_botton = gr.Button("Clear comments", interactive=len(comments) != 0)
|
612 |
|
613 |
-
with gr.
|
|
|
|
|
|
|
|
|
614 |
with gr.Row():
|
615 |
api = gr.Text(
|
616 |
max_lines=1,
|
@@ -620,14 +638,9 @@ with gr.Blocks(css=css, title="ViPer Demo", theme=gr.themes.Base()) as demo:
|
|
620 |
|
621 |
api_button = gr.Button("Enter", scale=0)
|
622 |
|
623 |
-
extract_vp_botton = gr.Button(f"Extract visual preference from {len(comments)} comments", interactive=len(comments) != 0)
|
624 |
|
625 |
with gr.Column(elem_id="gen-container"):
|
626 |
-
gr.Markdown(f"""
|
627 |
-
You can edit your visual preference in case of hallucinations.
|
628 |
-
"""
|
629 |
-
)
|
630 |
-
|
631 |
positive_extracted_vp = gr.Textbox(
|
632 |
label="Liked visual attributes",
|
633 |
lines=3,
|
@@ -639,6 +652,11 @@ with gr.Blocks(css=css, title="ViPer Demo", theme=gr.themes.Base()) as demo:
|
|
639 |
lines=1,
|
640 |
value="",
|
641 |
)
|
|
|
|
|
|
|
|
|
|
|
642 |
|
643 |
gr.Markdown(f"""
|
644 |
## Step 2: Personalized image generation (using Stable Diffusion XL)
|
@@ -652,18 +670,39 @@ with gr.Blocks(css=css, title="ViPer Demo", theme=gr.themes.Base()) as demo:
|
|
652 |
|
653 |
|
654 |
prompt = gr.Dropdown(
|
655 |
-
example_prompts, label="Prompt", info="Enter your prompt", allow_custom_value=True, multiselect=False, show_label=False
|
656 |
)
|
657 |
|
658 |
-
run_button = gr.Button("Run", scale=0, interactive=True)
|
659 |
|
660 |
result = gr.Image(label="Result", show_label=False, interactive=False)
|
661 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
662 |
with gr.Row(elem_id="main-container"):
|
663 |
-
with gr.Accordion("
|
664 |
|
665 |
|
666 |
-
example_prompt = gr.Markdown(f"
|
667 |
gallery = gr.Gallery(
|
668 |
value=examples[example_prompts[0]],
|
669 |
label="",
|
@@ -674,8 +713,8 @@ with gr.Blocks(css=css, title="ViPer Demo", theme=gr.themes.Base()) as demo:
|
|
674 |
height=500)
|
675 |
|
676 |
with gr.Row():
|
677 |
-
pre_prompt_button = gr.Button("Previous prompt", scale=1, interactive=True)
|
678 |
-
next_prompt_button = gr.Button("Next prompt", scale=1, interactive=True)
|
679 |
|
680 |
|
681 |
submit_comment_button.click(
|
@@ -710,7 +749,7 @@ with gr.Blocks(css=css, title="ViPer Demo", theme=gr.themes.Base()) as demo:
|
|
710 |
|
711 |
run_button.click(
|
712 |
fn = generate,
|
713 |
-
inputs = [prompt, positive_extracted_vp, negative_extracted_vp, slider, example_prompt, gallery],
|
714 |
outputs = [result, example_prompt, gallery],
|
715 |
)
|
716 |
|
|
|
155 |
|
156 |
examples = {
|
157 |
"A person reaching for stars":[
|
158 |
+
"examples/A person reaching fo_0.png",
|
159 |
"examples/A person reaching fo_1.png",
|
160 |
"examples/A person reaching fo_2.png",
|
161 |
+
#"examples/A person reaching fo_3.png",
|
162 |
"examples/A person reaching fo_4.png",
|
163 |
"examples/A person reaching fo_5.png",
|
164 |
"examples/A person reaching fo_6.png",
|
|
|
167 |
"examples/A person reaching fo_10.png",
|
168 |
],
|
169 |
"Abandoned robot at the depth of the sea":[
|
170 |
+
"examples/Abandoned robot at t_0.png",
|
171 |
"examples/Abandoned robot at t_1.png",
|
172 |
"examples/Abandoned robot at t_2.png",
|
173 |
+
#"examples/Abandoned robot at t_3.png",
|
174 |
"examples/Abandoned robot at t_4.png",
|
175 |
"examples/Abandoned robot at t_5.png",
|
176 |
"examples/Abandoned robot at t_6.png",
|
|
|
179 |
"examples/Abandoned robot at t_10.png",
|
180 |
],
|
181 |
"Cityscape during a thunderstorm":[
|
182 |
+
"examples/Cityscape during a t_0.png",
|
183 |
"examples/Cityscape during a t_1.png",
|
184 |
"examples/Cityscape during a t_2.png",
|
185 |
+
#"examples/Cityscape during a t_3.png",
|
186 |
"examples/Cityscape during a t_4.png",
|
187 |
"examples/Cityscape during a t_5.png",
|
188 |
"examples/Cityscape during a t_6.png",
|
|
|
191 |
"examples/Cityscape during a t_10.png",
|
192 |
],
|
193 |
"Human in a frame":[
|
194 |
+
"examples/Human in a frame_0.png",
|
195 |
"examples/Human in a frame_1.png",
|
196 |
"examples/Human in a frame_2.png",
|
197 |
+
#"examples/Human in a frame_3.png",
|
198 |
"examples/Human in a frame_4.png",
|
199 |
"examples/Human in a frame_5.png",
|
200 |
"examples/Human in a frame_6.png",
|
|
|
203 |
"examples/Human in a frame_10.png",
|
204 |
],
|
205 |
"Inside an abondoned train, window view":[
|
206 |
+
"examples/Inside an abondoned _0.png",
|
207 |
"examples/Inside an abondoned _1.png",
|
208 |
"examples/Inside an abondoned _2.png",
|
209 |
+
#"examples/Inside an abondoned _3.png",
|
210 |
"examples/Inside an abondoned _4.png",
|
211 |
"examples/Inside an abondoned _5.png",
|
212 |
"examples/Inside an abondoned _6.png",
|
|
|
215 |
"examples/Inside an abondoned _10.png",
|
216 |
],
|
217 |
"Lonely astronaut in abyss":[
|
218 |
+
"examples/Lonely astronaut in _0.png",
|
219 |
"examples/Lonely astronaut in _1.png",
|
220 |
"examples/Lonely astronaut in _2.png",
|
221 |
+
#"examples/Lonely astronaut in _3.png",
|
222 |
"examples/Lonely astronaut in _4.png",
|
223 |
"examples/Lonely astronaut in _5.png",
|
224 |
"examples/Lonely astronaut in _6.png",
|
|
|
227 |
"examples/Lonely astronaut in _10.png",
|
228 |
],
|
229 |
"Painting of a lady":[
|
230 |
+
"examples/Painting of a lady_0.png",
|
231 |
"examples/Painting of a lady_1.png",
|
232 |
"examples/Painting of a lady_2.png",
|
233 |
+
#"examples/Painting of a lady_3.png",
|
234 |
"examples/Painting of a lady_4.png",
|
235 |
"examples/Painting of a lady_5.png",
|
236 |
"examples/Painting of a lady_6.png",
|
|
|
265 |
clear_botton = gr.Button("Clear comments", interactive=len(comments) != 0)
|
266 |
|
267 |
return (gr.Image(value=comment_images[0], label=f"image {image_index+1}/{len(comment_images)}", show_label=True),
|
268 |
+
gr.Text(label="Comment", show_label=False, lines=2, max_lines=3, placeholder="Enter your comment. The more detailed the better.", value=next_comment, container=False),
|
269 |
+
gr.Button(f"Extract visual preference from {len(comments)} comments", interactive=len(comments) != 0, variant="primary"),
|
270 |
clear_botton
|
271 |
)
|
272 |
|
|
|
282 |
|
283 |
image_index = (image_index + 1) % len(comment_images)
|
284 |
|
285 |
+
return gr.Image(value=comment_images[0], label=f"image {image_index+1}/{len(comment_images)}", show_label=True), gr.Text(label="Comment", show_label=False, lines=2, max_lines=3, placeholder="Enter your comment. The more detailed the better.", value=next_comment, container=False)
|
286 |
|
287 |
def previous_image():
|
288 |
global comment_images, image_index
|
|
|
298 |
|
299 |
image_index = (image_index - 1) % len(comment_images)
|
300 |
|
301 |
+
return gr.Image(value=comment_images[0], label=f"image {image_index+1}/{len(comment_images)}", show_label=True), gr.Text(label="Comment", show_label=False, lines=2, max_lines=3, placeholder="Enter your comment. The more detailed the better.", value=next_comment, container=False)
|
302 |
|
303 |
def clear_comments():
|
304 |
comments.clear()
|
305 |
+
extract_vp_botton = gr.Button(f"Extract visual preference from {len(comments)} comments", interactive=len(comments) != 0, variant="primary")
|
306 |
clear_botton = gr.Button("Clear comments", interactive=len(comments) != 0)
|
307 |
return extract_vp_botton, clear_botton
|
308 |
|
309 |
@spaces.GPU(duration=120)
|
310 |
def extract_vp_from_vpe():
|
311 |
global comments
|
312 |
+
if len(comments) < 8:
|
313 |
+
gr.Warning("Number of comments less than 8 could lead to errors.")
|
314 |
|
315 |
prompt = """I will provide a set of artworks along with accompanying comments from a person. Analyze these artworks and the comments on them and identify artistic features such as present or mentioned colors, style, composition, mood, medium, texture, brushwork, lighting, shadow effects, perspective, and other noteworthy elements.
|
316 |
Your task is to extract the artistic features the person likes and dislikes based on both the artworks' features and the person's comments. Focus solely on artistic aspects and refrain from considering subject matter.
|
|
|
354 |
return positive_vp, negative_vp
|
355 |
|
356 |
def extract_vp():
|
357 |
+
|
358 |
if valid_api == "":
|
359 |
positive_vp, negative_vp = extract_vp_from_vpe()
|
360 |
|
|
|
449 |
|
450 |
gr.Info("Visual preference successfully extracted.")
|
451 |
|
452 |
+
return gr.Textbox(label="Liked visual attributes", lines=3, value=positive_vp, interactive=True), gr.Textbox(label="Disliked visual attributes", lines=1, value=negative_vp, interactive=True), gr.Button("Run personalized generation", scale=0, interactive=True, variant="primary")
|
453 |
|
454 |
def api_fn(api):
|
455 |
global valid_api
|
|
|
475 |
|
476 |
|
477 |
@spaces.GPU(duration=45)
|
478 |
+
def generate(prompt, vp_pos, vp_neg, slider, example_prompt, gallery, num_inference_steps, seed, randomize_seed):
|
479 |
if vp_pos == "" and vp_neg == "":
|
480 |
+
gr.Warning("Visual preference is empty.")
|
481 |
slider = 0
|
482 |
|
483 |
for filter in word_list:
|
|
|
485 |
raise gr.Error("Please try again with a different prompt")
|
486 |
if re.search(rf"\b{filter}\b", vp_pos) or re.search(rf"\b{filter}\b", vp_neg):
|
487 |
raise gr.Error("Please try again with a different visual preference")
|
488 |
+
|
489 |
+
if randomize_seed:
|
490 |
+
seed = random.randint(0, MAX_SEED)
|
491 |
+
|
492 |
+
generator = torch.Generator().manual_seed(seed)
|
493 |
|
494 |
+
print(f"Prompt: {prompt}")
|
495 |
image = pipe(prompt=prompt,
|
496 |
+
num_inference_steps=num_inference_steps,
|
497 |
vp_pos=vp_pos,
|
498 |
vp_neg=vp_neg,
|
499 |
vp_degree_pos=slider,
|
500 |
+
vp_degree_neg=slider,
|
501 |
+
generator=generator
|
502 |
).images[0]
|
503 |
|
504 |
global example_prompts, examples
|
|
|
507 |
example_prompts.append(example_prompts[0])
|
508 |
example_prompts = example_prompts[1:]
|
509 |
|
510 |
+
example_prompt = gr.Markdown(f"Prompt: {example_prompts[0]}")
|
511 |
if len(examples[example_prompts[0]]) == 10:
|
512 |
examples[example_prompts[0]] = examples[example_prompts[0]][:-1]
|
513 |
|
|
|
534 |
comment_images = [file_path] + comment_images
|
535 |
|
536 |
next_comment = ""
|
537 |
+
return gr.Image(value=comment_images[0], label=f"image {image_index+1}/{len(comment_images)}", show_label=True), gr.Text(label="Comment", show_label=False, lines=2, max_lines=3, placeholder="Enter your comment. The more detailed the better.", value=next_comment, container=False)
|
538 |
|
539 |
def next_prompt():
|
540 |
global example_prompts, examples
|
541 |
example_prompts.append(example_prompts[0])
|
542 |
example_prompts = example_prompts[1:]
|
543 |
|
544 |
+
example_prompt = gr.Markdown(f"Prompt: {example_prompts[0]}")
|
545 |
gallery = gr.Gallery(
|
546 |
value=examples[example_prompts[0]],
|
547 |
label="",
|
|
|
560 |
example_prompts = example_prompts[1:]
|
561 |
example_prompts = example_prompts[::-1]
|
562 |
|
563 |
+
example_prompt = gr.Markdown(f"Prompt: {example_prompts[0]}")
|
564 |
gallery = gr.Gallery(
|
565 |
value=examples[example_prompts[0]],
|
566 |
label="",
|
|
|
613 |
show_label=False,
|
614 |
lines=2,
|
615 |
max_lines=3,
|
616 |
+
placeholder="Enter your comment. The more detailed the better.",
|
617 |
container=False,
|
618 |
)
|
619 |
|
620 |
with gr.Row():
|
621 |
+
previous_image_botton = gr.Button("⬅ Previous Image", scale=0)
|
622 |
submit_comment_button = gr.Button("Submit comment", scale=0)
|
623 |
+
next_image_botton = gr.Button("Skip Image ➡", scale=0)
|
|
|
624 |
|
625 |
file_output = gr.File(visible=False)
|
|
|
|
|
|
|
626 |
|
627 |
+
with gr.Row():
|
628 |
+
upload_button = gr.UploadButton("Click to upload images 📤", file_types=["image"], file_count="multiple")
|
629 |
+
clear_botton = gr.Button("Clear comments 🗑", interactive=len(comments) != 0)
|
630 |
+
|
631 |
+
with gr.Accordion("Enter Claude API (optional)", open=False):
|
632 |
with gr.Row():
|
633 |
api = gr.Text(
|
634 |
max_lines=1,
|
|
|
638 |
|
639 |
api_button = gr.Button("Enter", scale=0)
|
640 |
|
641 |
+
extract_vp_botton = gr.Button(f"Extract visual preference from {len(comments)} comments", interactive=len(comments) != 0, variant="primary")
|
642 |
|
643 |
with gr.Column(elem_id="gen-container"):
|
|
|
|
|
|
|
|
|
|
|
644 |
positive_extracted_vp = gr.Textbox(
|
645 |
label="Liked visual attributes",
|
646 |
lines=3,
|
|
|
652 |
lines=1,
|
653 |
value="",
|
654 |
)
|
655 |
+
|
656 |
+
gr.Markdown(f"""
|
657 |
+
Hint: You can edit your visual preference in case of hallucinations.
|
658 |
+
"""
|
659 |
+
)
|
660 |
|
661 |
gr.Markdown(f"""
|
662 |
## Step 2: Personalized image generation (using Stable Diffusion XL)
|
|
|
670 |
|
671 |
|
672 |
prompt = gr.Dropdown(
|
673 |
+
example_prompts, label="Prompt", info="Enter your prompt or choose an example prompts from the dropdown.", allow_custom_value=True, multiselect=False, show_label=False
|
674 |
)
|
675 |
|
676 |
+
run_button = gr.Button("Run personalized generation", scale=0, interactive=True, variant="primary")
|
677 |
|
678 |
result = gr.Image(label="Result", show_label=False, interactive=False)
|
679 |
|
680 |
+
with gr.Accordion("Advanced Settings", open=False):
|
681 |
+
|
682 |
+
with gr.Row():
|
683 |
+
seed = gr.Slider(
|
684 |
+
label="Seed",
|
685 |
+
minimum=0,
|
686 |
+
maximum=1000,
|
687 |
+
step=1,
|
688 |
+
value=0,
|
689 |
+
)
|
690 |
+
|
691 |
+
num_inference_steps = gr.Slider(
|
692 |
+
label="Number of inference steps",
|
693 |
+
minimum=1,
|
694 |
+
maximum=50,
|
695 |
+
step=1,
|
696 |
+
value=40,
|
697 |
+
)
|
698 |
+
|
699 |
+
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
700 |
+
|
701 |
with gr.Row(elem_id="main-container"):
|
702 |
+
with gr.Accordion("Images generated from the example prompts, but with different extracted preferences. The first image shows the non-personalized baseline generation.", open=False):
|
703 |
|
704 |
|
705 |
+
example_prompt = gr.Markdown(f"Prompt: {example_prompts[0]}")
|
706 |
gallery = gr.Gallery(
|
707 |
value=examples[example_prompts[0]],
|
708 |
label="",
|
|
|
713 |
height=500)
|
714 |
|
715 |
with gr.Row():
|
716 |
+
pre_prompt_button = gr.Button("⬅ Previous prompt", scale=1, interactive=True)
|
717 |
+
next_prompt_button = gr.Button("Next prompt ➡", scale=1, interactive=True)
|
718 |
|
719 |
|
720 |
submit_comment_button.click(
|
|
|
749 |
|
750 |
run_button.click(
|
751 |
fn = generate,
|
752 |
+
inputs = [prompt, positive_extracted_vp, negative_extracted_vp, slider, example_prompt, gallery, num_inference_steps, seed, randomize_seed],
|
753 |
outputs = [result, example_prompt, gallery],
|
754 |
)
|
755 |
|