Spaces:
Running
Running
| # Flux Kontext Image Generator Library | |
| A Python library for interacting with the Kontext Chat image generation API. | |
| ## Installation | |
| ```bash | |
| pip install requests | |
| ``` | |
| ## Usage | |
| ```python | |
| 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 modification | |
| - `image_input` (str or bytes): Image file path or bytes content | |
| - `headers` (dict, optional): Custom request headers | |
| ## Returns | |
| - dict: API response on success | |
| - None: On request failure | |
| ## Error Handling | |
| Raises: | |
| - `FileNotFoundError`: If image file doesn't exist | |
| - `ValueError`: For unsupported input types | |
| ## Example | |
| See [example_usage.py](example_usage.py) for a complete usage example. | |