model-metadata/code_python_files
013k
1# /// script2# requires-python = ">=3.12"3# dependencies = [4# "torch",5# "torchvision",6# "transformers",7# "diffusers",8# "sentence-transformers",9# "accelerate",10# "peft",11# "slack-sdk",12# ]13# ///14 15try:16 # Use a pipeline as a high-level helper17 from transformers import pipeline18 19 pipe = pipeline("image-text-to-text", model="AvitoTech/avision")20 messages = [21 {22 "role": "user",23 "content": [24 {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"},25 {"type": "text", "text": "What animal is on the candy?"}26 ]27 },28 ]29 pipe(text=messages)30 with open('AvitoTech_avision_0.txt', 'w', encoding='utf-8') as f:31 f.write('Everything was good in AvitoTech_avision_0.txt')32except Exception as e:33 import os34 from slack_sdk import WebClient35 client = WebClient(token=os.environ['SLACK_TOKEN'])36 client.chat_postMessage(37 channel='#hub-model-metadata-snippets-sprint',38 text='Problem in <https://huggingface.co/datasets/model-metadata/code_execution_files/blob/main/AvitoTech_avision_0.txt|AvitoTech_avision_0.txt>',39 )40 41 with open('AvitoTech_avision_0.txt', 'a', encoding='utf-8') as f:42 import traceback43 f.write('''```CODE: 44# Use a pipeline as a high-level helper45from transformers import pipeline46 47pipe = pipeline("image-text-to-text", model="AvitoTech/avision")48messages = [49 {50 "role": "user",51 "content": [52 {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"},53 {"type": "text", "text": "What animal is on the candy?"}54 ]55 },56]57pipe(text=messages)58```59 60ERROR: 61''')62 traceback.print_exc(file=f)63 64finally:65 from huggingface_hub import upload_file66 upload_file(67 path_or_fileobj='AvitoTech_avision_0.txt',68 repo_id='model-metadata/code_execution_files',69 path_in_repo='AvitoTech_avision_0.txt',70 repo_type='dataset',71 )72 