GithubHelp home page GithubHelp logo

acheong08 / bingimagecreator Goto Github PK

View Code? Open in Web Editor NEW
292.0 11.0 89.0 77 KB

High quality image generation by Microsoft. Reverse engineered API.

License: The Unlicense

Python 97.94% Makefile 2.06%
bing edgegpt image-generation microsoft reverse-engineering

bingimagecreator's People

Contributors

coolplaylin avatar doevent avatar fbarbe00 avatar fredi-python avatar mic92 avatar qcgm1978 avatar richardoc avatar spike014 avatar vmtask avatar xnny avatar yihong0618 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bingimagecreator's Issues

Exception: Redirect failed

Hi,

i still get the Redirect failed error. Tried several things, new cookie, different versions of your tool (up to 0.1.2), different prompts, even running it inside a docker container and with VPN, each time the same error:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/usr/local/lib/python3.11/site-packages/BingImageCreator.py", line 380, in <module>
    main()
  File "/usr/local/lib/python3.11/site-packages/BingImageCreator.py", line 372, in main
    image_generator.get_images(args.prompt),
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/BingImageCreator.py", line 99, in get_images
    raise Exception(error_redirect)
Exception: Redirect failed

Before this error there is a really large "wall of text" with html code. Pasting this into a textfile and opening in Firefox I get the following image:
image

Generating images "the normal way" inside the browser is working fine.
Any ideas what I can try to fix this issue?

Redirect errors with valid cookies

Using the latest release (0.4.2) like this:

$ edge-gpt-image --prompt "A funny cat" --cookie-file /tmp/cookies.json

Results in:

