Code Monkey home page Code Monkey logo

dalle3's Introduction

Multi-Modality

DALLE3 API

A radically simple Dalle3 API.

Disclaimer: This code is provided "as-is" and is not affiliated with or endorsed by the source website. Use responsibly and at your own risk.

Installation 🐠


You can install DALLE3 API using pip:

pip3 install --upgrade dalle3

Usage 🐡


Here's a simple example of how to use DALLE3 API:

import logging
from dalle3 import Dalle

# Define cookie using env or empty string
cookie = ""

# Set up logging
logging.basicConfig(level=logging.INFO)

# Instantiate the Dalle class with your cookie value
dalle = Dalle(cookie)

# Open the website with your query
dalle.create(
    "Fish hivemind swarm in light blue avatar anime in zen garden pond concept art anime art, happy fish"
)

# Get the image URLs
urls = dalle.get_urls()

# Download the images to your specified folder
dalle.download(urls, "images/")

Dalle Documentation

Table of Contents

  1. Introduction
  2. Dalle Class
  3. Methods and Usage
  4. Examples
  5. Additional Information
  6. References and Resources

1. Introduction

Welcome to the documentation on the Dalle class. This comprehensive guide provides in-depth information about the Dalle library and its core components. Before we dive into the details, it's crucial to understand the purpose and significance of this library.

1.1 Purpose

This library houses the DALL-E 3 Unofficial API, providing tools to download images based on queries. The Dalle class facilitates this process, allowing users to interact with the API efficiently.

1.2 Key Features

  • DALL-E 3 API Interaction: The Dalle class provides an interface to interact with the DALL-E 3 Unofficial API.

  • Image Download: Dalle3 allows you to download images from the web based on your queries.


2. Dalle Class

The Dalle class is a fundamental module in the Dalle3 library, enabling interactions with the DALL-E 3 Unofficial API.

2.1 Initialization Parameters

Here are the initialization parameters for the Dalle class:

  • cookie_value (str): A string representing the cookie value to bypass automation detection.

2.2 Methods

The Dalle class provides the following methods:

  • get_time(): Returns the current time in the format "[%d/%m/%Y %H:%M:%S]".

  • get_time_save(): Returns the current time in the format "%d-%m-%Y %H-%M-%S".

  • download(urls: list, save_folder: str): Downloads images from the provided URLs and saves them in the specified folder.

  • create(query: str): Opens the Bing Image Creator (DALL-E 3) and adds a cookie to interact with the API.

  • get_urls(): Extracts and returns image URLs from the website.

  • run(query: str): Runs the whole process of downloading images from the provided query.


3. Methods and Usage

Let's explore the methods provided by the Dalle class and how to use them effectively.

3.1 get_time Method

The get_time method returns the current time in the format "[%d/%m/%Y %H:%M:%S]". It's a utility function to help with logging and timestamping.

3.2 get_time_save Method

The get_time_save method returns the current time in the format "%d-%m-%Y %H-%M-%S". It's useful for creating timestamped folders for image downloads.

3.3 download Method

The download method takes a list of image URLs and a save folder path. It downloads images from the provided URLs and saves them in the specified folder. This method is crucial for downloading images based on your queries.

3.4 create Method

The create method opens the Bing Image Creator (DALL-E 3) website and adds a cookie to bypass automation detection. It prepares the environment for querying and downloading images.

3.5 get_urls Method

The get_urls method extracts and returns image URLs from the website. It allows you to retrieve the image URLs that match your query.

3.6 run Method

The run method combines the previous methods to execute the whole process of downloading images based on the provided query. It's a convenient way to automate the image download process.


4. Examples

Let's dive into practical examples to demonstrate the usage of the Dalle class.

4.1 Example 1: Creating a Dalle Instance

In this example, we create an instance of the Dalle class with your provided cookie value:

# Instantiate the Dalle class with your cookie value
dalle = Dalle("your_cookie_value_here")

4.2 Example 2: Running the Whole Process

Here, we demonstrate how to use the Dalle class to run the whole process of downloading images based on a query:

# Run the whole process of downloading images from the provided query
dalle.run("Fish hivemind swarm in light blue avatar anime in zen garden pond concept art anime art, happy fish, anime scenery")

5. Additional Information

Here are some additional tips and information for using the Dalle3 library and the Dalle class effectively:

  • The download method allows you to specify the folder where downloaded images will be saved. Ensure that you have the necessary permissions to write to that folder.

  • If you encounter issues with image downloads, check the prompt you provided. The quality and specificity of your query can affect the results.


6. References and Resources

