2

Generate images with DALL·E 2 and Twilio SMS using ASP.NET Core

 1 year ago
source link: https://www.twilio.com/blog/generate-images-with-dall-e-2-and-twilio-sms-using-aspnet-core
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Generate images with DALL·E 2 and Twilio SMS using ASP.NET Core

Generate images with DALL·E 2 and Twilio SMS using ASP.NET Core

Recently, there has been a massive boost in AI-generated art. It came to a point that an AI-generated piece of art won a contest a few months ago. There are many art generation programs available such as OpenAI DALL·E 2, Midjourney, Stable Diffusion, etc. In this article, you will use DALL·E 2 to generate images. They recently made their system available to the general public without a waitlist and also opened their API. They also give free credits so you can follow this article for free. You can also get the final source code from my GitHub repository.

Prerequisites

You'll need the following things in this tutorial:

OpenAI and DALL·E 2

OpenAI started as a non-profit artificial intelligence research organization founded by Elon Musk and Sam Altman. Elon Musk later quit the company. Currently, it operates under OpenAI LP, a “capped-profit” company (a hybrid of profit and non-profit models).

DALL·E, is a machine learning model that uses GPT-3 to generate realistic images from a description. It was initially announced in January 2021. The latest iteration of the system, DALL·E 2, was announced in April 2022. It initially required joining a waiting list, and after you’ve been accepted, you could only generate images using their web front-end. Those limitations have now been lifted, and you can sign up and start using their API to generate images.

Overview of DALL·E 2 Front-End

When you go to the DALL·E 2 website and log in, you see an input box and a Generate button.

DALL-E 2 front-end showing an input box, Surprise me link on top of the input and a Generate button next to the input

The simplicity in the design reminds me of the Google homepage. It even has a “Surprise me” option which is similar to the “I’m feeling lucky” button.

Enter your description and press the Generate button. In a matter of seconds, you will see 4 image suggestions generated for you based on your description as shown below.

Image showing 4 images generated by DALL-E 2 based on description

You get 50 credits upon sign up but they expire after a month. After that, you get 15 free credits every month. 1 image generation costs 1 credit. You can check your credit status by clicking on your profile image on the upper right-hand corner.

Image showing the account information and remaining credits with a

If you hover over the images, you see a “...” button appear. Click on it and the “Quick Actions” menu opens.

Image showing mouse hovered over a generated image and clicked on the

Here you can download the image or generate more variations based on this. The new variations are quite similar to the original one though, as they are all based on the same description.

Image showing 4 more variations generated based on a previously generated image.

You can keep on generating variations from variations as well. Generating variations also costs 1 credit.

Overview of OpenAI Account

To be able to use the OpenAI API, you will need an API key and some credits. When you sign up, OpenAI gives you free credits. Note that this is different from the 50 credits DALL·E 2 gave.

To check your credit status, go to your account page.

You should see your usage breakdown and your credit status.

Image showing the usage and credits granted for free trial usage

You get quite a lot of credits ($18) considering 1 image generation costs $0.02. There are even cheaper options depending on the image size and generation model.

Image showing the different pricing between image models  (1024x1024 $0.02, 512x512 $0.018, 256x256 $0.016) and language models (Ada $0.0004, Babbage $0.0005, Curie $0.0020, Davinci $0.02)

You can check the pricing page for full details.

After you’ve confirmed you have free credits granted, click on API Keys on the left menu.

Here, click on the Create new secret key button.

As the prompt says, save your secret key somewhere safe as you’ll not have another chance to see it.

Image showing the current API keys. User clicked Create new secret key button and a new API key is generated and shown along with a warning to keep it safe.

Now that you’ve familiarized yourself with image generation, have your API key and credits available, move on to the next section to implement your own API to send the DALL·E 2-generated images.

Project Implementation

To be able to generate the images, you will need to receive the image description from the user via SMS. To achieve this, you will implement a web API that responds to Twilio SMS webhook requests.

Create the API by running the following commands in a terminal:


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK