model-metadata/code_python_files
013k
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 # Use a pipeline as a high-level helper23 from transformers import pipeline24 25 pipe = pipeline("image-text-to-text", model="zai-org/Glyph")26 messages = [27 {28 "role": "user",29 "content": [30 {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"},31 {"type": "text", "text": "What animal is on the candy?"}32 ]33 },34 ]35 pipe(text=messages)36 with open('zai-org_Glyph_0.txt', 'w', encoding='utf-8') as f:37 f.write('Everything was good in zai-org_Glyph_0.txt')38except Exception as e:39 import os40 from slack_sdk import WebClient41 client = WebClient(token=os.environ['SLACK_TOKEN'])42 client.chat_postMessage(43 channel='#hub-model-metadata-snippets-sprint',44 text='Problem in <https://huggingface.co/datasets/model-metadata/code_execution_files/blob/main/zai-org_Glyph_0.txt|zai-org_Glyph_0.txt>',45 )46 47 with open('zai-org_Glyph_0.txt', 'a', encoding='utf-8') as f:48 import traceback49 f.write('''```CODE: 50# Use a pipeline as a high-level helper51from transformers import pipeline52 53pipe = pipeline("image-text-to-text", model="zai-org/Glyph")54messages = [55 {56 "role": "user",57 "content": [58 {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"},59 {"type": "text", "text": "What animal is on the candy?"}60 ]61 },62]63pipe(text=messages)64```65 66ERROR: 67''')68 traceback.print_exc(file=f)69 70finally:71 from huggingface_hub import upload_file72 upload_file(73 path_or_fileobj='zai-org_Glyph_0.txt',74 repo_id='model-metadata/code_execution_files',75 path_in_repo='zai-org_Glyph_0.txt',76 repo_type='dataset',77 )78 