ariG23498 HF Staff commited on
Commit
aa76955
·
verified ·
1 Parent(s): e72d7b4

Upload dx8152_Qwen-Edit-2509-Light-Migration_0.py with huggingface_hub

Browse files
dx8152_Qwen-Edit-2509-Light-Migration_0.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # /// script
2
+ # 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
+
22
+ try:
23
+ import torch
24
+ from diffusers import DiffusionPipeline
25
+ from diffusers.utils import load_image
26
+
27
+ # switch to "mps" for apple devices
28
+ pipe = DiffusionPipeline.from_pretrained("Qwen/Qwen-Image-Edit-2509", dtype=torch.bfloat16, device_map="cuda")
29
+ pipe.load_lora_weights("dx8152/Qwen-Edit-2509-Light-Migration")
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('dx8152_Qwen-Edit-2509-Light-Migration_0.txt', 'w', encoding='utf-8') as f:
36
+ f.write('Everything was good in dx8152_Qwen-Edit-2509-Light-Migration_0.txt')
37
+ except Exception as e:
38
+ import os
39
+ from slack_sdk import WebClient
40
+ 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/dx8152_Qwen-Edit-2509-Light-Migration_0.txt|dx8152_Qwen-Edit-2509-Light-Migration_0.txt>',
44
+ )
45
+
46
+ with open('dx8152_Qwen-Edit-2509-Light-Migration_0.txt', 'a', encoding='utf-8') as f:
47
+ import traceback
48
+ f.write('''```CODE:
49
+ import torch
50
+ from diffusers import DiffusionPipeline
51
+ from diffusers.utils import load_image
52
+
53
+ # switch to "mps" for apple devices
54
+ pipe = DiffusionPipeline.from_pretrained("Qwen/Qwen-Image-Edit-2509", dtype=torch.bfloat16, device_map="cuda")
55
+ pipe.load_lora_weights("dx8152/Qwen-Edit-2509-Light-Migration")
56
+
57
+ prompt = "Turn this cat into a dog"
58
+ input_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/cat.png")
59
+
60
+ image = pipe(image=input_image, prompt=prompt).images[0]
61
+ ```
62
+
63
+ ERROR:
64
+ ''')
65
+ traceback.print_exc(file=f)
66
+
67
+ finally:
68
+ from huggingface_hub import upload_file
69
+ upload_file(
70
+ path_or_fileobj='dx8152_Qwen-Edit-2509-Light-Migration_0.txt',
71
+ repo_id='model-metadata/code_execution_files',
72
+ path_in_repo='dx8152_Qwen-Edit-2509-Light-Migration_0.txt',
73
+ repo_type='dataset',
74
+ )