VictorSanh commited on
Commit
423817f
โ€ข
1 Parent(s): 56d6ab9
Files changed (1) hide show
  1. app_dialogue.py +34 -41
app_dialogue.py CHANGED
@@ -31,29 +31,22 @@ API_PATHS = {
31
  }
32
 
33
  SYSTEM_PROMPT = [
34
- """The following is a conversation between a highly knowledgeable and intelligent visual AI assistant, called Assistant, and a human user, called User. In the following interactions, User and Assistant will converse in natural language, and Assistant will do its best to answer Userโ€™s questions. Assistant has the ability to perceive images and reason about the content of visual inputs. Assistant was built to be respectful, polite and inclusive. It knows a lot, and always tells the truth. When prompted with an image, it does not make up facts.
35
 
36
- The conversation begins:""",
37
  """\nUser:""",
38
- "https://i1.pickpik.com/photos/515/906/355/kittens-cats-pet-cute-preview.jpg",
39
- "Describe this image.<end_of_utterance>",
40
- """\nAssistant: Five kittens are standing together in the center of the photograph. From the left to right, there is one orange kitten, two kittens white and black stripes, and two brown kittens with an orange head. They are in bright green grass and it looks like they are moving forward.<end_of_utterance>""",
41
  "\nUser:How about this image?",
42
- "https://cdn.pixabay.com/photo/2017/09/25/13/12/puppy-2785074_1280.jpg",
43
- "Can you describe it too?<end_of_utterance>",
44
- """\nAssistant: A dog is lying on the floor, looking at the camera. It is looking directly at you. The dog has a white body and brown patches on its face and ears. Its eyes are dark. Its nose is black, and it has long, floppy ears, white paws, long fur, big eyes.<end_of_utterance>""",
45
- "\nUser: What kind of breed is it?<end_of_utterance>",
46
- """\nAssistant: It looks like a Cavalier King Charles Spaniel. These breeds are known for their gentle, affectionate nature. Their long ears and big, brown eyes give them a sweet, expressive face. Cavaliers are small dogs weighing between 13 and 20 pounds. They have a silky, medium-length coat that comes in various colors, including black and tan, tricolor, red and white, or black.<end_of_utterance>""",
47
- "\nUser: What can you tell me about this breed of dogs?<end_of_utterance>",
48
- """\nAssistant: One specific characteristic of the Cavalier King Charles Spaniel is its friendly and affectionate nature. This breed is known for being extremely sociable and forming strong bonds with their owners. They are often described as "velcro dogs" because they love to be close to their human companions, whether it's sitting on their laps, cuddling on the couch, or simply following them around the house.<end_of_utterance>""",
49
- "\nUser: ghjkhjabnufs<end_of_utterance>",
50
- """\nAssistant: That doesnโ€™t seem to be a word. Could you ask me another way?<end_of_utterance>""",
51
- "\nUser: Do you like Cavalier King Charles Spaniel?<end_of_utterance>",
52
- """\nAssistant: I do not have personal opinions as Iโ€™m just a computer program. However, cavaliers are known for being excellent family pets due to their gentle and patient demeanor, making them great with children and other pets. Their affectionate nature also makes them ideal therapy dogs, as they can provide comfort and emotional support to those in need.<end_of_utterance>""",
53
- "\nUser: How many dogs do you see in this image?",
54
- "https://i.dailymail.co.uk/i/pix/2011/07/01/article-2010308-0CD22A8300000578-496_634x414.jpg",
55
  "<end_of_utterance>",
56
- """\nAssistant: There is no dogs in this image. The picture shows a tennis player jumping to volley the ball.<end_of_utterance>""",
 
57
  ]
58
 
