ariG23498 HF Staff commited on
Commit
bca06cc
·
verified ·
1 Parent(s): 367dc1f

Upload black-forest-labs_FLUX.1-Kontext-dev_1.py with huggingface_hub

Browse files
black-forest-labs_FLUX.1-Kontext-dev_1.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # /// script
2
+ # requires-python = ">=3.12"
3
+ # dependencies = [
4
+ # "transformers",
5
+ # "torch",
6
+ # ]
7
+ # ///
8
+
9
+ try:
10
+ from diffusers import DiffusionPipeline
11
+ from diffusers.utils import load_image
12
+
13
+ pipe = DiffusionPipeline.from_pretrained("black-forest-labs/FLUX.1-Kontext-dev")
14
+
15
+ prompt = "Turn this cat into a dog"
16
+ input_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/cat.png")
17
+
18
+ image = pipe(image=input_image, prompt=prompt).images[0]
19
+ with open('black-forest-labs_FLUX.1-Kontext-dev_1.txt', 'w') as f:
20
+ f.write('Everything was good in black-forest-labs_FLUX.1-Kontext-dev_1.txt')
21
+ except Exception as e:
22
+ with open('black-forest-labs_FLUX.1-Kontext-dev_1.txt', 'w') as f:
23
+ import traceback
24
+ traceback.print_exc(file=f)
25
+ finally:
26
+ from huggingface_hub import upload_file
27
+ upload_file(
28
+ path_or_fileobj='black-forest-labs_FLUX.1-Kontext-dev_1.txt',
29
+ repo_id='model-metadata/custom_code_execution_files',
30
+ path_in_repo='black-forest-labs_FLUX.1-Kontext-dev_1.txt',
31
+ repo_type='dataset',
32
+ )