/Imaginepy

ImaginePy, opensource (reversed) API like Stable Diffusion, Midjourney. Everything at 0 Cost.

Primary LanguagePythonGNU General Public License v3.0GPL-3.0

ImaginePy
Discord Banner 4
Python version Release Version

Features

  • 🎨 Turn words into art
  • 👓 Choose from an array of art styles
  • 🔧 Adjust your masterpiece with creative controls!
  • 📦 Stay ahead of the game with the ever-growing art library!
  • 🌇 Generate wallpapers
  • 🔎 Discover and explore similar artistic designs
  • This is refactored and improved version of the original from hyugogirubato

Installation

Note: Requires Python 3.7.0 or newer with PIP installed.

$ python setup.py install

You now have the imaginepy package installed.

PyPi Installation

pip install imaginepy

From Source Code

The following steps are instructions on download, preparing, and running the code under a Venv environment. You can skip steps 3-5 with a simple python setup.py install call instead, but you miss out on a wide array of benefits.

  1. git clone https://github.com/ItsCEED/Imaginepy
  2. cd Imaginepy
  3. python -m venv env
  4. source env/bin/activate
  5. python setup.py install

As seen in Step 5, running the imaginepy executable is somewhat different to a normal PIP installation. See Venv's Docs on various ways of making calls under the virtual-environment.

Usage

The following is a minimal example of using ImaginePy in a script. It gets the generated image from the text and increases the quality.

from imaginepy import Imagine
from imaginepy.constants import *


def main():
    imagine = Imagine()

    img_data = imagine.sdprem(
        prompt="Woman sitting on a table, looking at the sky, seen from behind",
        style=Style.NO_STYLE,
        ratio=Ratio.RATIO_16X9,
        negative="",
        seed=1000,
        cfg=16,
        model=Model.REALISTIC,
        asbase64=False  # default is false, putting it here as presentation.
    )

    if img_data is None:
        print("An error occurred while generating the image.")
        return

    img_data = imagine.upscale(img_data)

    if img_data is None:
        print("An error occurred while upscaling the image.")
        return

    try:
        with open("example.jpeg", mode="wb") as img_file:
            img_file.write(img_data)
    except Exception as e:
        print(f"An error occurred while writing the image to file: {e}")


if __name__ == "__main__":
    main()

Async version

import asyncio
from imaginepy import AsyncImagine
from imaginepy.constants import *


async def main():
    imagine = AsyncImagine()
    img_data = imagine.sdprem(
        prompt="Woman sitting on a table, looking at the sky, seen from behind",
        style=Style.NO_STYLE,
        ratio=Ratio.RATIO_16X9,
        negative="",
        seed=1000,
        cfg=16,
        model=Model.REALISTIC,
        asbase64=False  # default is false, putting it here as presentation.
    )

    if img_data is None:
        print("An error occurred while generating the image.")
        return

    img_data = await imagine.upscale(image=img_data)

    if img_data is None:
        print("An error occurred while upscaling the image.")
        return

    try:
        with open("example.png", mode="wb") as img_file:
            img_file.write(img_data)
    except Exception as e:
        print(f"An error occurred while writing the image to file: {e}")

    await imagine.close()


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

Credit

  • Imagine Icon © Vyro AI & API
  • Original reverse and version by: hyugogirubato

License

GNU General Public License, Version 3.0