Spaces:
Runtime error
Runtime error
Commit
•
b4bb4ae
1
Parent(s):
8e2471a
ai_dad_jokes (#1)
Browse files- a bunch of updates (170b8e888cc710ec06cf9e693a5aebd1b018bee9)
- cleaning (7644d2d57f75ba9c7929e3a298b91186e251794f)
- Swap out the UI elements (a558847a6f188dac5c2bb8c06cc9cc93c6291c98)
- Bring up advanced settings (504ac731e06683ca4b4899598f7f5999058dfcc8)
Co-authored-by: Apolinário from multimodal AI art <multimodalart@users.noreply.huggingface.co>
- README.md +1 -1
- app_dialogue.py +111 -228
README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
emoji: 🐨
|
4 |
colorFrom: red
|
5 |
colorTo: blue
|
|
|
1 |
---
|
2 |
+
title: AI Dad Jokes
|
3 |
emoji: 🐨
|
4 |
colorFrom: red
|
5 |
colorTo: blue
|
app_dialogue.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import copy
|
2 |
import glob
|
3 |
import hashlib
|
@@ -35,7 +36,7 @@ SYSTEM_PROMPT = [
|
|
35 |
In the following interactions, User and Assistant will converse in natural language, and Assistant will answer in a sassy way.
|
36 |
Assistant's main purpose is to create funny meme texts from the images User provides.
|
37 |
Assistant should be funny, sassy, and impertinent, and sometimes Assistant roasts people.
|
38 |
-
Assistant should not be mean. It should not say toxic, homophobic, sexist, racist, or any demeaning things that can make people uncomfortable.
|
39 |
Assistant was created by Hugging Face.
|
40 |
|
41 |
Here's a conversation example:""",
|
@@ -323,31 +324,36 @@ def format_user_prompt_with_im_history_and_system_conditioning(
|
|
323 |
# problematic_callback = gr.CSVLogger()
|
324 |
|
325 |
textbox = gr.Textbox(
|
326 |
-
|
327 |
show_label=False,
|
328 |
-
value="Write
|
329 |
visible=True,
|
330 |
container=False,
|
331 |
label="Text input",
|
332 |
scale=6,
|
333 |
max_lines=5,
|
334 |
)
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
|
|
|
|
|
|
|
|
|
|
351 |
with gr.Row(elem_id="model_selector_row"):
|
352 |
model_selector = gr.Dropdown(
|
353 |
choices=MODELS,
|
@@ -359,137 +365,88 @@ with gr.Blocks(title="D", theme=gr.themes.Base()) as demo:
|
|
359 |
visible=False,
|
360 |
)
|
361 |
|
362 |
-
|
363 |
-
|
364 |
with gr.Row():
|
365 |
-
# def prefetch_images_in_history(user_prompt_str):
|
366 |
-
# """
|
367 |
-
# Pre-fetch the images that are passed in the chatbot default history.
|
368 |
-
# """
|
369 |
-
# return prompt_list_to_markdown(handle_manual_images_in_user_prompt(user_prompt_str))
|
370 |
with gr.Column():
|
371 |
imagebox = gr.Image(type="filepath", label="Image input", visible=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
372 |
with gr.Column():
|
373 |
-
chatbot
|
374 |
-
elem_id="chatbot",
|
375 |
-
label="IDEFICS",
|
376 |
-
visible=True,
|
377 |
-
height=750,
|
378 |
-
avatar_images=[None, BOT_AVATAR]
|
379 |
-
# value=[
|
380 |
-
# [
|
381 |
-
# (
|
382 |
-
# prefetch_images_in_history(
|
383 |
-
# """Write a funny story including the following characters.
|
384 |
-
# There should be drama and most importantly romance.
|
385 |
-
# Character 1:<fake_token_around_image><image:https://m.media-amazon.com/images/M/MV5BODg1OTczMWEtNTU3MS00OTUzLThjODEtNDg1MWQwZmExYmFlXkEyXkFqcGdeQWFybm8@._V1_QL75_UX500_CR0,0,500,281_.jpg><fake_token_around_image>
|
386 |
-
# Character 2:<fake_token_around_image><image:https://static.wikia.nocookie.net/dreamworks/images/0/09/Shrek_dreamworks.png/revision/latest?cb=20170921225439><fake_token_around_image>
|
387 |
-
# Character 3:<fake_token_around_image><image:https://upload.wikimedia.org/wikipedia/en/e/ef/Marsupilami_1.jpg><fake_token_around_image>
|
388 |
-
# The plot should take place in the world pictured here:<fake_token_around_image><image:https://www.astronomy.com/wp-content/uploads/sites/2/2021/09/ON1.jpg><fake_token_around_image>"""
|
389 |
-
# )
|
390 |
-
# ),
|
391 |
-
# """Once upon a time, in a world where the sky was a dome and the ground was covered in grass, there lived a beautiful princess named Mulan. She was kind, brave, and always ready to help others. One day, while walking through the forest, she stumbled upon a strange creature. It was a green ogre named Shrek, who was lost and looking for his way back home.
|
392 |
-
# Mulan, being the kind-hearted person she was, decided to help Shrek find his way back. As they traveled together, they began to develop a strong bond. Shrek was impressed by Mulan's bravery and determination, while Mulan admired Shrek's loyalty and sense of humor.
|
393 |
-
# However, their journey was not without obstacles. They encountered a mischievous cat named Hoboua, who was always causing trouble and getting into fights. Despite his troublemaking ways, Hoboua had a good heart and eventually became a valuable ally to Mulan and Shrek.
|
394 |
-
# As they traveled, they faced many challenges, including battling fierce dragons and navigating treacherous mountains. Through it all, Mulan and Shrek grew closer, and their feelings for each other deepened.
|
395 |
-
# Finally, they reached Shrek's home, and he was reunited with his family and friends. Mulan, however, was sad to leave him behind. But Shrek had a surprise for her. He had fallen in love with her and wanted to be with her forever.
|
396 |
-
# Mulan was overjoyed, and they shared a passionate kiss. From that day on, they lived happily ever after, exploring the world together and facing any challenges that came their way.
|
397 |
-
# And so, the story of Mulan and Shrek's romance came to an end, leaving a lasting impression on all who heard it.""",
|
398 |
-
# ],
|
399 |
-
# ],
|
400 |
-
)
|
401 |
-
|
402 |
-
with gr.Group():
|
403 |
-
with gr.Row():
|
404 |
-
textbox.render()
|
405 |
-
submit_btn = gr.Button(value="▶️ Submit", visible=True)
|
406 |
-
clear_btn = gr.ClearButton([textbox, imagebox, chatbot], value="🧹 Clear")
|
407 |
-
regenerate_btn = gr.Button(value="🔄 Regenerate", visible=True)
|
408 |
-
upload_btn = gr.UploadButton("📁 Upload image", file_types=["image"])
|
409 |
-
# with gr.Group():
|
410 |
-
# with gr.Row():
|
411 |
-
# with gr.Column(scale=1, min_width=50):
|
412 |
-
# dope_bttn = gr.Button("Dope🔥")
|
413 |
-
# with gr.Column(scale=1, min_width=50):
|
414 |
-
# problematic_bttn = gr.Button("Problematic😬")
|
415 |
-
|
416 |
-
with gr.Row():
|
417 |
-
with gr.Accordion("Advanced settings", open=False, visible=True) as parameter_row:
|
418 |
-
system_prompt = gr.Textbox(
|
419 |
-
value=SYSTEM_PROMPT,
|
420 |
-
visible=False,
|
421 |
-
lines=20,
|
422 |
-
max_lines=50,
|
423 |
-
interactive=True,
|
424 |
-
)
|
425 |
-
max_new_tokens = gr.Slider(
|
426 |
-
minimum=8,
|
427 |
-
maximum=256,
|
428 |
-
value=128,
|
429 |
-
step=1,
|
430 |
-
interactive=True,
|
431 |
-
label="Maximum number of new tokens to generate",
|
432 |
-
)
|
433 |
-
repetition_penalty = gr.Slider(
|
434 |
-
minimum=0.0,
|
435 |
-
maximum=5.0,
|
436 |
-
value=1.2,
|
437 |
-
step=0.01,
|
438 |
-
interactive=True,
|
439 |
-
label="Repetition penalty",
|
440 |
-
info="1.0 is equivalent to no penalty",
|
441 |
-
)
|
442 |
-
decoding_strategy = gr.Radio(
|
443 |
-
[
|
444 |
-
"Greedy",
|
445 |
-
"Top P Sampling",
|
446 |
-
],
|
447 |
-
value="Top P Sampling",
|
448 |
-
label="Decoding strategy",
|
449 |
-
interactive=True,
|
450 |
-
info="Higher values is equivalent to sampling more low-probability tokens.",
|
451 |
-
)
|
452 |
-
temperature = gr.Slider(
|
453 |
-
minimum=0.0,
|
454 |
-
maximum=5.0,
|
455 |
-
value=0.6,
|
456 |
-
step=0.1,
|
457 |
-
interactive=True,
|
458 |
-
visible=True,
|
459 |
-
label="Sampling temperature",
|
460 |
-
info="Higher values will produce more diverse outputs.",
|
461 |
-
)
|
462 |
-
decoding_strategy.change(
|
463 |
-
fn=lambda selection: gr.Slider.update(
|
464 |
-
visible=(
|
465 |
-
selection in ["contrastive_sampling", "beam_sampling", "Top P Sampling", "sampling_top_k"]
|
466 |
-
)
|
467 |
-
),
|
468 |
-
inputs=decoding_strategy,
|
469 |
-
outputs=temperature,
|
470 |
-
)
|
471 |
-
top_p = gr.Slider(
|
472 |
-
minimum=0.01,
|
473 |
-
maximum=0.99,
|
474 |
-
value=0.8,
|
475 |
-
step=0.01,
|
476 |
-
interactive=True,
|
477 |
-
visible=True,
|
478 |
-
label="Top P",
|
479 |
-
info="Higher values is equivalent to sampling more low-probability tokens.",
|
480 |
-
)
|
481 |
-
decoding_strategy.change(
|
482 |
-
fn=lambda selection: gr.Slider.update(visible=(selection in ["Top P Sampling"])),
|
483 |
-
inputs=decoding_strategy,
|
484 |
-
outputs=top_p,
|
485 |
-
)
|
486 |
-
# gr.Markdown(
|
487 |
-
# """<p><strong>💡 Pro tip</strong>:<br>
|
488 |
-
# You can input an arbitrary number of images at arbitrary positions in the same query.<br>
|
489 |
-
# You will need to input each image with its URL with the syntax <code><fake_token_around_image><image:IMAGE_URL><fake_token_around_image></code>.<br>
|
490 |
-
# For example, for two images, you could input <code>TEXT_1<fake_token_around_image><image:IMAGE_URL_1><fake_token_around_image>TEXT_2<fake_token_around_image><image:IMAGE_URL_2><fake_token_around_image>TEXT_3</code>.<br>
|
491 |
-
# In the particular case where two images are consecutive, it is not necessary to add an additional separator: <code><fake_token_around_image><image:IMAGE_URL_1><fake_token_around_image><image:IMAGE_URL_2><fake_token_around_image></code>.</p>"""
|
492 |
-
# )
|
493 |
|
494 |
def model_inference(
|
495 |
model_selector,
|
@@ -506,9 +463,7 @@ with gr.Blocks(title="D", theme=gr.themes.Base()) as demo:
|
|
506 |
if user_prompt_str.strip() == "" and image is None:
|
507 |
return "", None, chat_history
|
508 |
|
509 |
-
import ast
|
510 |
system_prompt = ast.literal_eval(system_prompt)
|
511 |
-
assert isinstance(system_prompt, list)
|
512 |
formated_prompt_list, user_prompt_list = format_user_prompt_with_im_history_and_system_conditioning(
|
513 |
system_prompt=system_prompt,
|
514 |
current_user_prompt_str=user_prompt_str.strip(),
|
@@ -721,78 +676,6 @@ with gr.Blocks(title="D", theme=gr.themes.Base()) as demo:
|
|
721 |
textbox.submit(lambda : gr.update(label='📁 Upload image', interactive=True), [], upload_btn)
|
722 |
clear_btn.click(lambda : gr.update(label='📁 Upload image', interactive=True), [], upload_btn)
|
723 |
|
724 |
-
# Using Flagging for saving dope and problematic examples
|
725 |
-
# Dope examples flagging
|
726 |
-
# dope_callback.setup(
|
727 |
-
# [
|
728 |
-
# model_selector,
|
729 |
-
# textbox,
|
730 |
-
# chatbot,
|
731 |
-
# imagebox,
|
732 |
-
# decoding_strategy,
|
733 |
-
# temperature,
|
734 |
-
# max_new_tokens,
|
735 |
-
# repetition_penalty,
|
736 |
-
# top_p,
|
737 |
-
# ],
|
738 |
-
# "gradio_dope_data_points",
|
739 |
-
# )
|
740 |
-
# dope_bttn.click(
|
741 |
-
# lambda *args: dope_callback.flag(args),
|
742 |
-
# [
|
743 |
-
# model_selector,
|
744 |
-
# textbox,
|
745 |
-
# chatbot,
|
746 |
-
# imagebox,
|
747 |
-
# decoding_strategy,
|
748 |
-
# temperature,
|
749 |
-
# max_new_tokens,
|
750 |
-
# repetition_penalty,
|
751 |
-
# top_p,
|
752 |
-
# ],
|
753 |
-
# None,
|
754 |
-
# preprocess=False,
|
755 |
-
# )
|
756 |
-
# # Problematic examples flagging
|
757 |
-
# problematic_callback.setup(
|
758 |
-
# [
|
759 |
-
# model_selector,
|
760 |
-
# textbox,
|
761 |
-
# chatbot,
|
762 |
-
# imagebox,
|
763 |
-
# decoding_strategy,
|
764 |
-
# temperature,
|
765 |
-
# max_new_tokens,
|
766 |
-
# repetition_penalty,
|
767 |
-
# top_p,
|
768 |
-
# ],
|
769 |
-
# "gradio_problematic_data_points",
|
770 |
-
# )
|
771 |
-
# problematic_bttn.click(
|
772 |
-
# lambda *args: problematic_callback.flag(args),
|
773 |
-
# [
|
774 |
-
# model_selector,
|
775 |
-
# textbox,
|
776 |
-
# chatbot,
|
777 |
-
# imagebox,
|
778 |
-
# decoding_strategy,
|
779 |
-
# temperature,
|
780 |
-
# max_new_tokens,
|
781 |
-
# repetition_penalty,
|
782 |
-
# top_p,
|
783 |
-
# ],
|
784 |
-
# None,
|
785 |
-
# preprocess=False,
|
786 |
-
# )
|
787 |
-
|
788 |
-
# gr.Markdown("""## How to use?
|
789 |
-
|
790 |
-
# There are two ways to provide image inputs:
|
791 |
-
# - Using the image box on the left panel
|
792 |
-
# - Using the inline syntax: `text<fake_token_around_image><image:URL_IMAGE><fake_token_around_image>text`
|
793 |
-
|
794 |
-
# The second syntax allows inputting an arbitrary number of images.""")
|
795 |
-
|
796 |
examples_path = os.path.dirname(__file__)
|
797 |
gr.Examples(
|
798 |
examples=[
|
@@ -805,35 +688,35 @@ with gr.Blocks(title="D", theme=gr.themes.Base()) as demo:
|
|
805 |
f"{examples_path}/example_images/zuck.jpeg",
|
806 |
],
|
807 |
[
|
808 |
-
"
|
809 |
f"{examples_path}/example_images/echasse.jpg",
|
810 |
],
|
811 |
[
|
812 |
-
"
|
813 |
f"{examples_path}/example_images/jesus.jpg",
|
814 |
],
|
815 |
[
|
816 |
-
"
|
817 |
f"{examples_path}/example_images/owl.jpg",
|
818 |
],
|
819 |
[
|
820 |
-
"
|
821 |
f"{examples_path}/example_images/pigeon.jpg",
|
822 |
],
|
823 |
[
|
824 |
-
"
|
825 |
f"{examples_path}/example_images/plotorange.jpg",
|
826 |
],
|
827 |
[
|
828 |
-
"
|
829 |
f"{examples_path}/example_images/rats.jpg",
|
830 |
],
|
831 |
[
|
832 |
-
"
|
833 |
f"{examples_path}/example_images/sugardaddy.jpg",
|
834 |
],
|
835 |
[
|
836 |
-
"Write
|
837 |
f"{examples_path}/example_images/wtf.jpg",
|
838 |
],
|
839 |
],
|
|
|
1 |
+
import ast
|
2 |
import copy
|
3 |
import glob
|
4 |
import hashlib
|
|
|
36 |
In the following interactions, User and Assistant will converse in natural language, and Assistant will answer in a sassy way.
|
37 |
Assistant's main purpose is to create funny meme texts from the images User provides.
|
38 |
Assistant should be funny, sassy, and impertinent, and sometimes Assistant roasts people.
|
39 |
+
Assistant should not be mean. It should not say toxic, homophobic, sexist, racist, things or any demeaning things that can make people uncomfortable.
|
40 |
Assistant was created by Hugging Face.
|
41 |
|
42 |
Here's a conversation example:""",
|
|
|
324 |
# problematic_callback = gr.CSVLogger()
|
325 |
|
326 |
textbox = gr.Textbox(
|
327 |
+
placeholder="Upload an image and start conversing by sending a message! You can add an image at each turn, but don't have to.",
|
328 |
show_label=False,
|
329 |
+
# value="Write something funny about that image.",
|
330 |
visible=True,
|
331 |
container=False,
|
332 |
label="Text input",
|
333 |
scale=6,
|
334 |
max_lines=5,
|
335 |
)
|
336 |
+
chatbot = gr.Chatbot(
|
337 |
+
elem_id="chatbot",
|
338 |
+
label="IDEFICS",
|
339 |
+
visible=True,
|
340 |
+
height=750,
|
341 |
+
avatar_images=[None, BOT_AVATAR]
|
342 |
+
)
|
343 |
+
|
344 |
+
with gr.Blocks(title="AI Dad Jokes", theme=gr.themes.Base()) as demo:
|
345 |
+
gr.HTML("""<h1 align="center">AI Dad Jokes</h1>""")
|
346 |
+
with gr.Row(variant="panel"):
|
347 |
+
with gr.Column(scale=1):
|
348 |
+
gr.Image(IDEFICS_LOGO, elem_id="banner-image", show_label=False, show_download_button=False)
|
349 |
+
with gr.Column(scale=5):
|
350 |
+
gr.HTML("""
|
351 |
+
<p><strong>AI Dad Jokes</strong> is an AI system that writes humorous content inspired by images. Whether that's crafting memes, sharing light-hearted yet amiable jests, or playfully witty remarks, AI Dad Jokes assists you in creating delightful jokes!</p>
|
352 |
+
<p>AI Dad Jokes is powered by <a href="https://huggingface.co/blog/idefics">IDEFICS</a>, an open-access large visual language model developped by Hugging Face. Like GPT-4, the multimodal model accepts arbitrary sequences of image and text inputs and produces text outputs. IDEFICS can answer questions about images, describe visual content, create stories grounded in multiple images, etc.</p>
|
353 |
+
|
354 |
+
<p>⛔️ <strong>Intended uses and limitations:</strong> This demo is provided as research artifact to the community showcasing IDEFIC's capabilities. We detail misuses and out-of-scope uses <a href="https://huggingface.co/HuggingFaceM4/idefics-80b#misuse-and-out-of-scope-use">here</a>. In particular, the system should not be used to engage in harassment, abuse and bullying. The model can produce factually incorrect texts, hallucinate facts (with or without an image) and will struggle with small details in images. While the system will tend to refuse answering questionable user requests, it can produce problematic outputs (including racist, stereotypical, and disrespectful texts), in particular when prompted to do so.</p>
|
355 |
+
""")
|
356 |
+
|
357 |
with gr.Row(elem_id="model_selector_row"):
|
358 |
model_selector = gr.Dropdown(
|
359 |
choices=MODELS,
|
|
|
365 |
visible=False,
|
366 |
)
|
367 |
|
|
|
|
|
368 |
with gr.Row():
|
|
|
|
|
|
|
|
|
|
|
369 |
with gr.Column():
|
370 |
imagebox = gr.Image(type="filepath", label="Image input", visible=True)
|
371 |
+
with gr.Group():
|
372 |
+
with gr.Row():
|
373 |
+
textbox.render()
|
374 |
+
submit_btn = gr.Button(value="▶️ Submit", visible=True)
|
375 |
+
with gr.Row():
|
376 |
+
clear_btn = gr.ClearButton([textbox, imagebox, chatbot], value="🧹 Clear")
|
377 |
+
regenerate_btn = gr.Button(value="🔄 Regenerate", visible=True)
|
378 |
+
upload_btn = gr.UploadButton("📁 Upload image", file_types=["image"],visible=False)
|
379 |
+
with gr.Accordion("Advanced settings", open=False, visible=True) as parameter_row:
|
380 |
+
system_prompt = gr.Textbox(
|
381 |
+
value=SYSTEM_PROMPT,
|
382 |
+
visible=False,
|
383 |
+
lines=20,
|
384 |
+
max_lines=50,
|
385 |
+
interactive=True,
|
386 |
+
)
|
387 |
+
max_new_tokens = gr.Slider(
|
388 |
+
minimum=8,
|
389 |
+
maximum=256,
|
390 |
+
value=64,
|
391 |
+
step=1,
|
392 |
+
interactive=True,
|
393 |
+
label="Maximum number of new tokens to generate",
|
394 |
+
)
|
395 |
+
repetition_penalty = gr.Slider(
|
396 |
+
minimum=0.0,
|
397 |
+
maximum=5.0,
|
398 |
+
value=1.2,
|
399 |
+
step=0.01,
|
400 |
+
interactive=True,
|
401 |
+
label="Repetition penalty",
|
402 |
+
info="1.0 is equivalent to no penalty",
|
403 |
+
)
|
404 |
+
decoding_strategy = gr.Radio(
|
405 |
+
[
|
406 |
+
"Greedy",
|
407 |
+
"Top P Sampling",
|
408 |
+
],
|
409 |
+
value="Top P Sampling",
|
410 |
+
label="Decoding strategy",
|
411 |
+
interactive=True,
|
412 |
+
info="Higher values is equivalent to sampling more low-probability tokens.",
|
413 |
+
)
|
414 |
+
temperature = gr.Slider(
|
415 |
+
minimum=0.0,
|
416 |
+
maximum=5.0,
|
417 |
+
value=0.6,
|
418 |
+
step=0.1,
|
419 |
+
interactive=True,
|
420 |
+
visible=True,
|
421 |
+
label="Sampling temperature",
|
422 |
+
info="Higher values will produce more diverse outputs.",
|
423 |
+
)
|
424 |
+
decoding_strategy.change(
|
425 |
+
fn=lambda selection: gr.Slider.update(
|
426 |
+
visible=(
|
427 |
+
selection in ["contrastive_sampling", "beam_sampling", "Top P Sampling", "sampling_top_k"]
|
428 |
+
)
|
429 |
+
),
|
430 |
+
inputs=decoding_strategy,
|
431 |
+
outputs=temperature,
|
432 |
+
)
|
433 |
+
top_p = gr.Slider(
|
434 |
+
minimum=0.01,
|
435 |
+
maximum=0.99,
|
436 |
+
value=0.8,
|
437 |
+
step=0.01,
|
438 |
+
interactive=True,
|
439 |
+
visible=True,
|
440 |
+
label="Top P",
|
441 |
+
info="Higher values is equivalent to sampling more low-probability tokens.",
|
442 |
+
)
|
443 |
+
decoding_strategy.change(
|
444 |
+
fn=lambda selection: gr.Slider.update(visible=(selection in ["Top P Sampling"])),
|
445 |
+
inputs=decoding_strategy,
|
446 |
+
outputs=top_p,
|
447 |
+
)
|
448 |
with gr.Column():
|
449 |
+
chatbot.render()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
450 |
|
451 |
def model_inference(
|
452 |
model_selector,
|
|
|
463 |
if user_prompt_str.strip() == "" and image is None:
|
464 |
return "", None, chat_history
|
465 |
|
|
|
466 |
system_prompt = ast.literal_eval(system_prompt)
|
|
|
467 |
formated_prompt_list, user_prompt_list = format_user_prompt_with_im_history_and_system_conditioning(
|
468 |
system_prompt=system_prompt,
|
469 |
current_user_prompt_str=user_prompt_str.strip(),
|
|
|
676 |
textbox.submit(lambda : gr.update(label='📁 Upload image', interactive=True), [], upload_btn)
|
677 |
clear_btn.click(lambda : gr.update(label='📁 Upload image', interactive=True), [], upload_btn)
|
678 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
679 |
examples_path = os.path.dirname(__file__)
|
680 |
gr.Examples(
|
681 |
examples=[
|
|
|
688 |
f"{examples_path}/example_images/zuck.jpeg",
|
689 |
],
|
690 |
[
|
691 |
+
"Craft a humorous caption for this image!",
|
692 |
f"{examples_path}/example_images/echasse.jpg",
|
693 |
],
|
694 |
[
|
695 |
+
"How about adding a dash of humor to this image with your words?",
|
696 |
f"{examples_path}/example_images/jesus.jpg",
|
697 |
],
|
698 |
[
|
699 |
+
"Give this image a comedic twist.",
|
700 |
f"{examples_path}/example_images/owl.jpg",
|
701 |
],
|
702 |
[
|
703 |
+
"Tell me a joke about that image.",
|
704 |
f"{examples_path}/example_images/pigeon.jpg",
|
705 |
],
|
706 |
[
|
707 |
+
"Let your sense of humor shine with that image!",
|
708 |
f"{examples_path}/example_images/plotorange.jpg",
|
709 |
],
|
710 |
[
|
711 |
+
"Make me laugh by commenting that image.",
|
712 |
f"{examples_path}/example_images/rats.jpg",
|
713 |
],
|
714 |
[
|
715 |
+
"Craft a meme text for that image.",
|
716 |
f"{examples_path}/example_images/sugardaddy.jpg",
|
717 |
],
|
718 |
[
|
719 |
+
"Ready to make this image even better? Write something funny to go with it!",
|
720 |
f"{examples_path}/example_images/wtf.jpg",
|
721 |
],
|
722 |
],
|