CoolFace
Datasetpublic

model-metadata/code_python_files

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes13kdownloads
peteromallet_Qwen-Image-Edit-InScene_0.py75 linesDownload Raw Back to root
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_image26    27    # switch to "mps" for apple devices28    pipe = DiffusionPipeline.from_pretrained("Qwen/Qwen-Image-Edit", dtype=torch.bfloat16, device_map="cuda")29    pipe.load_lora_weights("peteromallet/Qwen-Image-Edit-InScene")30    31    prompt = "Turn this cat into a dog"32    input_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/cat.png")33    34    image = pipe(image=input_image, prompt=prompt).images[0]35    with open('peteromallet_Qwen-Image-Edit-InScene_0.txt', 'w', encoding='utf-8') as f:36        f.write('Everything was good in peteromallet_Qwen-Image-Edit-InScene_0.txt')37except Exception as e:38    import os39    from slack_sdk import WebClient40    client = WebClient(token=os.environ['SLACK_TOKEN'])41    client.chat_postMessage(42        channel='#hub-model-metadata-snippets-sprint',43        text='Problem in <https://huggingface.co/datasets/model-metadata/code_execution_files/blob/main/peteromallet_Qwen-Image-Edit-InScene_0.txt|peteromallet_Qwen-Image-Edit-InScene_0.txt>',44    )45 46    with open('peteromallet_Qwen-Image-Edit-InScene_0.txt', 'a', encoding='utf-8') as f:47        import traceback48        f.write('''```CODE: 49import torch50from diffusers import DiffusionPipeline51from diffusers.utils import load_image52 53# switch to "mps" for apple devices54pipe = DiffusionPipeline.from_pretrained("Qwen/Qwen-Image-Edit", dtype=torch.bfloat16, device_map="cuda")55pipe.load_lora_weights("peteromallet/Qwen-Image-Edit-InScene")56 57prompt = "Turn this cat into a dog"58input_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/cat.png")59 60image = pipe(image=input_image, prompt=prompt).images[0]61```62 63ERROR: 64''')65        traceback.print_exc(file=f)66    67finally:68    from huggingface_hub import upload_file69    upload_file(70        path_or_fileobj='peteromallet_Qwen-Image-Edit-InScene_0.txt',71        repo_id='model-metadata/code_execution_files',72        path_in_repo='peteromallet_Qwen-Image-Edit-InScene_0.txt',73        repo_type='dataset',74    )75