Python SDK combining FAI API modules
Project description
InstantLight-sdk
Installation
Install the SDK using pip:
pip install FAIsdk
Usage of InstantLight
Here’s an example of how to use the InstantLight SDK to make an API call and handle the response:
from InstantLight import InstantLightSDK
from PIL import Image
import base64
from io import BytesIO
# Initialize the SDK
sdk = InstantLightSDK(
base_url='https://api.fotographer.ai/instantLight',
api_key='your_api_key',
email='your_email@example.com'
)
# Convert images to base64
def image_to_base64(image_path):
with Image.open(image_path) as img:
buffered = BytesIO()
img.save(buffered, format="PNG")
return base64.b64encode(buffered.getvalue()).decode('utf-8')
# Prepare the image data
foreground_image64 = image_to_base64('path_to_foreground_image.png')
background_image64 = image_to_base64('path_to_background_image.png')
# Define the image data
image_data = {
"foreground_image64": foreground_image64,
"background_image64": background_image64,
"prompt": "example prompt",
"mode": 2,
"prompt_strength": 0.8,
"inf_factor": 1.00,
"mask_strength": 0.5,
"image_width": 1400,
"image_height": 1400,
"additional_prompt": "",
"negative_prompt": "",
"lights": []
}
# Make the API call
response = sdk.image_generation.get_image_gen(image_data)
# Print the response keys for debugging
print("Response Keys:", response.keys())
# Print the keys at all levels of the response for debugging
for key, value in response.items():
if isinstance(value, dict):
print(f"Response[{key}] Keys: {value.keys()}")
# Save the image and mask image if they exist in the response
if 'image' in response:
image_data = response['image']
image_bytes = base64.b64decode(image_data)
image = Image.open(BytesIO(image_bytes))
image.save("output_image.png")
print("Image retrieved and saved as output_image.png.")
if 'mask_image' in response:
mask_data = response['mask_image']
mask_bytes = base64.b64decode(mask_data)
mask_image = Image.open(BytesIO(mask_bytes))
mask_image.save("output_mask_image.png")
print("Mask retrieved and saved as output_mask_image.png.")
else:
print("Response does not contain 'image'")
Make sure to update your_api_key
and your_email@example.com
with the actual values in the example usage section.
Usage of ImageGen
from FAImageGen import ImageGen as FAImageGenSDK
from PIL import Image
import base64
from io import BytesIO
# Initialize the SDK API
api = FAImageGenSDK(
base_url='https://api.fotographer.ai/Image-gen',
api_key='your_api_key',
email='your_email@example.com'
)
# Convert images to base64
def image_to_base64(image_path):
with Image.open(image_path) as img:
buffered = BytesIO()
img.save(buffered, format="PNG")
return base64.b64encode(buffered.getvalue()).decode('utf-8')
# Prepare the image data
image_path = 'C:/Users/Saliou Kane/Downloads/perfume_black.png'
prompt = 'a black perfume bottle on top of mounntain in front of the sea'
# Make the API call
response = api.image_generation.get_image_gen(image_path, prompt)
try:
# Make the API call
response = api.image_generation.get_image_gen(image_path, prompt)
# Print the response keys for debugging
#logging.debug("Response Keys: %s", response.keys())
# Print the keys at all levels of the response for debugging
for key, value in response.items():
if isinstance(value, dict):
logging.debug(f"Response[{key}] Keys: %s", value.keys())
# Save the image and mask image if they exist in the response
if 'image' in response:
logging.debug("Success")
else:
logging.debug("Response does not contain 'image'")
except requests.exceptions.RequestException as e:
logging.error(f"HTTP error occurred: {e}")
if hasattr(e, 'response') and e.response is not None:
logging.error(f"Response content: {e.response.content}")
except Exception as e:
logging.error("An unexpected error occurred: %s", e)
Usage of Harmonizer
from FAImageGen import ImageGen
from PIL import Image
import base64
from io import BytesIO
# Initialize the Harmonizer
image_gen = ImageGen(
base_url='https://api.fotographer.ai/Image-gen',
api_key='your_api_key',
email='your_email@example.com'
)
# Convert images to base64
def image_to_base64(image_path):
with Image.open(image_path) as img:
buffered = BytesIO()
img.save(buffered, format="PNG")
return base64.b64encode(buffered.getvalue()).decode('utf-8')
# Prepare the image data
image_path = 'path_to_your_image.png'
prompt = 'a black perfume bottle on top of a mountain in front of the sea'
# Harmonize the image
harmonized_image = image_gen.harmonizer.harmonize_image(image_path, prompt)
# Print the response keys for debugging
print("Response Keys:", response.keys())
# Print the keys at all levels of the response for debugging
for key, value in response.items():
if isinstance(value, dict):
print(f"Response[{key}] Keys: {value.keys()}")
# Save the harmonized image if it exists in the response
if 'image' in response:
image_data = response['image']
image_bytes = base64.b64decode(image_data)
image = Image.open(BytesIO(image_bytes))
image.save("harmonized_output_image.png")
print("Harmonized image retrieved and saved as harmonized_output_image.png.")
else:
print("Response does not contain 'image'")
Usage of Fuzer
from FAImageGen import ImageGen
from PIL import Image
import base64
from io import BytesIO
# Initialize the Harmonizer
image_gen = ImageGen(
base_url='https://api.fotographer.ai/Image-gen',
api_key='your_api_key',
email='your_email@example.com'
)
# Convert images to base64
def image_to_base64(image_path):
with Image.open(image_path) as img:
buffered = BytesIO()
img.save(buffered, format="PNG")
return base64.b64encode(buffered.getvalue()).decode('utf-8')
# Prepare the image data
image_path = 'path_to_your_image.png'
prompt = 'a black perfume bottle on top of a mountain in front of the sea'
refprompt = 'a reference prompt for the image'
mode = 'first-stage' # or 'full' or 'refiner'
intensity = 5 # 1 to 11
width = 1024
height = 768
# Fuse the image
fuzed_image = image_gen.fuzer.fuzer(image_path, prompt, refprompt, mode, intensity, width, height)
# Save the fuzed image if it exists in the response
if fuzed_image:
print("Success")
else:
print("Fuzing failed or image not found in the response.")
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
FAIsdk-1.3.3.tar.gz
(5.5 kB
view details)
Built Distribution
File details
Details for the file FAIsdk-1.3.3.tar.gz
.
File metadata
- Download URL: FAIsdk-1.3.3.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a93ec657d5d631ff99f0e5a27903a28de591a100be5ca81cc94eba255a1f22a |
|
MD5 | 92d0a99c2474389b332424393eabbc32 |
|
BLAKE2b-256 | e2f04c58a3f4a124b5e8cb3daed3ed026c67652a34fb9d11eec17caff3405417 |
File details
Details for the file FAIsdk-1.3.3-py3-none-any.whl
.
File metadata
- Download URL: FAIsdk-1.3.3-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32b0c9ab9fbeb07358b10d790bc2b68ef1d7b612a02086650b2ca9833d00524c |
|
MD5 | 6876378f8eb23dca120f85918b29e1d8 |
|
BLAKE2b-256 | 1f31723afde9d411f4b9609586c081897c6fdd8f27e7b9d6ece31dc3eb0fb5bb |