For further information and resources related to the Dalle3 library and DALL-E:

This concludes the documentation for the Dalle3 library and the Dalle class. You now have a comprehensive guide on how to interact with the DALL-E 3 Unofficial API and download images based on your queries using Dalle3.

7. Obtaining Your Cookie 🍪


To use DALLE3 API, you need to obtain your cookie from Bing Image Creator. Here's how you can do it:

  1. Go to Bing Image Creator in your browser and log in to your account.
  2. Press Ctrl+Shift+J (or Cmd+Option+J on Mac) to open developer tools.
  3. Navigate to the Application section.
  4. Click on the Cookies section.
  5. Find the variable _U and copy its value.
  6. Paste in the cookie parameter.

Now you can use this cookie value to instantiate the Dalle class.

8. Edge Cases 🦀


  • If the save_folder path you provide when calling download does not exist, the function will attempt to create it. Make sure you have the necessary permissions to create directories in the specified location.
  • If the user is not signed in on the browser that Selenium WebDriver is controlling, the script will not be able to retrieve the cookie. Make sure you're signed in to your Bing Image Creator account in the same browser session.
  • If you see: selenium.common.exceptions.WebDriverException: Message: unknown error: cannot connect to chrome at 127.0.0.1:58296 from session not created: This version of ChromeDriver only supports Chrome version 118 Current browser version is 117.0.5938.15 then you need to update your chrome by going here: t add chrome://settings/help

Features 🌊


  • Easy to Use: With just a few lines of code, you can start generating images.
  • Customizable: You can provide your own creative prompts to generate unique images.
  • Automated Download: The API automatically downloads the generated images to your specified folder.
  • Real-Time Updates: The API provides real-time logging information about the image generation and download process.

License 📜


DALLE3 API is licensed under the MIT License. See the LICENSE file for more details.

Todo

  • Add Automatic cookie finding seamlessly
  • Automatically upgrade chrome to 118
  • Add automatic browser detection, cross browser
  • Lower amount of endpoints to run by 90% => dalle = Dalle() dalle.run("image")
  • Add gpt4 vision api using same approach, scrape and enter but need to find the right cookie
  • Establish Idea2Image Documentation
  • Create tests for Idea2Image
  • Add human feedback for idea2image, prompt -> llm -> dalle -> human feedback -> back to llm -> dalle
  • Different output types, svg, jpg
  • Add bingchat api
  • Add chatgpt dalle api
  • Create Chatgpt V api

dalle3's People

Contributors

carden-code avatar dependabot[bot] avatar elder-plinius avatar kyegomez 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

dalle3's Issues

TOS

is this against the TOS, and will they ban accounts for this? You should let people know ahead of time, that this is not an "unofficial api", this is literally a webscraper.

from: https://www.microsoft.com/en-us/servicesagreement
"ii. Extracting Data. Unless explicitly permitted, you may not use web scraping, web harvesting, or web data extraction methods to extract data from the AI services."

[BUG] NFO:undetected_chromedriver.patcher:patching driver executable /Users/abcd/Library/Application Support/undetected_chromedriver/undetected_chromedriver INFO:root:[21/10/2023 01:11:24] Bing Image Creator (Dalle-3) Opened INFO:root:[21/10/2023 01:11:24] Cookie values added

Describe the bug
Getting this error:INFO:undetected_chromedriver.patcher:patching driver executable /Users/abcd/Library/Application Support/undetected_chromedriver/undetected_chromedriver
INFO:root:[21/10/2023 01:11:24] Bing Image Creator (Dalle-3) Opened
INFO:root:[21/10/2023 01:11:24] Cookie values added
To Reproduce
When executing the example script from the readme I get the error:
Getting this error:INFO:undetected_chromedriver.patcher:patching driver executable /Users/abcd/Library/Application Support/undetected_chromedriver/undetected_chromedriver
INFO:root:[21/10/2023 01:11:24] Bing Image Creator (Dalle-3) Opened
INFO:root:[21/10/2023 01:11:24] Cookie values added

[BUG] CRITICAL:root:Error while extracting image urls...

I ran the supplied simple example with my _U cookie and get this error:

CRITICAL:root:Error while extracting image urls. Maybe something is wrong about your prompt. (You can check you prompt manually)

Does this still work for other people?

[ERR0R]

i have already pasted mybig cookie still error

TypeError Traceback (most recent call last)
in <cell line: 13>()
11
12 # Instantiate the Dalle class with your cookie value
---> 13 dalle = Dalle(cookie)
14
15 # Open the website with your query

