packages/tasks-gen/snippets-fixtures/image-to-image/python/huggingface_hub/0.hf-inference.py (13 lines of code) (raw):

import os from huggingface_hub import InferenceClient client = InferenceClient( provider="hf-inference", 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", )