acheong08 / bingimagecreator Goto Github PK
View Code? Open in Web Editor NEWHigh quality image generation by Microsoft. Reverse engineered API.
License: The Unlicense
High quality image generation by Microsoft. Reverse engineered API.
License: The Unlicense
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"
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.
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)
I see Microsoft just release a new product name is Mcrosoft Design with Dall e 2.5. Can you intergrate this repo with it
BingImageCreator/src/BingImageCreator.py
Line 254 in 2213130
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>
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.
And down there, I removed the _U
extraction from the cookie file and left it to be passed entirely.
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
Something like def save_images(self, links: list, output_dir: str,file_name:str='') -> None:
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`
...
line 123, in
with open(args.cookie_file, encoding="utf-8") as file:
TypeError: expected str, bytes or os.PathLike object, not NoneType
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")
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
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:
Generating images "the normal way" inside the browser is working fine.
Any ideas what I can try to fix this issue?
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
I'm in china mainland,but i don't want to use VPN.
How can i non-VPN to use it?
INFO[0004] [TCP] 127.0.0.1:48148 --> www.bing.com:443 using GLOBAL
WARN[0004] [TCP] dial GLOBAL 127.0.0.1:48152 --> www.bing.comhttps:443 error: couldn't find ip
Why does www.bing.com become www.bing.comhttps
Has anyone ever had this problem
function to save forward My saved items with a form of function
https://www.bing.com/saves?&FORM=savim2&collId=3
https://www.bing.com/mysaves/edge/collections/3/items?Comp=IDPMainImage&sid="
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)
error Timeout context manager should be used inside a task
or Unclosed client session
while trying to generate with ImageGenAsync, how to fix?
-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",
]
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.