Giter VIP home page Giter VIP logo

pyfirefly's Introduction

pyfirefly

python library for reverse engineered Adobe Firefly API

Installing

pip install pyfirefly

Example Usage

Text to Image

The following example will request for 10 images of "flying cats" from Adobe Firefly and save those images.

import asyncio
import aiohttp
import aiofiles

import pyfirefly
from pyfirefly.utils import ImageOptions

token = 'ey...'  # replace with your bearer token

async def create_save_image(a, prompt, img_options, num):
    result = await a.text_to_image(prompt, **img_options)
    async with aiofiles.open(f'{num}.{result.ext}', mode='wb+') as f:
        await f.write(result.image)


async def demo(prompt, num):
    a = await pyfirefly.Firefly(token)
    img = ImageOptions(image_styles = a.image_styles)
    img.add_styles(['Photo', 'Blurry background', 'Origami'])

    tasks = [create_save_image(a, prompt, img.options, i) for i in range(num)]

    await asyncio.gather(*tasks)


asyncio.run(demo('flying cats', 10))

Glyph to Image

The following example will request for 10 images of a glyph.webp image that has "bundle of colorful electric wires" as the fill effect. example webp image

import asyncio
import aiohttp
import aiofiles

import pyfirefly
from pyfirefly.utils import ImageOptions

token = 'ey...'  # replace with your bearer token

async def create_save_image(a, glyph, img_options, num):
    result = await a.glyph_to_image(glyph, **img_options)
    async with aiofiles.open(f'{num}.{result.ext}', mode='wb+') as f:
        await f.write(result.image)


async def demo(input_fn, num):
    async with aiofiles.open('./glyph.webp', mode='rb') as f:
        glyph = await f.read()

    a = await pyfirefly.Firefly(token)
    img = ImageOptions(text_presets = a.text_presets)
    img.set_text_preset('wires')

    tasks = [create_save_image(a, glyph, img.options, i) for i in range(num)]

    await asyncio.gather(*tasks)


asyncio.run(demo('glyph.webp', 10))

Docs

https://discordtehe.github.io/pyfirefly

pyfirefly's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.