Skip to content

Waenara/bing-create

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Bing Create

This is a simple lightweight reverse engineered Bing Image Creator API made in python that allows you to quickly generate high quality AI images. This package was inspired by BingImageCreator package and the main goal is to make better version of it.

Advantages over the original package:

  • Actively maintained
  • Lightweight
  • Easier to use
  • Ability to specify the number of images to generate
  • Termux support
  • Complete code rewrite

You can use it from console\terminal or integrate it to your python project. To get started read the instructions below.

Installation

To install the package you can use pip:

pip install bing-create

or you can clone the repository and install it manually:

git clone https://github.com/Waenara/bing-create.git
cd bing_create
pip install .

Usage

Getting cookies

After installing the package as described above you will need to get your _U and SRCHHPGUSR cookies from Bing. You can do this by logging in to Bing, opening the developer tools (F12) and going to the console tab. Then you can run the following code:

console.log(`_U:\n${document.cookie.match(/(?:^|;\s*)_U=(.*?)(?:;|$)/)[1]}\n\nSRCHHPGUSR:\n${document.cookie.match(/(?:^|;\s*)SRCHHPGUSR=(.*?)(?:;|$)/)[1]}`)

This will output your _U and SRCHHPGUSR cookies.

Terminal\Console

If you are an average user you can use the package from the console\terminal. After you installed the package and got the cookies. use the following command to get help, or you may enter arguments from below to generate images:

bing-create

All arguments:

  • --u - Your _U cookie
  • --s - Your SRCHHPGUSR cookie
  • --prompt - Description of images you want to generate
  • --output (Optional) - Path to directory where the images will be saved
  • --number (Optional, default: 4) - Number of images to generate
  • --quiet (Optional) - If present logging is disabled

Integration to your python project

If you are a developer you can integrate the package to your python project. Here is an example of how you can use the package:

Synchronous:

from bing_create.main import ImageGenerator

# Create an instance of the ImageGenerator class
generator = ImageGenerator(
    auth_cookie_u='Your _U cookie',
    auth_cookie_srchhpgusr='Your SRCHHPGUSR cookie'
)

# Generate 5 images from a text prompt
images = generator.generate(
    prompt='A cute cat',
    num_images=5
)

# Save the images to the directory called 'output'
generator.save(
    images=images, 
    output_dir='output'
)

Asynchronous:

import asyncio
from bing_create.main import AsyncImageGenerator


async def main():
    # Create an instance of the AsyncImageGenerator class
    generator = AsyncImageGenerator(
        auth_cookie_u='Your _U cookie',
        auth_cookie_srchhpgusr='Your SRCHHPGUSR cookie'
    )

    # Generate 5 images from a text prompt
    images = await generator.generate(
        prompt='A cute cat',
        num_images=5
    )

    # Save the images to the directory called 'output'
    await generator.save(
        images=images,
        output_dir='output'
    )


asyncio.run(main())

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages