Skip to content

hoopengo/HappyAccidentsAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

banner

License Pypi Pypi Downloads Python version

HappyAccidentsAPI

At the moment, HappyAccidents has not provided an official API and the library is built on the basis of the client API. Because of this, you may find bugs and shortcomings, if this happened, please provide a report in Issues.

Installation

# Via pip
## Linux/macOS
python3 -m pip install -U happyaccidentsapi

## Windows
py -3 -m pip install -U happyaccidentsapi

# Via poetry
poetry add happyaccideentsapi

# [SOON]Via pacman
# pacman -Sy python-happyaccidentsapi

Quick example

import asyncio

from happyaccidentsapi import ClientAPI
from happyaccidentsapi.models import CreateInferenceParams


async def main():
    api = ClientAPI(token="...")
    model = (await api.fetch_metadata_items("Stable Diffusion v1.5")).first()

    inference_params = CreateInferenceParams(
        modelId=model.id,
        prompt="Beautiful girl on the beach",
        numImagesToGenerate=5,
    )

    inference = await api.create_inference(inference_params)  # <InferenceHistoricalResult ...>
    for image in inference.images:  # [<ImageRecord ...>, ...]
        print(image.get_url())  # https://https://ik.imagekit.io/.../result-4.png
        await image.save(f"./images/{image.id}-{image.filename}")


if __name__ == "__main__":
    asyncio.run(main())

NOTE: It is not advised to leave your token directly in your code, as it allows anyone with it to access your account. If you intend to make your code public you should store it securely.

Links