model-metadata/code_python_files
013k
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 import torch24 from diffusers import DiffusionPipeline25 from diffusers.utils import load_image, export_to_video26 27 # switch to "mps" for apple devices28 pipe = DiffusionPipeline.from_pretrained("Qwen/Qwen-Image-Edit-2509", dtype=torch.bfloat16, device_map="cuda")29 pipe.load_lora_weights("AmirKerr/ThisPerson")30 31 prompt = "A man with short gray hair plays a red electric guitar."32 input_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/guitar-man.png")33 34 image = pipe(image=input_image, prompt=prompt).frames[0]35 export_to_video(output, "output.mp4")36 with open('AmirKerr_ThisPerson_0.txt', 'w', encoding='utf-8') as f:37 f.write('Everything was good in AmirKerr_ThisPerson_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/AmirKerr_ThisPerson_0.txt|AmirKerr_ThisPerson_0.txt>',45 )46 47 with open('AmirKerr_ThisPerson_0.txt', 'a', encoding='utf-8') as f:48 import traceback49 f.write('''```CODE: 50import torch51from diffusers import DiffusionPipeline52from diffusers.utils import load_image, export_to_video53 54# switch to "mps" for apple devices55pipe = DiffusionPipeline.from_pretrained("Qwen/Qwen-Image-Edit-2509", dtype=torch.bfloat16, device_map="cuda")56pipe.load_lora_weights("AmirKerr/ThisPerson")57 58prompt = "A man with short gray hair plays a red electric guitar."59input_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/guitar-man.png")60 61image = pipe(image=input_image, prompt=prompt).frames[0]62export_to_video(output, "output.mp4")63```64 65ERROR: 66''')67 traceback.print_exc(file=f)68 69finally:70 from huggingface_hub import upload_file71 upload_file(72 path_or_fileobj='AmirKerr_ThisPerson_0.txt',73 repo_id='model-metadata/code_execution_files',74 path_in_repo='AmirKerr_ThisPerson_0.txt',75 repo_type='dataset',76 )77 