Building a website gallery with ChatGPT, Stable Diffusion, React and NodeJS š¤Æ
In this article, you'll learn how to build a web application that uses ChatGPT and Stable Diffusion to generate a logo and a befitting domain name for any website description you provide.

Intro
AI is taking over the world. The technologies are rocking our world daily: ChatGPT and Stable Diffusion.ChatGPT can answer any question in the world using its GPT3.5 model.Stable Diffusion is a text-to-image model that can convert any text into a picture.Combining both technologies is the future of AI.I will show you how to create an entire website branding by combining the two in this article.
I am really excited about this one š¤©Please click on the āLikeā button so I know you like it and you want more.
Novu ā the first open-source notification infrastructure
Just a quick background about us. Novu is the first open-sourceĀ notification infrastructure. We basically help to manage all the product notifications. It can beĀ In-AppĀ (the bell icon like you have in Facebook āĀ Websockets), Emails, SMSs and so on.

I would be super happy if you could give us a star! And let me also know in the comments ā¤ļø https://github.com/novuhq/novu
What is Stable Diffusion?
Stable DiffusionĀ is a text-to-image latent diffusion model that enables users to generate images within a few seconds based on a given text input. It is also used in processes such as in-painting, out-painting, and generating image-to-image translations.
ChatGPTĀ is also an AI language model trained byĀ OpenAIĀ to generate text and interact with users in a human-like conversational manner. Users can submit requests and get information or answers to questions from a wide range of topics such as history, science, mathematics, and current events in just a few seconds.
At the end of this article, youāll learn how to create images from text using theĀ Stable Diffusion WebUIĀ and send messages to ChatGPT from a Node.js application.
Installing and Running the Stable Diffusion Web UI
You can install Stable Diffusion Web UI onĀ Windows,Ā Linux, and Apple Silicon. Here, Iāll guide you through the installation on Apple Silicon.
Prerequisites:Ā Ensure you haveĀ HomebrewĀ installed on your computer. It is a package that enables you to install various applications not provided by Apple.
- Open a new terminal window and run the command below to install the WebUI dependencies.
MAC:
Debian-based:
Red Hat-based
Arch-based:
- Clone the web UI repository by running the below:
- We need to download the Stable Diffusion model (large file). Navigate to stable-diffusion-webui/models/Stable-diffusion
Download the model ā For our use case we will use Stable Diffusion 1.5 but feel free toĀ download any other versionĀ you want.To download use:
rename the model from v1-5-pruned-emaonly.ckpt to model.ckptmv v1-5-pruned-emaonly.ckpt model.ckpt
- Navigate into theĀ
stable-diffusion-webuiĀ folder and run the web UI project to create a virtual environment and install its dependencies.
- Visit the local URL āĀ
http://127.0.0.1:7860Ā to interact with the Web UI via its user interface. - To relaunch the web UI process later, navigate into theĀ
stable-diffusion-webuiĀ folder on your terminal and run the commandĀ./webui.sh. If you want to use the Web UI API, add the flag api flag to the commandĀ./webui.sh --api
Building the web application
In this section, Iāll guide you through creating the project environment for the web application. Weāll use React.js for the front end and Node.js for the backend server.
Create the project folder for the web application by running the code below:
Setting up the React application
Navigate into the client folder via your terminal and create a new React.js project.
Delete the redundant files, such as the logo and the test files from the React app, and update theĀ App.jsĀ file to display āHello Worldā as below.
Navigate into theĀ src/index.cssĀ file and copy the code below. It contains all the CSS required for styling this project.
Update theĀ App.jsĀ file to display an input field that allows you to enter the proposed website description.
Setting up the Node.js server
Navigate into the server folder within your terminal and create aĀ package.jsonĀ file.
Install Express, Nodemon, and the CORS library.
ExpressJSĀ is a fast, minimalist framework that provides several features for building web applications in Node.js,Ā CORSĀ is a Node.js package that allows communication between different domains, andĀ NodemonĀ is a Node.js tool that automatically restarts the server after detecting file changes.
Create anĀ index.jsĀ file ā the entry point to the web server.
Set up a Node.js server using ExpressJS. The code snippet below returns a JSON object when you visit theĀ http://localhost:4000/apiĀ in your browser.
InstallĀ Axios, theĀ unofficial ChatGPT API library, andĀ Puppeteer. The ChatGPT API uses Puppeteer as an optional peer dependency to automate bypassing the Cloudflare protections.
To use the ChatGPT API within theĀ server/index.jsĀ file, you need to configure the file to use both theĀ requireĀ andĀ importĀ keywords for importing libraries.Therefore, update theĀ server/package.jsonĀ file to contain theĀ typeĀ keyword.
Add the code snippet below at the top of theĀ server/index.jsĀ file.
Once you have completed the last two steps, you can now use ChatGPT within theĀ index.jsĀ file.
Configure Nodemon by adding the start command to the list of scripts in theĀ package.jsonĀ file. The code snippet below starts the server using Nodemon.
Congratulations! You can now start the server by using the command below.
How to communicate with ChatGPT in a Node.js application
In this section, youāll learn how to communicate with ChatGPT from the Node.js server via theĀ unofficial ChatGPT library.
The library uses a fully automated browser-based solution that enables us to scrape our way in ā meaning it performs a full browser automation that allows us to log in to the OpenAI website, solve the captcha, and send messages via the OpenAI cookies.
Youāve installed the library in the previous section; next, import the ChatGPT API library into theĀ index.jsĀ file as done below. The ChatGPT API uses Puppeteer as an optional peer dependency to automate bypassing the Cloudflare protections.
We need ChatGPT to generate a domain name for any description specified by the user and to create a prompt for the Stable Diffusion API.
Therefore, create a route on the server that accepts the description from the React app.
Create a function within the React app that sends the description to theĀ /apiĀ endpoint on the server once the user submits the form
Add a loading state within the React app that holds the request status and call the async function once the form is submitted.
Update theĀ /apiĀ endpoint to send the description to ChatGPT and generate a domain name and prompt for Stable Diffusion.
The code snippet above uses Puppeteer to launch the browser and enable you to sign in to your ChatGPT account automatically. After authentication, ChatGPT processes the requests and returns the response.
In the upcoming section, Iāll guide you on how to send the generated prompt to the Stable Diffusion API.
How to interact with the Stable Diffusion API
To interact with the Stable Diffusion API, relaunch the web UI process by running the command below:
You can view the available API endpoints atĀ http://127.0.0.1:7860/docsĀ Weāll make use of theĀ /sdapi/v1/txt2imgĀ endpoint for the text-to-image conversion.
Make a POST request to theĀ /sdapi/v1/txt2imgĀ endpoint with the generated prompt as the payload.
From the code snippet above, theĀ /sdapi/v1/txt2imgĀ endpoint accepts a required parameter called prompt ā the text description of the image to be generated.
Update theĀ /apiĀ endpoint on the Node.js server to save the result and send it to the React.js application.
Displaying the results with the React app
Update theĀ sendDescriptionĀ function to receive the response from the server.
Create a Loading component that is shown to the user whenever the request is pending.
Add the code snippet below to display the component when the request is pending.
Update the component to render the results generated as done below.
The code snippet above displays the logo and domain name generated for various requests. Congratulations!š Youāve completed the project for this tutorial.
Here is a sample of the results gotten for cocktail websites:
Conclusion
So far, youāve learnt:
- what Stable Diffusion is,
- how to install and set up Stable Diffusion on your computer
- how to send messages to ChatGPT from a Node.js application, and
- how to generate images from text via the Stable Diffusion API.
This tutorial walks you through an example of an application you can build using Stable Diffusion and ChatGPT. These AI technologies can be used to create powerful applications useful in various fields.
The source code for this tutorial is available here:
https://github.com/novuhq/blog/tree/main/webapp-with-stable-diffusion-and-chatgpt
Thank you for reading!
Help me out!
If you feel like this article helped you, I would be super happy if you could give us a star! And let me also know in the comments ā¤ļø
https://github.com/novuhq/novu

