I used ChatGPT to create an AI application on AWS

Tram Ho

This new language model can be your future programmer

ChatGPT a new language model is an improved version of GPT-3, and possibly, gives us a glimpse of what GPT-4 will be capable of when it’s released early next year (as outlined above). rumor). With ChatGPT it is possible to have an actual conversation with the model, referencing earlier points in the conversation.

I want to try it out if I can use this model as a fellow programmer that I can give some guidance and it generates the code for me. Of course, I’ll still test those pieces of code again, but at least I won’t have to write them from scratch.

So, in this post, I describe how I used ChatGPT to create a simple sentiment analysis app from scratch. The application will run on an EC2 instance and use the modern NLP model from the Hugging Face Model Hub. The results are amazing

I had to try and tweak the prompt a few times to get the results I wanted. That being said, it usually only takes small tweaks to get the desired results. My prompts and the code generated by the model can be found in this GitHub repo !

Let’s start!

First check if Chatgpt is available: image.png

Let’s dive into the details, at the request of this companion!

Create a CloudFormation Template for an EC2 instance

We want to run this application on an EC2 instance, but we don’t want to click through the AWS console to create this EC2 instance. Thus, our first task for ChatGPT is to create a CloudFormation template that sets up an EC2 instance: image.png

image.png

The instructions are pretty specific (I had to look up the AMI ID myself, for example), but I was still quite surprised when it came up with a near-perfect CF sample. Note that ChatGPT also puts some disclaimer at the end of the code! Full code generated by Chatgpt:

Note that the EC2 instance is actually not getting the name we specified in the prompt. Another “error” in this sample is that the preinstalled pytorch environment on the AMI is called “pytorch” not “pytorch_36”. Let’s fix it by replacing the environment name.

image.png

Ok, running this line started the Stack creation using the CF template. After a few minutes, we see the EC2 instance in action. Note that the template created a security group and the EC2 instance uses that security group as specified: image.png

SSH into the EC2 instance to see if the packages we need are installed image.png Looks like everything is set up for the Streamlit app 😊

Streamlit app

Now we need an application that runs on Streamlit and analyzes the sentiment of the text. To my surprise, this was even easier than I expected:

image.png

image.png

Again, nice disclaimer at the end. Entire code:

This looks really good to me, let’s try to run this without modification. Copy and paste this code into a file on EC2 called ‘ app.py ‘. But how to run Streamlit application again? Ask my ‘colleague’: image.png

I have Streamlit installed, so go ahead and run ‘streamlit run app.py ‘: image.png Looks good!

Conclusion

This has been very exciting and the possibilities are endless. I will try to experiment more with this model in the future!

References

https://towardsdatascience.com/i-used-chatgpt-to-create-an-entire-ai-application-on-aws-5b90e34c3d50

Share the news now

Source : Viblo