AI for Dummies

Carolina Azcona
Oracle Developers
Published in
9 min readNov 18, 2022

Last week I was following an amazing tutorial by Carlos Guirado about how to generate AI avatars using OCI. After creating my images I decided to go further and develop an app to see this images around my Oracle badge

Watch the app runing here!

However, while I was doing the AI tutorial one question came to my mind…

Could someone that is not from IT follow this?

I could imagine my mother’s face reading the steps… and the answer was… NO!!

And not because she is not smart enough… but maybe these tutorials are focused on their target audience: Tech people! And they assume things that for the rest of the humans are not… so common…

As I have been working with Oracle Cloud Infrastructure for just a couple months (which is the platform we use to generate this AI) a lot of concepts were not so familiar to me either.

That is why I decided to write this article!

I will move from the complex to the simple to make sure you have some basic foundations to understand what is happening with the AI in our beloved Cloud.

Sounds interesting? Let’s start!

First of all…

WHAT THE HECK IS AI?

Artificial intelligence (AI) is the simulation of human intelligence processes by machines, especially computers systems. Often what they refer to as AI is simply one component of AI, such as Machine Learning.

In general, AI systems work by ingesting large amounts of labeled training data, analyzing the data for correlations and patterns, and using these patterns to make predictions about future states.

AI can help us solve many problems, but in this case we will focus on its ability to generate images. AI-generated images can be used for a variety of purposes, such as creating realistic 3D images (for metaverse purposes) or generating images from scratch.

Models like Stable diffusion create this images. Following the tutorial you can generate images as cool as this ones…(me as Wonder Woman, as a character of game of thrones, as cyberpunk…)

One of my favourites is this one created by Google’s AI image model, Imagen

Imagen works by taking a natural language text input, in this example, ‘The Toronto skyline with Google brain logo written in fireworks’, and then using an encoder to turn that input text into embeddings. A ‘conditional diffusion model’ then maps the text embedding into a small 64x64 image. Imagen uses text-conditional super-resolution diffusion models to upsample the 64x64 image into a 256x256 and 1024x1024.

The steps

We will be following the tutorial and I will be guiding you in each step of the configuration.

Four steps that might appear simple but can be really tricky if you are not used to work with these environments.

1. You generate this AI in OCI… But what is OCI?

Oracle Cloud Infrastructure (OCI) is a platform of cloud services that enable you to build and run a wide range of applications in a highly-available, consistently high-performance environment.

To sign in:

https://www.oracle.com/cloud/sign-in.html

This is the aspect of the console:

OCI Sign in

To start the configuration we have to authenticate against our tenant and install our OCI-CLI.

But what is OCI-CLI?

The CLI is a small-footprint tool that you can use on its own or with the console to complete Oracle Cloud Infrastructure tasks. The CLI provides the same core functionality as the Console, plus additional commands. Some of these, such as the ability to run scripts, extend Console functionality.

*To install the OCI-CLI in Windows you have to open the PowerShell console using the Run as administrator option.

But what is PowerShell?

PowerShell is a cross-platform task automation solution made up of a command-line shell, a scripting language, and a configuration management framework. PowerShell runs on Windows, Linux, and macOS.

You can find it in the Windows menu, type Windows Power Shell. However, the trick here is to select the option “Run as administrator”.

After that a new window will appear and you just have to write the commands that appear in the Windows section of this article:

It will look like this…

Windows Power Shell

Now you just need to create an API key for your user.

An application programming interface (API) key is a unique identifier used to authenticate a user, developer, or calling program to an API. However, they are typically used to authenticate a project with the API rather than a human user.

The steps are explained in this article of Carlos Guirado, so you just need to follow them

Congratulations! You did the first part!

Now let’s make some more configurations and everything will be ready soon…

2. The repository…

But what is a repository??

Some people call it GitHub… Others call it GOD.

GitHub is a code hosting platform for version control and collaboration. It lets you and others work together on projects from anywhere.

Version control is a way of keeping track of all your changes to a document or folder. It basically allows you to create points in history for any change that you have made to a file, and go back to that identical version of the file at any point in the future.

