model-metadata/code_python_files
014k
1# /// script2# requires-python = ">=3.12"3# dependencies = [4# "torch",5# "torchvision",6# "transformers",7# "accelerate",8# "peft",9# "slack-sdk",10# ]11# ///12 13try:14 import torch15 from diffusers import DiffusionPipeline16 from diffusers.utils import load_image, export_to_video17 18 pipe = DiffusionPipeline.from_pretrained("lightx2v/Wan2.2-Distill-Loras", torch_dtype=torch.float16)19 pipe.to("cuda")20 21 prompt = "A man with short gray hair plays a red electric guitar."22 image = load_image(23 "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/guitar-man.png"24 )25 26 output = pipe(image=image, prompt=prompt).frames[0]27 export_to_video(output, "output.mp4")28 with open('lightx2v_Wan2.2-Distill-Loras_2.txt', 'w', encoding='utf-8') as f:29 f.write('Everything was good in lightx2v_Wan2.2-Distill-Loras_2.txt')30except Exception as e:31 import os32 from slack_sdk import WebClient33 client = WebClient(token=os.environ['SLACK_TOKEN'])34 client.chat_postMessage(35 channel='#exp-slack-alerts',36 text='Problem in <https://huggingface.co/datasets/model-metadata/code_execution_files/blob/main/lightx2v_Wan2.2-Distill-Loras_2.txt|lightx2v_Wan2.2-Distill-Loras_2.txt>',37 )38 39 with open('lightx2v_Wan2.2-Distill-Loras_2.txt', 'a', encoding='utf-8') as f:40 import traceback41 f.write('''```CODE: 42import torch43from diffusers import DiffusionPipeline44from diffusers.utils import load_image, export_to_video45 46pipe = DiffusionPipeline.from_pretrained("lightx2v/Wan2.2-Distill-Loras", torch_dtype=torch.float16)47pipe.to("cuda")48 49prompt = "A man with short gray hair plays a red electric guitar."50image = load_image(51 "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/guitar-man.png"52)53 54output = pipe(image=image, prompt=prompt).frames[0]55export_to_video(output, "output.mp4")56```57 58ERROR: 59''')60 traceback.print_exc(file=f)61 62finally:63 from huggingface_hub import upload_file64 upload_file(65 path_or_fileobj='lightx2v_Wan2.2-Distill-Loras_2.txt',66 repo_id='model-metadata/code_execution_files',67 path_in_repo='lightx2v_Wan2.2-Distill-Loras_2.txt',68 repo_type='dataset',69 )70 