Spaces:
Runtime error
Runtime error
[ | |
"""The following is a conversation between a highly knowledgeable and intelligent 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 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.\n\nThe conversation begins:\nUser:""" | |
"""https://i1.pickpik.com/photos/515/906/355/kittens-cats-pet-cute-preview.jpg""", | |
"""Describe this image.</s>\n""", | |
"""Assistant: Five kittens are standing together in the center of the photograph. From the left to right, there is one orange kitte, 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.</s>\n""", | |
"""User:How about this image?""", | |
"https://cdn.pixabay.com/photo/2017/09/25/13/12/puppy-2785074_1280.jpg""", | |
"""Can you describe it too?</s>\n""" | |
"""Assistant: 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.</s>\n""", | |
"""User: What kind of breed is it?</s>\n""", | |
"""Assistant: 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.</s>\n""", | |
"""User: What can you tell me about this breed of dogs?</s>\n""" | |
"""Assistant: 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.</s>\n""", | |
"""User: ghjkhjabnufs</s>\n""", | |
"""Assistant: That doesn’t seem to be a word. Could you ask me another way?</s>\n""", | |
"""User: Do you like Cavalier King Charles Spaniel?</s>\n""", | |
"""Assistant: 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.</s>\n""", | |
"""User: How many dogs do you see in this image?""", | |
"""https://i.dailymail.co.uk/i/pix/2011/07/01/article-2010308-0CD22A8300000578-496_634x414.jpg""", | |
"""</s>\n""", | |
"""Assistant: There is no dogs in this image. The picture shows a tennis player jumping to volley the ball.</s>\n""", | |
"""User: What color are the cat's eyes?</s>\n""", | |
"""Assistant:""" | |
] | |
SYSTEM_PROMPT = """The following is a conversation between a highly knowledgeable and intelligent 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 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. | |
The conversation begins: | |
User:<fake_token_around_image><image:https://i1.pickpik.com/photos/515/906/355/kittens-cats-pet-cute-preview.jpg><fake_token_around_image>Describe this image.</s> | |
Assistant: Five kittens are standing together in the center of the photograph. From the left to right, there is one orange kitte, 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.</s>""" | |
prompts = [ | |
"""The following is a conversation between a highly knowledgeable and intelligent 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 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.\n\nThe conversation begins:\nUser:""", | |
"""https://i1.pickpik.com/photos/515/906/355/kittens-cats-pet-cute-preview.jpg""", | |
"""Describe this image.</s>\nAssistant: Five kittens are standing together in the center of the photograph. From the left to right, there is one orange kitte, 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.</s>""" | |
] | |
SYSTEM_PROMPT = """HELLO | |
AUREVOIR | |
User:<fake_token_around_image><image:AAA><fake_token_around_image><image:BBB><fake_token_around_image>BOJOUR</s> | |
Assistant: SPECIFIC</s>""" | |
def split_prompt_into_list(prompt_str): | |
prompt_splitted = prompt_str.split("<fake_token_around_image>") | |
prompt_list = [] | |
for ps in prompt_splitted: | |
if ps.startswith("<image:"): | |
prompt_list.append(ps[7:-1]) | |
else: | |
prompt_list.append(ps) | |
return prompt_list | |
prompts = split_prompt_into_list(formated_prompt) | |
i = processor(prompts, eval_mode=True) | |
from transformers import AutoTokenizer, AutoProcessor | |
checkpoint = "HuggingFaceM4/idefics-9b-instruct" | |
tokenizer = AutoTokenizer.from_pretrained(checkpoint) | |
processor = AutoProcessor.from_pretrained(checkpoint) | |
prompts = [ | |
[ | |
"User:", | |
# "https://hips.hearstapps.com/hmg-prod/images/cute-photos-of-cats-in-grass-1593184777.jpg", | |
# "https://hips.hearstapps.com/hmg-prod/images/cute-photos-of-cats-in-grass-1593184777.jpg", | |
"Describe this image.\nAssistant: An image of two kittens in grass.\n", | |
"User:", | |
# "https://hips.hearstapps.com/hmg-prod/images/dog-puns-1581708208.jpg", | |
"Describe this image.\nAssistant:", | |
], | |
] | |
inputs = processor(prompts, eval_mode=True) | |
tokenizer.decode(inputs["input_ids"][0]) |