ariG23498 HF Staff commited on
Commit
eaa2eaf
·
verified ·
1 Parent(s): f07c55d

Upload Qwen_Qwen-Image-Edit_3.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. Qwen_Qwen-Image-Edit_3.py +75 -0
Qwen_Qwen-Image-Edit_3.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # /// script
2
+ # requires-python = ">=3.12"
3
+ # dependencies = [
4
+ # "torch",
5
+ # "torchvision",
6
+ # "transformers",
7
+ # "accelerate",
8
+ # "peft",
9
+ # "slack-sdk",
10
+ # ]
11
+ # ///
12
+
13
+ try:
14
+ import os
15
+ from huggingface_hub import InferenceClient
16
+
17
+ client = InferenceClient(
18
+ provider="auto",
19
+ api_key=os.environ["HF_TOKEN"],
20
+ )
21
+
22
+ with open("cat.png", "rb") as image_file:
23
+ input_image = image_file.read()
24
+
25
+ # output is a PIL.Image object
26
+ image = client.image_to_image(
27
+ input_image,
28
+ prompt="Turn the cat into a tiger.",
29
+ model="Qwen/Qwen-Image-Edit",
30
+ )
31
+ with open('Qwen_Qwen-Image-Edit_3.txt', 'w', encoding='utf-8') as f:
32
+ f.write('Everything was good in Qwen_Qwen-Image-Edit_3.txt')
33
+ except Exception as e:
34
+ import os
35
+ from slack_sdk import WebClient
36
+ client = WebClient(token=os.environ['SLACK_TOKEN'])
37
+ client.chat_postMessage(
38
+ channel='#exp-slack-alerts',
39
+ text='Problem in <https://huggingface.co/datasets/model-metadata/code_execution_files/blob/main/Qwen_Qwen-Image-Edit_3.txt|Qwen_Qwen-Image-Edit_3.txt>',
40
+ )
41
+
42
+ with open('Qwen_Qwen-Image-Edit_3.txt', 'a', encoding='utf-8') as f:
43
+ import traceback
44
+ f.write('''```CODE:
45
+ import os
46
+ from huggingface_hub import InferenceClient
47
+
48
+ client = InferenceClient(
49
+ provider="auto",
50
+ api_key=os.environ["HF_TOKEN"],
51
+ )
52
+
53
+ with open("cat.png", "rb") as image_file:
54
+ input_image = image_file.read()
55
+
56
+ # output is a PIL.Image object
57
+ image = client.image_to_image(
58
+ input_image,
59
+ prompt="Turn the cat into a tiger.",
60
+ model="Qwen/Qwen-Image-Edit",
61
+ )
62
+ ```
63
+
64
+ ERROR:
65
+ ''')
66
+ traceback.print_exc(file=f)
67
+
68
+ finally:
69
+ from huggingface_hub import upload_file
70
+ upload_file(
71
+ path_or_fileobj='Qwen_Qwen-Image-Edit_3.txt',
72
+ repo_id='model-metadata/code_execution_files',
73
+ path_in_repo='Qwen_Qwen-Image-Edit_3.txt',
74
+ repo_type='dataset',
75
+ )