{"id":23139507,"url":"https://github.com/ezzcodeezzlife/dalle2-in-python","last_synced_at":"2025-04-06T06:12:21.632Z","repository":{"id":37337764,"uuid":"505603919","full_name":"ezzcodeezzlife/dalle2-in-python","owner":"ezzcodeezzlife","description":"Use DALL·E 2 in Python","archived":false,"fork":false,"pushed_at":"2023-05-01T17:53:16.000Z","size":42,"stargazers_count":178,"open_issues_count":12,"forks_count":35,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-03-30T04:09:17.208Z","etag":null,"topics":["ai","api","dall","dall-e","dall-e2","dalle","dalle2","e","generation","gpt-3","gpt3","images","openai"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/dalle2/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ezzcodeezzlife.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-06-20T21:31:38.000Z","updated_at":"2025-01-18T09:35:45.000Z","dependencies_parsed_at":"2024-06-21T16:42:10.728Z","dependency_job_id":null,"html_url":"https://github.com/ezzcodeezzlife/dalle2-in-python","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ezzcodeezzlife%2Fdalle2-in-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ezzcodeezzlife%2Fdalle2-in-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ezzcodeezzlife%2Fdalle2-in-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ezzcodeezzlife%2Fdalle2-in-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ezzcodeezzlife","download_url":"https://codeload.github.com/ezzcodeezzlife/dalle2-in-python/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247441059,"owners_count":20939239,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","api","dall","dall-e","dall-e2","dalle","dalle2","e","generation","gpt-3","gpt3","images","openai"],"created_at":"2024-12-17T13:14:20.112Z","updated_at":"2025-04-06T06:12:21.614Z","avatar_url":"https://github.com/ezzcodeezzlife.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[OpenAI has a official API now](https://openai.com/blog/dall-e-api-now-available-in-public-beta/)\n\n# Installation\n```bash\npip install dalle2\n```\n\n# Usage\n## Setup\n1. Go to https://openai.com/dall-e-2/\n2. Create an \nOpenAI Account\n3. Go to https://labs.openai.com/\n4. Open the Network Tab in Developer Tools\n5. Type a prompt and press \"Generate\"\n6. Look for fetch to https://labs.openai.com/api/labs/tasks\n7. In the request header look for authorization then get the Bearer Token\n\n```python\nfrom dalle2 import Dalle2\ndalle = Dalle2(\"sess-xxxxxxxxxxxxxxxxxxxxxxxxxxxx\") # your bearer key\n```\n\n## Generate images\n```python\ngenerations = dalle.generate(\"portal to another dimension, digital art\")\nprint(generations)\n```\n\n```\n✔️ Task created with ID: task-xsuhOthvBXLEjddn3ynyiiOR\n⌛ Waiting for task to finish...\n...task not completed yet\n...task not completed yet\n...task not completed yet\n...task not completed yet\n🙌 Task completed!\n\n[\n  {\n    'id': 'generation-sCnERSYDPP0Zu14fsdXEcKmL',\n    'object': 'generation',\n    'created': 1553332711,\n    'generation_type': 'ImageGeneration',\n    'generation': {\n      'image_path': 'https://openailabsprodscus.blob.core.windows.net/private/user-hadpVzldsfs28CwvEZYMUT/generations/generation...'\n    },\n    'task_id': 'task-nERkiKsdjVCSZ50yD69qewID',\n    'prompt_id': 'prompt-2CtaLQsgUbJHHDoJQy9Lul3T',\n    'is_public': false\n  },\n  # 3 more ... \n]\n```\n\n\n## Generate images and download them\n```python\nfile_paths = dalle.generate_and_download(\"portal to another dimension, digital art\")\n```\n\n```\n✔️ Task created with ID: task-xsuhOthvBXLEjddn3ynyiiOR\n⌛ Waiting for task to finish...\n...task not completed yet\n...task not completed yet\n...task not completed yet\n...task not completed yet\n🙌 Task completed!\n✔️ Downloaded: C:\\...\\generation-XySidj4N8EN6Ok9ed15BZ2bs.webp\n✔️ Downloaded: C:\\...\\generation-IK3UdxDz77FA5SLKpQPIITdU.webp\n✔️ Downloaded: C:\\...\\generation-uNejKBXz1z6EQxJAT9pAZbof.webp\n✔️ Downloaded: C:\\...\\generation-Ol1wEqNprf34vNohmJz0iUiE.webp\n```\n\n## Generate a specific number of images\n```python\ngenerations = dalle.generate_amount(\"portal to another dimension\", 8) # Every generation has batch size 4 -\u003e amount % 4 == 0 works best\n\n# download images\nfile_paths = dalle.download(generations)\nprint(file_paths)\n```\n\n```\n✔️ Task created with ID: task-lm0V4nZasgAFasd7AsStE67\n⌛ Waiting for task to finish...\n...task not completed yet\n...task not completed yet\n...task not completed yet\n...task not completed yet\n🙌 Task completed!\n✔️ Task created with ID: task-WcetZOHt8asdvHb433gi\n⌛ Waiting for task to finish...\n...task not completed yet\n...task not completed yet\n...task not completed yet\n...task not completed yet\n🙌 Task completed!\n```\n\n## Generate images from a masked file\nDALL·E supports an \"inpainting\" API that fills-in transparent parts of an image.\nThe website provides a tool to paint over an existing image to indicate which\nparts you want to be transparent. This Python package call assumes that the\nimage you provide has already been processed to have transparent parts.\n\n```python\n# make the right half of a saved image transparent\nfrom PIL import Image, ImageDraw\n\nimage = Image.open('my_image.png')\nm, n = image.size\n\narea_to_keep = (0, 0, m//2, n)\nimage_alpha = Image.new(\"L\", image.size, 0)\ndraw = ImageDraw.Draw(image_alpha)\ndraw.rectangle(area_to_keep, fill=255)\n\nimage_rgba = image.copy()\nimage_rgba.putalpha(image_alpha)\nimage_rgba = image_rgba.resize((1024, 1024)) # image must be square and 1024x1024\nimage_rgba.save('image_with_transparent_right_half.png')\n\n# ask DALL·E to fill-in the transparent right half\ngenerations = dalle.generate_from_masked_image(\n    \"portal to another dimension, digital art\",\n    \"image_with_transparent_right_half.png\",\n)\n```\n\n```\n✔️ Task created with ID: task-xsuhOthvBXLEjddn3ynyiiOR\n⌛ Waiting for task to finish...\n...task not completed yet\n...task not completed yet\n...task not completed yet\n...task not completed yet\n...task not completed yet\n🙌 Task completed!\n```\n\n# Other languages\n\n[Nodejs Package](https://github.com/ezzcodeezzlife/dalle-node)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fezzcodeezzlife%2Fdalle2-in-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fezzcodeezzlife%2Fdalle2-in-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fezzcodeezzlife%2Fdalle2-in-python/lists"}