CoolFace
Datasetpublic

model-metadata/code_python_files

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes13kdownloads
LiquidAI_LFM2-VL-3B_2.py90 linesDownload Raw Back to root
1# /// script2# requires-python = ">=3.12"3# dependencies = [4#     "torch",5#     "torchvision",6#     "transformers",7#     "accelerate",8#     "peft",9#     "slack-sdk",10# ]11# ///12 13try:14    # Load model directly15    from transformers import AutoProcessor, AutoModelForImageTextToText16    17    processor = AutoProcessor.from_pretrained("LiquidAI/LFM2-VL-3B")18    model = AutoModelForImageTextToText.from_pretrained("LiquidAI/LFM2-VL-3B")19    messages = [20        {21            "role": "user",22            "content": [23                {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"},24                {"type": "text", "text": "What animal is on the candy?"}25            ]26        },27    ]28    inputs = processor.apply_chat_template(29    	messages,30    	add_generation_prompt=True,31    	tokenize=True,32    	return_dict=True,33    	return_tensors="pt",34    ).to(model.device)35    36    outputs = model.generate(**inputs, max_new_tokens=40)37    print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:]))38    with open('LiquidAI_LFM2-VL-3B_2.txt', 'w', encoding='utf-8') as f:39        f.write('Everything was good in LiquidAI_LFM2-VL-3B_2.txt')40except Exception as e:41    import os42    from slack_sdk import WebClient43    client = WebClient(token=os.environ['SLACK_TOKEN'])44    client.chat_postMessage(45        channel='#exp-slack-alerts',46        text='Problem in <https://huggingface.co/datasets/model-metadata/code_execution_files/blob/main/LiquidAI_LFM2-VL-3B_2.txt|LiquidAI_LFM2-VL-3B_2.txt>',47    )48 49    with open('LiquidAI_LFM2-VL-3B_2.txt', 'a', encoding='utf-8') as f:50        import traceback51        f.write('''```CODE: 52# Load model directly53from transformers import AutoProcessor, AutoModelForImageTextToText54 55processor = AutoProcessor.from_pretrained("LiquidAI/LFM2-VL-3B")56model = AutoModelForImageTextToText.from_pretrained("LiquidAI/LFM2-VL-3B")57messages = [58    {59        "role": "user",60        "content": [61            {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"},62            {"type": "text", "text": "What animal is on the candy?"}63        ]64    },65]66inputs = processor.apply_chat_template(67	messages,68	add_generation_prompt=True,69	tokenize=True,70	return_dict=True,71	return_tensors="pt",72).to(model.device)73 74outputs = model.generate(**inputs, max_new_tokens=40)75print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:]))76```77 78ERROR: 79''')80        traceback.print_exc(file=f)81    82finally:83    from huggingface_hub import upload_file84    upload_file(85        path_or_fileobj='LiquidAI_LFM2-VL-3B_2.txt',86        repo_id='model-metadata/code_execution_files',87        path_in_repo='LiquidAI_LFM2-VL-3B_2.txt',88        repo_type='dataset',89    )90