VictorSanh commited on
Commit
170b8e8
β€’
1 Parent(s): 8e2471a

a bunch of updates

Browse files
Files changed (2) hide show
  1. README.md +1 -1
  2. app_dialogue.py +27 -121
README.md CHANGED
@@ -1,5 +1,5 @@
1
  ---
2
- title: Meme it
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,28 @@ def format_user_prompt_with_im_history_and_system_conditioning(
323
  # problematic_callback = gr.CSVLogger()
324
 
325
  textbox = gr.Textbox(
326
- # placeholder="Upload an image and send a message",
327
  show_label=False,
328
- value="Write a meme for that image.",
329
  visible=True,
330
  container=False,
331
  label="Text input",
332
  scale=6,
333
  max_lines=5,
334
  )
335
- with gr.Blocks(title="D", theme=gr.themes.Base()) as demo:
336
- gr.HTML("""<h1 align="center">Meme it</h1>""")
337
- # with gr.Row(variant="panel"):
338
- # with gr.Column(scale=1):
339
- # gr.Image(IDEFICS_LOGO, elem_id="banner-image", show_label=False, show_download_button=False)
340
- # with gr.Column(scale=5):
341
- # gr.HTML("""
342
- # <p>This demo showcases <strong>IDEFICS</strong>, a open-access large visual language model. 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>
343
- # <p>IDEFICS (which stands for <strong>I</strong>mage-aware <strong>D</strong>ecoder <strong>E</strong>nhanced Γ  la <strong>F</strong>lamingo with <strong>I</strong>nterleaved <strong>C</strong>ross-attention<strong>S</strong>) is an open-access reproduction of <a href="https://huggingface.co/papers/2204.14198">Flamingo</a>, a closed-source visual language model developed by Deepmind. IDEFICS was built solely on publicly available data and models. It is currently the only visual language model of this scale (80 billion parameters) that is available in open-access.</p>
344
- # <p>πŸ“š The variants available in this demo were fine-tuned on a mixture of supervised and instruction fine-tuning datasets to make the models more suitable in conversational settings. For more details, we refer to our <a href="https://huggingface.co/blog/idefics">blog post</a>.</p>
345
- # <p>πŸ…ΏοΈ <strong>Intended uses:</strong> This demo along with the <a href="https://huggingface.co/models?sort=trending&amp;search=HuggingFaceM4%2Fidefics">supporting models</a> are provided as research artifacts to the community. We detail misuses and out-of-scope uses <a href="https://huggingface.co/HuggingFaceM4/idefics-80b#misuse-and-out-of-scope-use">here</a>.</p>
346
- # <p>⛔️ <strong>Limitations:</strong> The model can produce factually incorrect texts, hallucinate facts (with or without an image) and will struggle with small details in images. While the model 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. We encourage users to read our findings from evaluating the model for potential biases in the <a href="https://huggingface.co/HuggingFaceM4/idefics-80b#bias-evaluation">model card</a>.</p>
347
- # """)
348
-
349
- # with gr.Row():
350
- # with gr.Column(scale=2):
351
  with gr.Row(elem_id="model_selector_row"):
352
  model_selector = gr.Dropdown(
353
  choices=MODELS,
@@ -362,11 +360,6 @@ with gr.Blocks(title="D", theme=gr.themes.Base()) as demo:
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():
@@ -406,12 +399,6 @@ with gr.Blocks(title="D", theme=gr.themes.Base()) as demo:
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:
@@ -425,7 +412,7 @@ with gr.Blocks(title="D", theme=gr.themes.Base()) as demo:
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",
@@ -483,13 +470,6 @@ with gr.Blocks(title="D", theme=gr.themes.Base()) as demo:
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>&lt;fake_token_around_image&gt;&lt;image:IMAGE_URL&gt;&lt;fake_token_around_image&gt;</code>.<br>
490
- # For example, for two images, you could input <code>TEXT_1&lt;fake_token_around_image&gt;&lt;image:IMAGE_URL_1&gt;&lt;fake_token_around_image&gt;TEXT_2&lt;fake_token_around_image&gt;&lt;image:IMAGE_URL_2&gt;&lt;fake_token_around_image&gt;TEXT_3</code>.<br>
491
- # In the particular case where two images are consecutive, it is not necessary to add an additional separator: <code>&lt;fake_token_around_image&gt;&lt;image:IMAGE_URL_1&gt;&lt;fake_token_around_image&gt;&lt;image:IMAGE_URL_2&gt;&lt;fake_token_around_image&gt;</code>.</p>"""
492
- # )
493
 
494
  def model_inference(
495
  model_selector,
@@ -506,9 +486,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 +699,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 +711,35 @@ with gr.Blocks(title="D", theme=gr.themes.Base()) as demo:
805
  f"{examples_path}/example_images/zuck.jpeg",
806
  ],
807
  [
808
- "Write a meme text for that image.",
809
  f"{examples_path}/example_images/echasse.jpg",
810
  ],
811
  [
812
- "Write a meme text for that image.",
813
  f"{examples_path}/example_images/jesus.jpg",
814
  ],
815
  [
816
- "Write a meme text for that image.",
817
  f"{examples_path}/example_images/owl.jpg",
818
  ],
819
  [
820
- "Write a meme text for that image.",
821
  f"{examples_path}/example_images/pigeon.jpg",
822
  ],
823
  [
824
- "Write a meme text for that image.",
825
  f"{examples_path}/example_images/plotorange.jpg",
826
  ],
827
  [
828
- "Write a meme text for that image.",
829
  f"{examples_path}/example_images/rats.jpg",
830
  ],
831
  [
832
- "Write a meme text for that image.",
833
  f"{examples_path}/example_images/sugardaddy.jpg",
834
  ],
835
  [
836
- "Write a meme text for that image.",
837
  f"{examples_path}/example_images/wtf.jpg",
838
  ],
839
  ],
@@ -848,4 +754,4 @@ with gr.Blocks(title="D", theme=gr.themes.Base()) as demo:
848
  )