Basically, if you are a programmer and you want to keep your mental health you have to use it.

In Github a repository contains all of your project’s files and each file’s revision history. You can discuss and manage your project’s work within the repository.

We are going to use the repository @carlgira for the project

And now we are going to install Git for Windows https://gitforwindows.org/

The installation let us use Git Bash, a BASH emulation used to run Git from the command line.

Basics commands you need to know….

cd <path>

The cd command, also known as chdir (change directory), is used to change the current working directory

ls

ls is a command to list computer files and directories in Unix and Unix-like operating systems. Using it you can see what there is inside this directory.

If you just tip cd, you come back to the root directory.

Now we go to Github and in the repository we select Code and we copy the first URL that appears

We open Git Bash and execute this command

git clone https://github.com/carlgira/oci-generative-ai.git

Our bash should look like this…

Et voilá!

Now we have a local copy of the Github repository!

3. Variables

The next step is to include 3 variables into our path.

This variables are crucial because it is how OCI knows who we are and where we want to put our resources in the cloud.

THE TENANCY OCID

A tenancy is a secure and isolated partition of Oracle Cloud Infrastructure to create, organize, and administer your cloud resources. This could include compute instances, networks, storage, databases, identity, analytics and more.

You can think of the tenancy as being synonymous with a company or organization

If you go to Profile (Upper Right) and select Tenancy, you can see your tenancy OCID.

You just need to copy that OCID and write in Git Bash this command

export TF_VAR_tenancy_ocid='<tenancy-ocid>'

You should change <tenancy-ocid> for your own OCID.

THE COMPARTMENT OCID

A compartment is a collection of related resources (such as cloud networks, compute instances, or block volumes) that can be accessed only by those groups that have been given permission by an administrator in your organization.

If you tip Compartments this window will appear

Then you just need to write the command in GitBash with your own OCID.


export TF_VAR_compartment_ocid='<comparment-ocid>'

THE REGION IDENTIFIER

A region is a localized geographic area.

You can easily see in the Console in which region you are.

For instance, I am working in Frankfurt region so my identifier is eu-frankfurt-1.

export TF_VAR_region='<home-region>'

Congratulations! We have almost finished…

4. Execute the script generate-keys.sh

Now we need to execute the script generate-keys.sh to generate private key to access the instance.

Compute Instance is a Linux/Windows machine created on the cloud with a shape that we can use to deploy various services depending on application requirements. Compute machines have OCPUs, memory, storage, and boot volume attach to it which defines the shape of an instance.

In this tutorial with the terraform script we launch 3 applications: stable-diffusion, bloom and dreambooth in compute instance using a nvidia GPU in OCI.

The command you have to write in Git Bash is:

sh generate-keys.sh

Your bash should look like this

Greetings! We are finished with all the Configuration stuff!

Now we are going to see how to build it! It is almost done…

BUILD

Terraform is an infrastructure as code tool that lets you build, change, and version infrastructure safely and efficiently. This includes low-level components like compute instances, storage, and networking; and high-level components like DNS entries and SaaS features.

To install it in Windows you just need to follow this steps

And then just write these three commands in your bash

terraform init
terraform plan
terraform apply

To test the app it’s necessary to create a ssh tunel to the port 7860 (stable-diffusion-webui), 5000 (bloom) and 3000 (dreambooth).

The output of the terraform script will give the ssh full command so you only need to copy and paste from GitBash.

ssh -i server.key -L 7860:localhost:7860 -L 5000:localhost:5000 -L 3000:localhost:3000 ubuntu@<instance-public-ip>

And… THE END!

If you did everything properly you should see a compute instance like this in your Instances.

Now you just have to enjoy!

Follow the Post Configuration part and enjoy playing with the AI!!!!!

Then, I developed my Augmented Reality app using Unity and Vuforia… but that is another Story…

If you want to know more, stay tunned. I will be publishing more about AI and AR soon!!

--

--

Carolina Azcona
Oracle Developers

Telecommunications engineer and Oracle Cloud Infrastructure Professional Architecht. Eager to learn and contribute here!