Spaces:
Running
Running
A newer version of the Gradio SDK is available:
5.38.0
Flux Kontext Image Generator Library
A Python library for interacting with the Kontext Chat image generation API.
Installation
pip install requests
Usage
from flux_kontext_lib import generate_image
# Using file path
result = generate_image("close her eyes", "path/to/image.jpg")
# Using image bytes
with open("path/to/image.jpg", "rb") as f:
image_bytes = f.read()
result = generate_image("add sunglasses", image_bytes)
# Custom headers
custom_headers = {"Authorization": "Bearer YOUR_TOKEN"}
result = generate_image("make it sunny", "path/to/image.jpg", headers=custom_headers)
Parameters
prompt_text
(str): Text prompt for image modificationimage_input
(str or bytes): Image file path or bytes contentheaders
(dict, optional): Custom request headers
Returns
- dict: API response on success
- None: On request failure
Error Handling
Raises:
FileNotFoundError
: If image file doesn't existValueError
: For unsupported input types
Example
See example_usage.py for a complete usage example.