Traceback (most recent call last):
  File "/nix/store/6xycw16a59gf3wlpbs7cpabayz10q40w-python3.10-edge-gpt-0.10.11/bin/.edge-gpt-image-wrapped", line 9, in <module>
    sys.exit(main())
  File "/nix/store/5h6j028kglkpysjpsp517dvcb1a6w703-python3.10-bing-image-creator-0.4.2/lib/python3.10/site-packages/BingImageCreator.py", line 467, in main
    asyncio.run(
  File "/nix/store/6qk2ybm2yx2dxmx9h4dikr1shjhhbpfr-python3-3.10.11/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/nix/store/6qk2ybm2yx2dxmx9h4dikr1shjhhbpfr-python3-3.10.11/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
    return future.result()
  File "/nix/store/5h6j028kglkpysjpsp517dvcb1a6w703-python3.10-bing-image-creator-0.4.2/lib/python3.10/site-packages/BingImageCreator.py", line 394, in async_image_gen
    images = await image_generator.get_images(prompt)
  File "/nix/store/5h6j028kglkpysjpsp517dvcb1a6w703-python3.10-bing-image-creator-0.4.2/lib/python3.10/site-packages/BingImageCreator.py", line 299, in get_images
    raise Exception("Redirect failed")
Exception: Redirect failed

Full error:
errors.txt

The same cookie works in edge-gpt:

edge-gpt --prompt "A funny cat" --cookie-file /tmp/cookies.json

        EdgeGPT - A demo of reverse engineering the Bing GPT chatbot
        Repo: github.com/acheong08/EdgeGPT
        By: Antonio Cheong

        !help for help

        Type !exit to exit

Initializing...
Enter `alt+enter` or `escape+enter` to send a message

You:
A funny cat

Bot:
Searching the web for: `funny cat`
...

Nothing happens.

I put in my api key and other params in the terminal and nothing happens:

.\venv\Lib\site-packages\BingImageCreator.py --U [APIKEY] --prompt "Pixel art of a spaceman riding a skateboard"

Exception: Redirect failed

command like this:
python3 -m BingImageCreator --cookie-file cookies.json --prompt "a white cat" --output-dir ./output/
response this:

Traceback (most recent call last):
File "/usr/local/python3/lib/python3.8/runpy.py", line 193, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/local/python3/lib/python3.8/runpy.py", line 86, in _run_code
exec(code, run_globals)
File "/usr/local/python3/lib/python3.8/site-packages/BingImageCreator.py", line 489, in
main()
File "/usr/local/python3/lib/python3.8/site-packages/BingImageCreator.py", line 470, in main
image_generator.get_images(args.prompt),
File "/usr/local/python3/lib/python3.8/site-packages/BingImageCreator.py", line 136, in get_images
raise Exception(error_redirect)
Exception: Redirect failed

ModuleNotFoundError: No module named 'BingImageCreator.BingImageCreator'; 'BingImageCreator' is not a package

I am trying to write your awesome python package into a script, and I keep getting the same error I have tried:
from BingImageCreator import BingImageCreator

import BingImageCreator.BingImageCreator as BingImageCreator

import BingImageCreator

image_creator = BingImageCreator()

import BingImageCreator

image_creator = BingImageCreator.BingImageCreator()
I am very new to coding and could use some help here. when I run your instructions in Power Shell it works so it seems to be installed correctly. I have it located in the python packages directory by using the pip and pip3 commands. I have Python 3.11.3 installed.

raise Bad images broken

-v 0.1.3
When raise exception "bad images" - doesn't returns exception, returns list of photo.

Line: 271 in BingImageCreator.py / get_images()

Returns this list:
bad_images = [
"https://r.bing.com/rp/in-2zU3AJUdkgFe7ZKv19yPBHVs.png",
"https://r.bing.com/rp/TX9QuO3WzcCJz1uaaSwQAz39Kb0.jpg",
]

better results with "https://cn.bing.com"

In some cases, BIC doesn't work (http connexion errors). (in threads of gunicorn/h11 workers)
I dive into the code, and reach to fix it ... just by changing the global var "BING_URL" from "https://www.bing.com" to "https://cn.bing.com" ... (in that cases, when using the original one, the first POST couldn't return the id, and breaks the following .... with the 'cn' version : it worked ootb) ... perhaps It could help someone.

BTW, you should concentrate your effort on the async one .... and make the sync one based on using the async one. (currently you have the 2 methods to maintain, when api/http changes)

BTW2: relations between edgegpt & bingimagecreator are confusing. For my needs, I've made a class, which use both, and expose functions from both in one instance. It's the way to go. And since, "creative mode" can return images too, it has a lot of sense ! Because it could replace the BIC apis. Because in chat mode, it's a lot easier to make multiple requests to make images, with context keeped. (the are no context in BIC)

Redirect fail.

Stopped working recently with redirect failure.

HTML dump shows panda image with the text:
"We're sorry — we've run into an issue.
The page is currently unavailable. Try creating an image or explore ideas on the [Bing Image Creator homepage.]"

Was initially getting the same message when trying to manually create images, but then that started working again.
Code still fails though.

Have they implemented additional Auth checks or something to try stop automating this?

(cn.bing isn't any different)

Redirect failed exceptions on any prompts

I am on edge-gpt 0.3.6 and bing-image-creator 0.1.5.
The same cookie that works for edge-gpt and has now stopped working for the bing image creator. So I am assuming something in the website changed?

$ python3 -m BingImageCreator --cookie-file /tmp/cookies2.json --prompt "Hello World" --debug-file /tmp/foo.log
...
 Traceback (most recent call last):                                                                                                                                              
 ▏ File "/nix/store/g15w167kd4wrzbyjbhh68irx2g8fc6fk-python3.10-edge-gpt-0.3.6/bin/.edge-gpt-image-wrapped", line 9, in <module>                                                 
 ▏ ▏ sys.exit(main())                                                                                                                                                            
 ▏ File "/nix/store/q6a1q207p2q5imhmmh0v5h1a5xxmwzyw-python3.10-bing-image-creator-0.1.5/lib/python3.10/site-packages/BingImageCreator.py", line 380, in main                    
 ▏ ▏ image_generator.get_images(args.prompt),                                                                                                                                    
 ▏ File "/nix/store/q6a1q207p2q5imhmmh0v5h1a5xxmwzyw-python3.10-bing-image-creator-0.1.5/lib/python3.10/site-packages/BingImageCreator.py", line 111, in get_images              
 ▏ ▏ raise Exception(error_redirect)                                                                                                                                             
 Exception: Redirect failed                                                                                                                                                      

The full error is here: error.txt

Warning:Unclosed client session

As titile, each time the function is runned, there is always a warning:Unclosed client session, if you can solve this problem, I will give you my great thanks!
Hope you have a nice day!😀

Here is the full log:
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x000002177E518310>
Unclosed connector
connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x000002177F0B9240>, 4686.937), (<aiohttp.client_proto.ResponseHandler object at 0x000002177F0B9860>, 4694.015)]']
connector: <aiohttp.connector.TCPConnector object at 0x000002177F0F2FD0>

Exception: Redirect failed

i got this

Traceback (most recent call last):
  File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/dev/.local/lib/python3.10/site-packages/BingImageCreator.py", line 137, in <module>
    image_generator.get_images(args.prompt),
  File "/home/dev/.local/lib/python3.10/site-packages/BingImageCreator.py", line 47, in get_images
    raise Exception("Redirect failed")

I tried everything but "Not a redirect"

I use this code:

 import httpx,asyncio,re,json
  
  HEADERS= {} # doesn't seem to be needed (?!)
  
  COOKIES={}
  for cookie in json.loads(open('bingOld.json', encoding="utf-8").read()):
      COOKIES[ cookie.get("name") ] = cookie.get("value")
  
  async def get_images(prompt:str) -> list:
      async with httpx.AsyncClient(base_url="https://www.bing.com", headers=HEADERS, cookies=COOKIES) as bing:
          r = await bing.post("/images/create",data={"q":prompt,"qs":"ds"},params={"q":prompt,"rt":4,"FORM":"GENCRE"})
          assert r.status_code==302, f"not a redirect: http/{r.status_code} ?!"
          request_id = r.headers.get("location","").split("id=")[-1]
      
          assert request_id.isalnum(),f"the redirect location doesn't contain 'id' {r.headers.get('location')}?!"
          
          await asyncio.sleep(5)   # seems it takes always more than 5sec
  
          for nb_retry in range(30):
              await asyncio.sleep(1)
              
              r=await bing.get(f"/images/create/async/results/{request_id}",params={"q":prompt})
              assert r.status_code==200,f"the polling url returns http/{r.status_code} ?!"
              
              if image_links := re.findall(r'src="([^"]+)"', r.text):
                  return [ x.split("?")[0] for x in image_links ]
              
          return [] # 30 poll calls, and nothing ;-(
  
  ll=asyncio.run(  get_images("cat with a ball")  )
  print( ll )

Tried a lot of things for the cookies. Chrome cookie editor and cookieStore.get("_U").then(result => console.log(result.value))
The last gives me just one huge string. Is this correct?

Apart from that I have no idea what I am missing.

Thanks for the help

Support Microsoft Designer

I see Microsoft just release a new product name is Mcrosoft Design with Dall e 2.5. Can you intergrate this repo with it

Just solved the `Exception: Redirect failed` error

Using the latest version of the project.
Received this error in response to any prompt.
Until I modified the code to pass ALL COOKIES, not just _U, and, miraculously, it worked without any exception.
#7 #16 #28
I know my quick edit is not the best way to implement this, but I'm sure we should add such a feature to the main project, as it could solve the problem for many people.
Снимок экрана 2023-05-21 в 13 42 29
And down there, I removed the _U extraction from the cookie file and left it to be passed entirely.

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.