Spaces:
Runtime error
Runtime error
VictorSanh
commited on
Commit
โข
423817f
1
Parent(s):
56d6ab9
hello
Browse files- 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
|
35 |
|
36 |
-
|
37 |
"""\nUser:""",
|
38 |
-
"https://
|
39 |
-
"
|
40 |
-
"""\nAssistant:
|
41 |
"\nUser:How about this image?",
|
42 |
-
"https://
|
43 |
-
"
|
44 |
-
"""\nAssistant:
|
45 |
-
"\nUser:
|
46 |
-
"
|
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:
|
|
|
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 |
-
|
331 |
visible=True,
|
332 |
container=False,
|
333 |
label="Text input",
|
334 |
scale=6,
|
335 |
)
|
336 |
-
with gr.Blocks(title="
|
337 |
-
gr.HTML("""<h1 align="center"
|
338 |
-
with gr.Row(variant="panel"):
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
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 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
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&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(
|