Upload black-forest-labs_FLUX.1-Kontext-dev_3.py with huggingface_hub
Browse files12345678910111213141516171819202122232425262728293031323334353637383940# /// script# requires-python = ">=3.12"# dependencies = [# "transformers",# "torch",# ]# ///
try: import os from huggingface_hub import InferenceClient client = InferenceClient( provider="auto", api_key=os.environ["HF_TOKEN"], ) with open("cat.png", "rb") as image_file: input_image = image_file.read() # output is a PIL.Image object image = client.image_to_image( input_image, prompt="Turn the cat into a tiger.", model="black-forest-labs/FLUX.1-Kontext-dev", ) with open('black-forest-labs_FLUX.1-Kontext-dev_3.txt', 'w') as f: f.write('Everything was good in black-forest-labs_FLUX.1-Kontext-dev_3.txt')except Exception as e: with open('black-forest-labs_FLUX.1-Kontext-dev_3.txt', 'w') as f: import traceback traceback.print_exc(file=f)finally: from huggingface_hub import upload_file upload_file( path_or_fileobj='black-forest-labs_FLUX.1-Kontext-dev_3.txt', repo_id='model-metadata/custom_code_execution_files', path_in_repo='black-forest-labs_FLUX.1-Kontext-dev_3.txt', repo_type='dataset', )black-forest-labs_FLUX.1-Kontext-dev_3.pyAdded+40