model-metadata/code_python_files
014k
1# /// script2# requires-python = ">=3.12"3# dependencies = [4# "numpy",5# "einops",6# "pandas",7# "matplotlib",8# "protobuf",9# "torch",10# "sentencepiece",11# "torchvision",12# "transformers",13# "timm",14# "diffusers",15# "sentence-transformers",16# "accelerate",17# "peft",18# "slack-sdk",19# ]20# ///21 22try:23 # Use a pipeline as a high-level helper24 from transformers import pipeline25 26 pipe = pipeline("image-text-to-text", model="google/translategemma-12b-it")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 pipe(text=messages)37 with open('google_translategemma-12b-it_1.txt', 'w', encoding='utf-8') as f:38 f.write('Everything was good in google_translategemma-12b-it_1.txt')39except Exception as e:40 import os41 from slack_sdk import WebClient42 client = WebClient(token=os.environ['SLACK_TOKEN'])43 client.chat_postMessage(44 channel='#hub-model-metadata-snippets-sprint',45 text='Problem in <https://huggingface.co/datasets/model-metadata/code_execution_files/blob/main/google_translategemma-12b-it_1.txt|google_translategemma-12b-it_1.txt>',46 )47 48 with open('google_translategemma-12b-it_1.txt', 'a', encoding='utf-8') as f:49 import traceback50 f.write('''```CODE: 51# Use a pipeline as a high-level helper52from transformers import pipeline53 54pipe = pipeline("image-text-to-text", model="google/translategemma-12b-it")55messages = [56 {57 "role": "user",58 "content": [59 {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"},60 {"type": "text", "text": "What animal is on the candy?"}61 ]62 },63]64pipe(text=messages)65```66 67ERROR: 68''')69 traceback.print_exc(file=f)70 71finally:72 from huggingface_hub import upload_file73 upload_file(74 path_or_fileobj='google_translategemma-12b-it_1.txt',75 repo_id='model-metadata/code_execution_files',76 path_in_repo='google_translategemma-12b-it_1.txt',77 repo_type='dataset',78 )79 