OpenAI (DALL-E) inside Grasshopper with Python
Recently many Architects and Designers have been exploring different AI platforms — This is exciting!
Thanks to Open AI API documentation for DALL-E is it possible to integrate into Grasshopper our “prompts to image” process throughout my component “LA_OpenAI-GH” (I am going to update it in my Ambrosinus-Toolkit soon!) — WIP.
Useful premises
- I recommend reading this page as could be useful to understand how DALL-E works;
- Install a Python distro (I installed Anaconda for instance — or a classic Python distro)
- Install the “openai” library using the pip protocol via the windows command prompt (cmd.exe)
- Super important! install the exceptional GH_CPYTHON component by MahmoudAbdelRahman (the Python with a black icon) — This is necessary because of importing the openai library and some others to run my ghuser component,
Then…
Generate a personal API key from your beta.openai.com account and save it in your window environment variables with this name: “OPENAI_API_KEY”
Each creation will take a small amount of your trial-granted credit (at the time I took the last screenshot I have generated more or less 100 images).
Don’t share your API key.
Below is the new component in action:
- Now you can save your Open AI API key in the environment variables of Windows O.S. or give it as input as shown above (my demo key has been deleted this is just a demonstration ;) ) — After you have saved your API key into the environment variables of Windows, restart your Rhino for letting the component reads the key. If you don’t connect anything in the “APIkey” input, the components will read the key stored in your Windows O.S.;
- When the toggle is in the “False state” the component read only the PNG files inside “Path” directory;
- The component generates for each prompt a text file (.txt) where you can read the prompt that has generated a specific image See image below);
A video demo here below
For extra info about downloading have a look at the bottom of this page