Live version: https://img-gen.kelvintam.dev/
React Native port w/ Android APK available: https://github.com/kelvinthh/Image-Generation-RN
This Next.js single-page web app allows users to generate images based on text prompts, utilizing OpenAI's DALL-E and ChatGPT APIs. The app is built using the powerful Next.js framework and styled with the popular Tailwind CSS utility-first CSS framework. It features serverless API backends powered by Microsoft Azure Function App with HTTP triggers and a Storage Account for saving generated images in a blob container. Deployed on Azure (for the HTTP triggers) and Vercel (for the front-end), this app offers a seamless and modern user experience.
- Generate images from text prompts using OpenAI's DALL-E
- Receive prompt suggestions from OpenAI's ChatGPT
- Serverless API backends with Microsoft Azure Function App HTTP triggers
- Image storage using Microsoft Azure Storage Account (blob container)
- Deployed on Azure (back-end) and Vercel (front-end)
To clone and run this project, you'll need the following:
- An OpenAI account with API key for DALL-E and ChatGPT access
- A Microsoft Azure account for Function App and Storage Account setup
- Your local environment file (.env) configured with the required API keys and credentials
- Azure Tools extentions for Visual Studio Code
-
Clone this repository:
git clone https://github.com/kelvinthh/Image-Generaton-Next.js.git
-
Install dependencies:
npm install
-
Make sure you created your Function App and Storage account for this project on Azure. In your Azure Storage account, create a blob container called
images
. Map your Function App & Storage Account to the project'sazure
folder under the root folder. -
Configure your local environment file (.env.local) with the required API keys and credentials:
# .env.local
OPEN_AI_ORG=org-your_open_ai_account
OPEN_AI_API_KEY=your_open_ai_key
# Azure remote house, uncomment one below:
# REMOTE_HOST=your_azure_remote_host_url (For deployment)
# REMOTE_HOST=http://127.0.0.1:7071 (Dev server only)
# IMG_GEN_URL=https://yourdomain.com (Leave blank if none)
# IMG_GEN_DOMAIN=yourdomain.com (Leave blank if none)
# DEV_PREVIEW_URL=devpreview.yourvercelurl.com (Leave blank if none)
# OG_IMAGE=https://youropengraphimage.png
# // API endpoint e.g. /api/getImages
API_GENERATE_IMAGE=your_generateImage_api_endpoint
API_GET_IMAGES=your_getImages_api_endpoint
API_GET_SUGGESTIONS=your_getChatGPTSuggestion_api_endpoint
# // Google Analytics Measurement ID
GA_ID=
If you need to find your Storage account access key: Go to Azure Portal > Your Storage account > Security + networking > Access key.
-
Install dependencies inside the Azure folder
cd azure && npm install
-
In VSCode click
Windows: Control + P / Mac: Command + P
and typeAzure Functions: Download Remote Settings...
-
Add the lines
OPEN_AI_ORG
&OPEN_AI_API_KEY
from your project.env
file toazure
'slocal.settings.json
-
Run the local Azure development server
cd azure && npm run start
, then it should run athttp://localhost:7071
. Unless your Azure backend is deployed, make sure to use sethttp://127.0.0.1:7071
as the value for env variableREMOTE_HOST
. -
Run the development server from the project's root directory:
npm run dev
-
Open your browser and navigate to http://localhost:3000 to see the app running.
To deploy the front-end on Vercel, follow these steps:
- Sign up or log in to your Vercel account.
- Connect your GitHub account and import the repository.
- Deploy your project with terminal command
vercel
. - Configure your environment variables in the Vercel dashboard, matching the local .env file.
To deploy the back-end on Azure Functions, follow these steps:
- Sign up or log in to your Microsoft Azure account.
- Create a new Function App and configure it with your preferred runtime, operating system, and hosting plan.
- Deploy your Function App using your preferred method (e.g., Git, Visual Studio Code, Azure Functions Core Tools).
- Configure the required environment variables in the Function App's "Application settings" to match your local .env file.
- Deploy your Function App using VSCode command line and use
Azure Functions: Deploy to Function App...
This project was inspired by following the tutorial Build an AI Image Generator App using Next.js and OpenAI DALL-E by Sonny Sangha. While the tutorial served as an excellent starting point, it is important to note that the code in this project was not directly copied and pasted. Instead, it was adapted and customized to better suit the needs and requirements of this specific implementation. We would like to express our gratitude to Sonny Sangha for sharing his knowledge and providing valuable guidance throughout the development process.