2 frames
/usr/local/lib/python3.10/dist-packages/selenium/webdriver/chromium/options.py in binary_location(self, value)
50 """
51 if not isinstance(value, str):
---> 52 raise TypeError(self.BINARY_LOCATION_ERROR)
53 self._binary_location = value
54

TypeError: Binary Location Must be a String

[BUG]

Describe the bug
Getting a cannot import name 'Dalle3' from 'dalle3' (D:_activeDev\dalle32.venv\Lib\site-packages\dalle3_init_.py)

To Reproduce
Steps to reproduce the behavior:
create a folder
install venv virtual environment
pip install python-dotenv, dalle3
Copy the initial code example.
Bug will display
maybe something to do with venv and the file structure?

Simultaneous image generation

Hello, please tell me how the generation works now? Do I need to wait until 1 request is completed or can I generate several at the same time? If you open 2 tabs in the browser and write 2 different requests and send them at the same time, they will be executed.

Specify chrome driver version

Is your feature request related to a problem? Please describe.
Github action environment doesnot support latest chrome driver version 118.

Error message:

This version of ChromeDriver only supports Chrome version 118\nCurrent browser version is 117.0.5938.0

Describe the solution you'd like
Maybe add a parameter to Dalle object or provide someway(environment variables) to manually assign version of chrome drive. Which eventually goes to undetected_chromedriver.Chrome.

   import undetected_chromedriver as uc
   driver = uc.Chrome( version_main = 95 )

[BUG] Bing image creator change the query url

Thanks very much for the great work.
It seems now Bing image creator change the query url from "https://www.bing.com/images/create?q=XXXXX" to https://www.bing.com/images/create?q=A%20fish%20is%20fishing%20a%20human&rt=4&FORM=GENCRE&id=6543ae2527e145a3895ad3cfd7612d33
and
https://www.bing.com/images/create/a-fish-is-fishing-a-human/6543ae2527e145a3895ad3cfd7612d33?FORM=GENCRE
This id seems different in each queries.
Could you help me to fix this issue?
image

[BUG]

Describe the bug
What am I doing wrong?
To Reproduce
Steps to reproduce the behavior:

import os
import logging
from dalle3 import Dalle
Traceback (most recent call last):
File "", line 1, in
File "/opt/homebrew/lib/python3.11/site-packages/dalle3/init.py", line 2, in
from dalle3.idea2image import Idea2Image
File "/opt/homebrew/lib/python3.11/site-packages/dalle3/idea2image.py", line 5, in
from swarms.models import OpenAIChat
File "/opt/homebrew/lib/python3.11/site-packages/swarms/init.py", line 13, in
from swarms.swarms.orchestrate import Orchestrator
File "/opt/homebrew/lib/python3.11/site-packages/swarms/swarms/init.py", line 3, in
from swarms.swarms.dialogue_simulator import DialogueSimulator
File "/opt/homebrew/lib/python3.11/site-packages/swarms/swarms/dialogue_simulator.py", line 2, in
from swarms.workers.worker import Worker
File "/opt/homebrew/lib/python3.11/site-packages/swarms/workers/init.py", line 1, in
from swarms.workers.worker import Worker
File "/opt/homebrew/lib/python3.11/site-packages/swarms/workers/worker.py", line 13, in
from swarms.tools.autogpt import (
File "/opt/homebrew/lib/python3.11/site-packages/swarms/tools/autogpt.py", line 6, in
import pandas as pd
ModuleNotFoundError: No module named 'pandas'

InvalidArgumentException: Message: invalid argument: missing 'value'

When I use the Example code you provide:

`

import os
import logging
from dalle3 import Dalle

cookie = os.getenv("16OIrOlIoTP5fqH8GhswDQ67f_Q4T-hyBZwnVzlhEg8oZE4B2jVEwa1Sog9mis_8lVS_XM8KPRHOZuyePRHXm55-lOANcfivACBuuBaqQ29kRL_lxzM343TMR95c9Kr3gYylpyzgm41iUO4r3o0Rrowcw30XIgF9rYcthyWPW9Dw0azAmFSCgOJM7G07l9lA_EUdNvWn1spdHYI3arFbV4g")

logging.basicConfig(level=logging.INFO)

dalle = Dalle(cookie)

dalle.create(
"Fish hivemind swarm in light blue avatar anime in zen garden pond concept art anime art, happy fish, anime scenery"
)

urls = dalle.get_urls()`

It returns this message:

could not detect version_main.therefore, we are assuming it is chrome 108 or higher
Started executable: C:\Users\Isuch\appdata\roaming\undetected_chromedriver\undetected_chromedriver.exe in a child process with pid: 12564
POST http://localhost:52674/session {"capabilities": {"firstMatch": [{}], "alwaysMatch": {"browserName": "chrome", "pageLoadStrategy": "normal", "goog:chromeOptions": {"extensions": [], "binary": "C:\Program Files\Google\Chrome\Application\chrome.exe", "args": ["--disable-blink-features=AutomationControlled", "--remote-debugging-host=127.0.0.1", "--remote-debugging-port=52673", "--user-data-dir=C:\Users\IGNACI~1\AppData\Local\Temp\tmp9w7qfeaa", "--lang=es-ES", "--no-default-browser-check", "--no-first-run", "--no-sandbox", "--test-type", "--headless=new", "--window-size=1920,1080", "--start-maximized", "--no-sandbox", "--log-level=0"], "debuggerAddress": "127.0.0.1:52673"}}}}
Starting new HTTP connection (1): localhost:52674
http://localhost:52674/ "POST /session HTTP/1.1" 200 0
Remote response: status=200 | data={"value":{"capabilities":{"acceptInsecureCerts":false,"browserName":"chrome","browserVersion":"118.0.5993.89","chrome":{"chromedriverVersion":"118.0.5993.70 (e52f33f30b91b4ddfad649acddc39ab570473b86-refs/branch-heads/5993@{#1216})"},"fedcm:accounts":true,"goog:chromeOptions":{"debuggerAddress":"127.0.0.1:52673"},"pageLoadStrategy":"normal","platformName":"","proxy":{},"setWindowRect":false,"strictFileInteractability":false,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000},"unhandledPromptBehavior":"dismiss and notify","webauthn:extension:credBlob":true,"webauthn:extension:largeBlob":true,"webauthn:extension:minPinLength":true,"webauthn:extension:prf":true,"webauthn:virtualAuthenticators":true},"sessionId":"db78f584ef599cf1edb53c83ab073138"}} | headers=HTTPHeaderDict({'Content-Length': '760', 'Content-Type': 'application/json; charset=utf-8', 'cache-control': 'no-cache'})
Finished Request
POST http://localhost:52674/session/db78f584ef599cf1edb53c83ab073138/execute/sync {"script": "return navigator.webdriver", "args": []}
http://localhost:52674/ "POST /session/db78f584ef599cf1edb53c83ab073138/execute/sync HTTP/1.1" 200 0
Remote response: status=200 | data={"value":false} | headers=HTTPHeaderDict({'Content-Length': '15', 'Content-Type': 'application/json; charset=utf-8', 'cache-control': 'no-cache'})
Finished Request
POST http://localhost:52674/session/db78f584ef599cf1edb53c83ab073138/url {"url": "https://www.bing.com/images/create?q=Fish hivemind swarm in light blue avatar anime in zen garden pond concept art anime art, happy fish, anime scenery"}
http://localhost:52674/ "POST /session/db78f584ef599cf1edb53c83ab073138/url HTTP/1.1" 200 0
Remote response: status=200 | data={"value":null} | headers=HTTPHeaderDict({'Content-Length': '14', 'Content-Type': 'application/json; charset=utf-8', 'cache-control': 'no-cache'})
Finished Request
[18/10/2023 10:50:52] Bing Image Creator (Dalle-3) Opened
POST http://localhost:52674/session/db78f584ef599cf1edb53c83ab073138/cookie {"cookie": {"name": "_U", "value": null}}
http://localhost:52674/ "POST /session/db78f584ef599cf1edb53c83ab073138/cookie HTTP/1.1" 400 0
Remote response: status=400 | data={"value":{"error":"invalid argument","message":"invalid argument: missing 'value'\n (Session info: chrome=118.0.5993.89)","stacktrace":"\tGetHandleVerifier [0x002C4DE3+43907]\n\t(No symbol) [0x00250741]\n\t(No symbol) [0x001433ED]\n\t(No symbol) [0x001B276B]\n\t(No symbol) [0x00192B5C]\n\t(No symbol) [0x001A55CA]\n\t(No symbol) [0x00192956]\n\t(No symbol) [0x0016E17E]\n\t(No symbol) [0x0016F32D]\n\tGetHandleVerifier [0x00575AF9+2865305]\n\tGetHandleVerifier [0x005BE78B+3163435]\n\tGetHandleVerifier [0x005B8441+3138017]\n\tGetHandleVerifier [0x0034E0F0+605840]\n\t(No symbol) [0x0025A64C]\n\t(No symbol) [0x00256638]\n\t(No symbol) [0x0025675F]\n\t(No symbol) [0x00248DB7]\n\tBaseThreadInitThunk [0x76BBFCC9+25]\n\tRtlGetAppContainerNamedObjectPath [0x77BA7C6E+286]\n\tRtlGetAppContainerNamedObjectPath [0x77BA7C3E+238]\n\t(No symbol) [0x00000000]\n"}} | headers=HTTPHeaderDict({'Content-Length': '858', 'Content-Type': 'application/json; charset=utf-8', 'cache-control': 'no-cache'})
Finished Request

InvalidArgumentException Traceback (most recent call last)
Cell In[6], line 16
13 dalle = Dalle(cookie)
15 # Open the website with your query
---> 16 dalle.create(
17 "Fish hivemind swarm in light blue avatar anime in zen garden pond concept art anime art, happy fish, anime scenery"
18 )
20 # Get the image URLs
21 urls = dalle.get_urls()

File C:\Anaconda\envs\Dalle\Lib\site-packages\dalle3\dalle.py:111, in Dalle.create(self, query)
108 self.driver.get(f"https://www.bing.com/images/create?q={query}")
109 logging.info(f"{self.get_time()} Bing Image Creator (Dalle-3) Opened")
--> 111 self.driver.add_cookie(cookie)
112 self.driver.refresh()
113 logging.info(f"{self.get_time()} Cookie values added ")

File C:\Anaconda\envs\Dalle\Lib\site-packages\selenium\webdriver\remote\webdriver.py:633, in WebDriver.add_cookie(self, cookie_dict)
631 self.execute(Command.ADD_COOKIE, {"cookie": cookie_dict})
632 else:
--> 633 self.execute(Command.ADD_COOKIE, {"cookie": cookie_dict})

File C:\Anaconda\envs\Dalle\Lib\site-packages\selenium\webdriver\remote\webdriver.py:344, in WebDriver.execute(self, driver_command, params)
342 response = self.command_executor.execute(driver_command, params)
343 if response:
--> 344 self.error_handler.check_response(response)
345 response["value"] = self._unwrap_value(response.get("value", None))
346 return response

File C:\Anaconda\envs\Dalle\Lib\site-packages\selenium\webdriver\remote\errorhandler.py:229, in ErrorHandler.check_response(self, response)
227 alert_text = value["alert"].get("text")
228 raise exception_class(message, screen, stacktrace, alert_text) # type: ignore[call-arg] # mypy is not smart enough here
--> 229 raise exception_class(message, screen, stacktrace)

InvalidArgumentException: Message: invalid argument: missing 'value'
(Session info: chrome=118.0.5993.89)
Stacktrace:
GetHandleVerifier [0x002C4DE3+43907]
(No symbol) [0x00250741]
(No symbol) [0x001433ED]
(No symbol) [0x001B276B]
(No symbol) [0x00192B5C]
(No symbol) [0x001A55CA]
(No symbol) [0x00192956]
(No symbol) [0x0016E17E]
(No symbol) [0x0016F32D]
GetHandleVerifier [0x00575AF9+2865305]
GetHandleVerifier [0x005BE78B+3163435]
GetHandleVerifier [0x005B8441+3138017]
GetHandleVerifier [0x0034E0F0+605840]
(No symbol) [0x0025A64C]
(No symbol) [0x00256638]
(No symbol) [0x0025675F]
(No symbol) [0x00248DB7]
BaseThreadInitThunk [0x76BBFCC9+25]
RtlGetAppContainerNamedObjectPath [0x77BA7C6E+286]
RtlGetAppContainerNamedObjectPath [0x77BA7C3E+238]
(No symbol) [0x00000000]

cannot import name 'load_tool' from 'transformers' [BUG]

when running the script, to the line:
from dalle3 import Dalle
There is exception. detail as below:
Exception has occurred: ImportError
cannot import name 'load_tool' from 'transformers' (C:\Users\xx\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\transformers_init_.py)
File "C:\Users\xx\Desktop\Dalle-3.py", line 3, in
from dalle3 import Dalle
ImportError: cannot import name 'load_tool' from 'transformers' (C:\Users\xx\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\transformers_init_.py)

I always get this error: "TypeError: Binary Location Must be a String"

I have written this code after the example in this repo:

cookie = "i pasted here the _U cookie"
dalle = Dalle(cookie)
dalle.create("apple")
urls = dalle.get_urls()
dalle.download(urls, "images/")

When I run this code, I get the following error:

TypeError: Binary Location Must be a String

The problem is with the dalle = Dalle(cookie) line.

The fix for this is probably easy, but I just can't figure it out.

TypeError

an error is constantly coming out - "TypeError: Binary Location Must be a String"

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.