This is a collection of Python scripts. Together, they can take a prompt input and generates images from PixAI directly. This procedure does NOT cost you credits and you can use an alt too.
Note: The Realtime generation feature is a compromise to not pay tokens but your images are of lesser quality.
git clone https://github.com/Recentaly/PixAI-Wrapper.git
cd PixAI-Wrapper
pip install -r requirements.txt
from res.scripts.generate_images import get_image_batch
from res.scripts.get_jwt import get_jwt
(Optional but recommended):
from res.SaveConfig import SaveConfig
When a SaveConfig
object is passed to the API, the API automatically saves the images. There's an option to Save + Return too. To only return the images from the API, leave SaveConfig
as None
when calling get_image_batch
.
Note: Automatically uses the .png file extension
# create a SaveConfig object
save_config = SaveConfig(
save_dir="output/images",
save_name="image",
force_mkdir=True,
additional_return_mode=False,
separator="-"
)
save_dir
(str) is a path to whatever directory you want the images to be saved at.save_name
(str) is whatever you want the file(s) to be called.force_mkdir
(bool) if the save_dir
doesn't exist, forcibly create that directory if force_mkdir
is True.additional_return_mode
(bool) If true, also returns a List
of images while also saving them at the specified directory.separator
(str) The separator between the save_name
and the Image's index.For example, if I have this code and generated, let's say, 4 images..
# create a SaveConfig object
save_config = SaveConfig(
save_dir="output/images",
save_name="generated-image",
force_mkdir=True,
additional_return_mode=False,
separator="_"
)
The images would be saved like this:
generated-image_0.png
generated-image_1.png
generated-image_2.png
generated-image_3.png
Here's example code to fetch your JWT.
jwt: str = get_jwt(
email="<your pixai email here>",
password="<your pixai password here>"
)
This will return a jwt of type string. Now you may actually use the function to gather the images
To gather images, simply call the get_image_batch
function after you've imported it.
Parameters:
Returns:
SaveConfig
is provided, and _saveConfig.additional_return_mode
is true, it saves the images and returns a List[Image]
object. Image is inherited from PIL._saveConfig.additional_return_mode
is False, the API returns None
SaveConfig
is provided, it return List[Image]
object. Image is inherited from PIL.Below is an example of how to generate images of a dog. The negative prompt is one I found and is useful to generate high quality results.
"""
The images automatically saved under 'output/images' as 'image-0.png'. The API didn't return anything because additional_return_mode is False.
"""
save_config = SaveConfig(
save_dir="output/images",
save_name="image",
force_mkdir=True,
additional_return_mode=False,
separator="-"
)
image_outputs = get_image_batch(
prompt="1dog. White. Fluffly. Looking at the camera.",
negative_prompt="nsfw, lowres, (bad), text, error, fewer, extra, missing, worst quality, jpeg artifacts, low quality, watermark, unfinished, displeasing, oldest, early, chromatic aberration, signature, extra digits, artistic error, username, scan, abstract",
size=(512, 512),
_n=1,
__jwt=__jwt,
_saveConfig=save_config
)
The Images are basic Image
objects of the Image module.
Output:
from res.scripts.get_jwt import get_jwt
from res.scripts.generate_images import get_image_batch
from res.SaveConfig import SaveConfig
# create a SaveConfig object
save_config = SaveConfig(
save_dir="output/images",
save_name="image",
force_mkdir=True,
additional_return_mode=True,
separator="-"
)
if __name__ == '__main__':
__jwt: str = get_jwt(
email="xxxxxxxx", # input your actual email here
password="xxxxxx" # input your actual password here
)
image_outputs = get_image_batch(
prompt="1cat. Yellow. Aggressive. Angry. Hissing at the camera. Best quality. Masterpiece. Best anatomy. Open mouth.",
negative_prompt="nsfw, lowres, (bad), text, error, fewer, extra, missing, worst quality, jpeg artifacts, low quality, watermark, unfinished, displeasing, oldest, early, chromatic aberration, signature, extra digits, artistic error, username, scan, abstract",
size=(512, 512),
_n=1,
__jwt=__jwt,
_saveConfig=save_config
)
# we can run the for loop because the API class is set to additionally return the images again
for image in image_outputs:
image.show()
Output:
To auto-claim your daily credits, first import the code to claim credits
from res.scripts.claim_credits import claim_daily_credits
Then, call the claim_daily_credits
function
claim_daily_credits(
jwt # you need your jwt from above
)
You will only get an error if something went wrong. It will tell you in the console if it was able to claim your daily credits or if you already claimed them.