849
 
850
  demo.queue(concurrency_count=40, max_size=40)
851
- demo.launch()
 
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
+ with gr.Blocks(title="AI Dad Jokes", theme=gr.themes.Base()) as demo:
337
+ gr.HTML("""<h1 align="center">AI Dad Jokes</h1>""")
338
+ with gr.Row(variant="panel"):
339
+ with gr.Column(scale=1):
340
+ gr.Image(IDEFICS_LOGO, elem_id="banner-image", show_label=False, show_download_button=False)
341
+ with gr.Column(scale=5):
342
+ gr.HTML("""
343
+ <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>
344
+ <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>
345
+
346
+ <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>
347
+ """)
348
+
 
 
 
349
  with gr.Row(elem_id="model_selector_row"):
350
  model_selector = gr.Dropdown(
351
  choices=MODELS,
 
360
 
361
 
362
  with gr.Row():
 
 
 
 
 
363
  with gr.Column():
364
  imagebox = gr.Image(type="filepath", label="Image input", visible=True)
365
  with gr.Column():
 
399
  clear_btn = gr.ClearButton([textbox, imagebox, chatbot], value="🧹 Clear")
400
  regenerate_btn = gr.Button(value="πŸ”„ Regenerate", visible=True)
401
  upload_btn = gr.UploadButton("πŸ“ Upload image", file_types=["image"])
 
 
 
 
 
 
402
 
403
  with gr.Row():
404
  with gr.Accordion("Advanced settings", open=False, visible=True) as parameter_row:
 
412
  max_new_tokens = gr.Slider(
413
  minimum=8,
414
  maximum=256,
415
+ value=64,
416
  step=1,
417
  interactive=True,
418
  label="Maximum number of new tokens to generate",
 
470
  inputs=decoding_strategy,
471
  outputs=top_p,
472
  )
 
 
 
 
 
 
 
473
 
474
  def model_inference(
475
  model_selector,
 
486
  if user_prompt_str.strip() == "" and image is None:
487
  return "", None, chat_history
488
 
 
489
  system_prompt = ast.literal_eval(system_prompt)
 
490
  formated_prompt_list, user_prompt_list = format_user_prompt_with_im_history_and_system_conditioning(
491
  system_prompt=system_prompt,
492
  current_user_prompt_str=user_prompt_str.strip(),
 
699
  textbox.submit(lambda : gr.update(label='πŸ“ Upload image', interactive=True), [], upload_btn)
700
  clear_btn.click(lambda : gr.update(label='πŸ“ Upload image', interactive=True), [], upload_btn)
701
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
702
  examples_path = os.path.dirname(__file__)
703
  gr.Examples(
704
  examples=[
 
711
  f"{examples_path}/example_images/zuck.jpeg",
712
  ],
713
  [
714
+ "Craft a humorous caption for this image!",
715
  f"{examples_path}/example_images/echasse.jpg",
716
  ],
717
  [
718
+ "How about adding a dash of humor to this image with your words?",
719
  f"{examples_path}/example_images/jesus.jpg",
720
  ],
721
  [
722
+ "Give this image a comedic twist.",
723
  f"{examples_path}/example_images/owl.jpg",
724
  ],
725
  [
726
+ "Tell me a joke about that image.",
727
  f"{examples_path}/example_images/pigeon.jpg",
728
  ],
729
  [
730
+ "Let your sense of humor shine with that image!",
731
  f"{examples_path}/example_images/plotorange.jpg",
732
  ],
733
  [
734
+ "Make me laugh by commenting that image.",
735
  f"{examples_path}/example_images/rats.jpg",
736
  ],
737
  [
738
+ "Craft a meme text for that image.",
739
  f"{examples_path}/example_images/sugardaddy.jpg",
740
  ],
741
  [
742
+ "Ready to make this image even better? Write something funny to go with it!",
743
  f"{examples_path}/example_images/wtf.jpg",
744
  ],
745
  ],
 
754
  )
755
 
756
  demo.queue(concurrency_count=40, max_size=40)
757
+ demo.launch(share=True)