Even though you can use this CLI to generate some cool fun images and show off in front of your friends and colleagues, but this is mostly an example to show one of the many potentials in using OpenAI and integrating with it!
Using this command, you can easily generate unique cool images in a few seconds and share them on Slack, Twitter, or any other social media! 😎
- Download an install Go locally
- Alternatively you can install and use Docker if you are not willing to install Go locally
- Sign up for OpenAI
- Create an API key
- Clone the repo
- Create a file named
token
inside thesecrets
directory
touch ./secrets/token
- Paste the value of your API key in the
token
file - Alternatively, you can set the
OPENAI_API_KEY
environment variable with the value of your API key.
- Run the command
# Example:
go run main.go -p "Dancing cat singing in a digital ocean" -s "1024x1024"
- Click on the link provided in the output and see your generated image!
- Run the command
# Example:
docker run -it --rm -v $(pwd):/app -w /app golang:1.16 go run main.go -p "Dancing cat singing in a digital ocean" -s "1024x1024"
You can even build the project and create an alias on your laptop to call this command from anywhere in your terminal!
# 1. Build the project (run it while you are in this path)
go build -o open-ai-image-generate
# 2.1. You can create an alias like this (if you prefer not to build the project)
alias 'open_ai_generate_image=docker run -it --rm -v /path/to/cloned/repo:/app -w /app golang:1.16 go run main.go'
# 2.2. You can create an alias like this (if you have also built the project)
alias 'open_ai_generate_image=/path/to/cloned/repo/open_ai_generate_image'
# 3. Then you can run it like this
open_ai_generate_image -p "Dancing cat singing in a digital ocean" -s "1024x1024"
Alternatively, you can simply either copy the executable to your /usr/local/bin or /usr/bin or anywhere else
defined in your $PATH
and call it from anywhere in your terminal, or you can add the project's directory
to your $PATH
.
Also, alternatively, you can run go install
to install the project in your $GOPATH
and call it from anywhere.
If you do this, remember to:
- Add your
$GOPATH
to your$PATH
if you haven't already. - Set the
OPENAI_API_KEY
environment variable with the value of your API key.
-p
or--prompt
is the prompt that tells OpenAI what image to generate-s
or--size
is the size of the image to generate
Based on the OpenAI's documentation:
- Prompt should be less than 1000 characters.
- Size must be one of these values:
256x256
,512x512
, or1024x1024
- Please do not use inappropriate words in the prompt.
- This program is not intended to be used by children.
- Never share any of your API keys with anyone or commit them even to your private repos!
This project is licensed under the MIT License - see the LICENSE.md file for details.