Skip to content

youngjeong46/OpenAIImageGenerator

Repository files navigation

OpenAI DALL·E Image Generator

This is a sample NodeJS application for generating images. The user is prompted to write a simple description, which the application will use to generate a corresponding image.

a cat and a dog image

The generation is provided using OpenAI's Images API and DALL·E models.

Prerequisites

To get started you will need:

  • Docker installed on your local machine.
  • Node, version v16.16 or later.
  • NPM package manager, version 8.11 or later.
  • An IDE for building the application such as Visual Studio
  • An account with OpenAI to use their API service. You can get a free account for personal use (with limited API calls).
  • An OpenAI API Key is required to access the API needed for image generation. Store it under .env file in the format provided under .env.example (assigned under OPENAI_API_KEY variable)

Running Locally (using npm)

To get started, first install dependencies:

npm i

Then, start the application:

npm run start

Running Locally (using docker build)

You can build your own Docker image as provided below. Since node provide multiarch option, we use buildx to build architectures available for node container image. You may choose to build an individual arch otherwise.

docker buildx build --push --platform linux/arm64/v8,linux/amd64 --tag {your image name}:{your tag} .

You can now run the built image using the following command:

docker run -p 3000:3000 --env-file ./.env {your image name}:{your tag}

You will then be able to access the application on your browser under the following URL: http://localhost:3000

Running Locally (using public image)

The image already exists publicly in DockerHub:

docker run -p 3000:3000 --env-file ./.env youngjeong46/chatgpt-image-generator:alpine

You will then be able to access the application on your browser under the following URL: http://localhost:3000

Running on ECS Fargate

The AWS CDK for Typescript is used to deploy the application to ECS Fargate. Follow the instructions in the README.md.

Running on Kubernetes

First, you will need to generate a Base64 encoded string of your OpenAI API key:

echo -n <your API key> | base64

Take the output and place it in the secret data inside kubernetes-manifests/apisecret.yaml.

To deploy to an existing Kubernetes cluster, run the following command to apply the manifests:

kubectl apply -f kubernetes-manifests/

The application.yaml manifest doesn't expose the service via a load balancer so in order to test do something like this:

kubectl -n chatgpt-apps port-forward svc/image-generator 3000:80 

You can access the application via http://localhost:3000.

About

Image generator using OpenAI's Images API and DALL·E models

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published