CoolFace
Datasetpublic

model-metadata/code_python_files

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes13kdownloads
zai-org_Glyph_1.py98 linesDownload Raw Back to root
1# /// script2# requires-python = ">=3.12"3# dependencies = [4#     "numpy",5#     "einops",6#     "pandas",7#     "protobuf",8#     "torch",9#     "sentencepiece",10#     "torchvision",11#     "transformers",12#     "timm",13#     "diffusers",14#     "sentence-transformers",15#     "accelerate",16#     "peft",17#     "slack-sdk",18# ]19# ///20 21try:22    # Load model directly23    from transformers import AutoProcessor, AutoModelForImageTextToText24    25    processor = AutoProcessor.from_pretrained("zai-org/Glyph")26    model = AutoModelForImageTextToText.from_pretrained("zai-org/Glyph")27    messages = [28        {29            "role": "user",30            "content": [31                {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"},32                {"type": "text", "text": "What animal is on the candy?"}33            ]34        },35    ]36    inputs = processor.apply_chat_template(37    	messages,38    	add_generation_prompt=True,39    	tokenize=True,40    	return_dict=True,41    	return_tensors="pt",42    ).to(model.device)43    44    outputs = model.generate(**inputs, max_new_tokens=40)45    print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:]))46    with open('zai-org_Glyph_1.txt', 'w', encoding='utf-8') as f:47        f.write('Everything was good in zai-org_Glyph_1.txt')48except Exception as e:49    import os50    from slack_sdk import WebClient51    client = WebClient(token=os.environ['SLACK_TOKEN'])52    client.chat_postMessage(53        channel='#hub-model-metadata-snippets-sprint',54        text='Problem in <https://huggingface.co/datasets/model-metadata/code_execution_files/blob/main/zai-org_Glyph_1.txt|zai-org_Glyph_1.txt>',55    )56 57    with open('zai-org_Glyph_1.txt', 'a', encoding='utf-8') as f:58        import traceback59        f.write('''```CODE: 60# Load model directly61from transformers import AutoProcessor, AutoModelForImageTextToText62 63processor = AutoProcessor.from_pretrained("zai-org/Glyph")64model = AutoModelForImageTextToText.from_pretrained("zai-org/Glyph")65messages = [66    {67        "role": "user",68        "content": [69            {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"},70            {"type": "text", "text": "What animal is on the candy?"}71        ]72    },73]74inputs = processor.apply_chat_template(75	messages,76	add_generation_prompt=True,77	tokenize=True,78	return_dict=True,79	return_tensors="pt",80).to(model.device)81 82outputs = model.generate(**inputs, max_new_tokens=40)83print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:]))84```85 86ERROR: 87''')88        traceback.print_exc(file=f)89    90finally:91    from huggingface_hub import upload_file92    upload_file(93        path_or_fileobj='zai-org_Glyph_1.txt',94        repo_id='model-metadata/code_execution_files',95        path_in_repo='zai-org_Glyph_1.txt',96        repo_type='dataset',97    )98