Create Aitana Lopez with Stable Diffusion XL Running on the AWS Cloud

AI-generated models like Aitana Lopez have been making the headlines recently [1] and have quite a following on Instagram [2]. In this tutorial, we will recreate Aitana using the Stable Diffusion XL model, a UI called Fooocus and we will run everything on the capable AWS infrastructure which is optimized for such use-cases.

Valentin Despa
Valentine about AI
6 min readDec 21, 2023

--

Why run AI models on AWS?

Popular YouTuber Jeff Delaney (Fireship) has already provided a blueprint for achieving this [3], but if you don’t have the hardware to run this AI image generation model locally, it is best to jump ship (pun intended) and take your business to the cloud.

There is no secret that these models will overwhelm your CPU/GPU and that anything you do will be extremely sluggish. Yes, you will save a few bucks but you will likely waste a lot of time trying to get this to run locally.

TLDR for AWS experts

If you already know what you are doing, here are the exact steps you need to do:

  1. Start a new instance using a Deep Learning AMI from AWS (example ami-0e2a8e53cc348e22b — Deep Learning OSS Nvidia Driver AMI GPU PyTorch 2.0.1 (Amazon Linux 2) 20231214) and a G4 instance type that has the Nvidia GPU (search for g4nd).
  2. SSH into the instance and run these commands:
git clone https://github.com/lllyasviel/Fooocus.git
cd Fooocus
python3 -m venv fooocus_env
source fooocus_env/bin/activate
pip install -r requirements_versions.txt
python entry_with_update.py --share

3. Configure authentication by creating the auth.json file and changing the default credentials.

cp auth-example.json auth.json

3. Once the app has been started successfully, open the public URL mentioned in the logs, which is something like https://abcdef123456789.gradio.live and log in.

4. Use the following prompt to generate an image that resembles Aitana Lopez:

Adult female, full body, realistic, 35 years old, Spanish descent, Instagram yoga pose, wearing tank top, yoga pants, barefoot, bright neon pink hair, long, slightly curly, messy style, thin long face, V-shaped face, extremely slender build, small mole on left side of neck, skin imperfections, dark very thin eyebrows, one eyebrow raised, head tilted to the right, suspicious expression, dark brown eyes, medium breasts, no makeup.

5. Don’t forget to terminate the AWS instance once you don’t need it anymore.

Not happy with the results? See the more detailed steps below.

1. Creating the EC2 instance

Create a new EC2 instance with the following characteristics:

  • AMI: Search for “deep learning” and choose a Deep Learning AMI from AWS. I am using Deep Learning OSS Nvidia Driver AMI GPU PyTorch 2.0.1 (Amazon Linux 2). This image has all the tools and drivers we need.
  • Instance type: I recommend using a G4 instance type with an Nvidia GPU (search for g4nd). I am using g4dn.2xlarge and the generation speed is about 1.30s/it.
  • Storage: 45 GB should be enough for this example but consider increasing the size if you plan to download more models later on.

2. Installing Fooocus

The next step is to install Fooocus, which is a tool based on Gradio which provides the UI needed to interact with the Stable Diffusion XL model and is optimized for image generation.

Open a terminal window and connect to the EC2 instance. I will use the AWSCloudShell.

Clone the Fooocus Git repository:

git clone https://github.com/lllyasviel/Fooocus.git

Enter the Fooocus directory, create a Python virtual environment, activate it, and install all project dependencies:

cd Fooocus
python3 -m venv fooocus_env
source fooocus_env/bin/activate
pip install -r requirements_versions.txt

It may take a few minutes to install all dependencies but in the end, no errors should appear:

Download the epiCPhotoGasm checkpoint which helps create better images.

wget -P models/checkpoints/ https://civitai.com/api/download/models/223670 --content-disposition

Next, while still being within the Python virtual environment, start Fooocus:

python entry_with_update.py --share

Initially, the base model needs to be downloaded, but the AWS infrastructure is quite fast and the 6GB will be downloaded in seconds. The base model used by Fooocus is Juggernaut XL (an SDXL model).

This will start a server locally but use Gradio as a proxy. Here is what they say about this: “Although the link is served through the Gradio Share Servers, these servers are only a proxy for your local server, and do not store any data sent through your app.” [5]

The address is visible in the logs printed in the console.

Once you open the URL, the UI should look like this:

No, nothing is broken, it is really so minimalistic.

3. Setting a password for the Fooocus UI (Gradio)

Since Fooocus is now available to anyone knowing (or guessing) this address, let’s make a few security changes.

Stop the running process with Ctrl +C and configure authentication by creating the auth.json file:

cp auth-example.json auth.json

Use a text editor like Vim to open the auth.json file and change the default values for the username and password.

Restart the application and use the newly generated link:

python entry_with_update.py --share

Now you should see the login form. Use the credentials you have configured to log in.

4. Generating Aitana Lopez in Fooocus

First, click on Advanced and then go to Style and make the same selections.

From the Model tab, select the refiner epicphotogasm_lastUnicorn.safetensors .

Now go to the prompt and try the following:

Adult female, full body, realistic, 35 years old, Spanish descent, Instagram yoga pose, wearing tank top, yoga pants, barefoot, bright neon pink hair, long, slightly curly, messy style, thin long face, V-shaped face, extremely slender build, small mole on left side of neck, skin imperfections, dark very thin eyebrows, one eyebrow raised, head tilted to the right, suspicious expression, dark brown eyes, medium breasts, no makeup.

Researching & writing this article took me quite a few hours. How long does it take you to press that 👏 a few times (up to 50 times)? Thank you for supporting me!

5. Terminate

Okay, the fun is over. These GPU-intensive instances are quite expensive so once you are done playing, don’t forget to stop them. Btw, you are still paying for storage even if you stop the instance.

Troubleshooting

You have requested more vCPU capacity than your current vCPU limit of 0 allows

AWS imposes restrictions on the number and size of EC2 instances you can start. To raise these limits, a request must be filed with the AWS Support Center through a limit increase form.

RuntimeError: No CUDA GPUs are available

Ensure that the AWS instance type is g4nd which uses Nvidia GPUs and not g4ad, which uses AMD GPUs that require additional configuration.

No interface is running right now

You probably stopped or restarted the Fooocus UI. Check the logs for the URL.

Conclusion

I hope this article helped you better understand how to get a simple example running on AWS. Leave a comment in the section below if you have any questions. I would love to hear from you!

Thank you for sticking with this article until the end. If you enjoyed it, please leave a comment, share, and press that 👏 a few times (up to 50 times). It will help others discover this information, and maybe it will help someone else as well.

Follow me on Medium and YouTube if you’re interested in more content like this one.

References

[1] https://www.euronews.com/next/2023/12/02/meet-the-first-spanish-ai-model-earning-up-to-10000-per-month

[2] https://www.instagram.com/fit_aitana/

[3] https://www.youtube.com/watch?v=ky5ZB-mqZKM

[4] https://aws.amazon.com/ec2/instance-types/g4/

[5] https://www.gradio.app/guides/sharing-your-app

--

--

Valentin Despa
Valentine about AI

Software developer, educator & overlander • GitLab Hero • AWS Community Builder • Postman Supernova • Imprint: http://vdespa.com/imprint