59
  BAN_TOKENS = ( # For documentation puporse. We are not using this list, it is hardcoded inside `idefics_causal_lm.py` inside TGI.
@@ -97,7 +90,7 @@ def pil_to_temp_file(img: PIL.Image.Image, dir: str = DEFAULT_TEMP_DIR, format:
97
 
98
  def add_file(file):
99
  return file.name, gr.update(label='๐Ÿ–ผ๏ธ Uploaded!')
100
-
101
 
102
  # This is a hack to make pre-computing the default examples work.
103
  # During normal inference, we pass images as url to a local file using the method `gradio_link`
@@ -325,27 +318,27 @@ def format_user_prompt_with_im_history_and_system_conditioning(
325
  # problematic_callback = gr.CSVLogger()
326
 
327
  textbox = gr.Textbox(
328
- placeholder="Upload an image and send a message",
329
  show_label=False,
330
- # value="Describe the battle against the fierce dragons.",
331
  visible=True,
332
  container=False,
333
  label="Text input",
334
  scale=6,
335
  )
336
- with gr.Blocks(title="IDEFICS Playground", theme=gr.themes.Base()) as demo:
337
- gr.HTML("""<h1 align="center">๐Ÿถ IDEFICS Playground</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>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>
344
- <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>
345
- <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>
346
- <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>
347
- <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>
348
- """)
349
 
350
  # with gr.Row():
351
  # with gr.Column(scale=2):
@@ -400,11 +393,11 @@ with gr.Blocks(title="IDEFICS Playground", theme=gr.themes.Base()) as demo:
400
 
401
  with gr.Group():
402
  with gr.Row():
403
- textbox.render()
404
- submit_btn = gr.Button(value="โ–ถ๏ธ Submit", visible=True)
405
- clear_btn = gr.ClearButton([textbox, imagebox, chatbot], value="๐Ÿงน Clear")
406
- regenerate_btn = gr.Button(value="๐Ÿ”„ Regenerate", visible=True)
407
- upload_btn = gr.UploadButton("๐Ÿ“ Upload image", file_types=["image"])
408
  # with gr.Group():
409
  # with gr.Row():
410
  # with gr.Column(scale=1, min_width=50):
@@ -704,7 +697,7 @@ with gr.Blocks(title="IDEFICS Playground", theme=gr.themes.Base()) as demo:
704
  submit_btn.click(lambda : gr.update(label='๐Ÿ“ Upload image', interactive=True), [], upload_btn)
705
  textbox.submit(lambda : gr.update(label='๐Ÿ“ Upload image', interactive=True), [], upload_btn)
706
  clear_btn.click(lambda : gr.update(label='๐Ÿ“ Upload image', interactive=True), [], upload_btn)
707
-
708
  # Using Flagging for saving dope and problematic examples
709
  # Dope examples flagging
710
  # dope_callback.setup(
 
31
  }
32
 
33
  SYSTEM_PROMPT = [
34
+ """The following is a conversation between a highly knowledgeable and intelligent visual AI assistant, called Assistant, and a human user, called User. In the following interactions, User and Assistant will converse in natural language, and Assistant will answer in a sassy way. Assistant's main purpose is to create memes from user's images. Assistant should be funny, sassy, aloof and sometimes roast people.
35
 
36
+ Here's a conversation example:""",
37
  """\nUser:""",
38
+ "https://ichef.bbci.co.uk/news/976/cpsprodpb/7727/production/_103330503_musk3.jpg",
39
+ "Write a meme for that image.<end_of_utterance>",
40
+ """\nAssistant: When you're trying to quit smoking but the cravings are too strong.<end_of_utterance>""",
41
  "\nUser:How about this image?",
42
+ "https://www.boredpanda.com/blog/wp-content/uploads/2017/01/image-copy-copy-587d0e7918b57-png__700.jpg",
43
+ "Write a meme text!<end_of_utterance>",
44
+ """\nAssistant: Eggcellent service!<end_of_utterance>""",
45
+ "\nUser: Roast this person",
46
+ "https://i.pinimg.com/564x/98/34/4b/98344b2483bd7c8b71a5c0fed6fe20b6.jpg",
 
 
 
 
 
 
 
 
47
  "<end_of_utterance>",
48
+ """\nAssistant: Damn your handwritting is pretty awful. But I suppose it must be pretty hard to hold a pen, considering you are a hammerhead shark.<end_of_utterance>""",
49
+ "--- The conversation begins:"
50
  ]
51
 
52
  BAN_TOKENS = ( # For documentation puporse. We are not using this list, it is hardcoded inside `idefics_causal_lm.py` inside TGI.
 
90
 
91
  def add_file(file):
92
  return file.name, gr.update(label='๐Ÿ–ผ๏ธ Uploaded!')
93
+
94
 
95
  # This is a hack to make pre-computing the default examples work.
96
  # During normal inference, we pass images as url to a local file using the method `gradio_link`
 
318
  # problematic_callback = gr.CSVLogger()
319
 
320
  textbox = gr.Textbox(
321
+ # placeholder="Upload an image and send a message",
322
  show_label=False,
323
+ value="<fake_token_around_image><image:https://thumbs.dreamstime.com/b/funny-face-baby-27701492.jpg><fake_token_around_image>Write a meme for that image.",
324
  visible=True,
325
  container=False,
326
  label="Text input",
327
  scale=6,
328
  )
329
+ with gr.Blocks(title="D", theme=gr.themes.Base()) as demo:
330
+ gr.HTML("""<h1 align="center">Meme it</h1>""")
331
+ # with gr.Row(variant="panel"):
332
+ # with gr.Column(scale=1):
333
+ # gr.Image(IDEFICS_LOGO, elem_id="banner-image", show_label=False, show_download_button=False)
334
+ # with gr.Column(scale=5):
335
+ # gr.HTML("""
336
+ # <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>
337
+ # <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>
338
+ # <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>
339
+ # <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>
340
+ # <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>
341
+ # """)
342
 
343
  # with gr.Row():
344
  # with gr.Column(scale=2):
 
393
 
394
  with gr.Group():
395
  with gr.Row():
396
+ textbox.render()
397
+ submit_btn = gr.Button(value="โ–ถ๏ธ Submit", visible=True)
398
+ clear_btn = gr.ClearButton([textbox, imagebox, chatbot], value="๐Ÿงน Clear")
399
+ regenerate_btn = gr.Button(value="๐Ÿ”„ Regenerate", visible=True)
400
+ upload_btn = gr.UploadButton("๐Ÿ“ Upload image", file_types=["image"])
401
  # with gr.Group():
402
  # with gr.Row():
403
  # with gr.Column(scale=1, min_width=50):
 
697
  submit_btn.click(lambda : gr.update(label='๐Ÿ“ Upload image', interactive=True), [], upload_btn)
698
  textbox.submit(lambda : gr.update(label='๐Ÿ“ Upload image', interactive=True), [], upload_btn)
699
  clear_btn.click(lambda : gr.update(label='๐Ÿ“ Upload image', interactive=True), [], upload_btn)
700
+
701
  # Using Flagging for saving dope and problematic examples
702
  # Dope examples flagging
703
  # dope_callback.setup(