ariG23498 HF Staff commited on
Commit
ddca94e
·
verified ·
1 Parent(s): d21f891

Upload black-forest-labs_FLUX.1-dev_4.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. black-forest-labs_FLUX.1-dev_4.py +67 -0
black-forest-labs_FLUX.1-dev_4.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ # output is a PIL.Image object
23
+ image = client.text_to_image(
24
+ "Astronaut riding a horse",
25
+ model="black-forest-labs/FLUX.1-dev",
26
+ )
27
+ with open('black-forest-labs_FLUX.1-dev_4.txt', 'w', encoding='utf-8') as f:
28
+ f.write('Everything was good in black-forest-labs_FLUX.1-dev_4.txt')
29
+ except Exception as e:
30
+ import os
31
+ from slack_sdk import WebClient
32
+ client = WebClient(token=os.environ['SLACK_TOKEN'])
33
+ client.chat_postMessage(
34
+ channel='#exp-slack-alerts',
35
+ text='Problem in <https://huggingface.co/datasets/model-metadata/code_execution_files/blob/main/black-forest-labs_FLUX.1-dev_4.txt|black-forest-labs_FLUX.1-dev_4.txt>',
36
+ )
37
+
38
+ with open('black-forest-labs_FLUX.1-dev_4.txt', 'a', encoding='utf-8') as f:
39
+ import traceback
40
+ f.write('''```CODE:
41
+ import os
42
+ from huggingface_hub import InferenceClient
43
+
44
+ client = InferenceClient(
45
+ provider="auto",
46
+ api_key=os.environ["HF_TOKEN"],
47
+ )
48
+
49
+ # output is a PIL.Image object
50
+ image = client.text_to_image(
51
+ "Astronaut riding a horse",
52
+ model="black-forest-labs/FLUX.1-dev",
53
+ )
54
+ ```
55
+
56
+ ERROR:
57
+ ''')
58
+ traceback.print_exc(file=f)
59
+
60
+ finally:
61
+ from huggingface_hub import upload_file
62
+ upload_file(
63
+ path_or_fileobj='black-forest-labs_FLUX.1-dev_4.txt',
64
+ repo_id='model-metadata/code_execution_files',
65
+ path_in_repo='black-forest-labs_FLUX.1-dev_4.txt',
66
+ repo_type='dataset',
67
+ )