Hi all,

ahhhh ChatGPT. Some are buzzing by its endless potential, some treat it as a glorified Google search and some are sick of hearing the word and are just waiting for the mass adoption period. Well, depending where you sit on that spectrum will probably determine whether this blog is for you.

Today we are going to look at how we can host a mini chatbot locally hosted instead of loading the standard chat.openai website. This is a beginner tutorial for those wanted to play around with writing python code. Below is what we will look to recreate.

As always  – you can access the code in the repo at the top of the page.

So what is ChatGPT?

Well, let’s ask it.

ChatGPT is a large language model created by OpenAI. ChatGPT is designed to generate human-like text and to respond to natural language inputs.

ChatGPT can be used for a variety of applications, including language translation, question-answering, text summarization, and chatbot interactions.

What does creating a front end GUI unlock in terms of potential?

Just think… all the power of chatGPT but your own personalisation as a company brand. You can start to power services / chatbots / online automation whilst including all the design flexibility of the current site architecture.

How do we go about creating it?

Well first you will need an account (obviously)

Sign up to OpenAI using your email and make a password.

When you sign up you should get $5 of credit. I think it use to be $15 but recently reduced. This is a free trial period when it comes to using the API.

We DO NOT need to add any billing to go through this tutorial. (Only if you want to go on to use additional features or run out of user credits would you need this)

You can see your credits under Usage.

Go down to user and click API Keys.

Create a new key.

You can see I’ve created a new “Test Key”

This key will be added to our code to interact with ChatGPT.

Now we have our key, let’s look at getting set up.

Open up an IDE of your choice, for me I use PyCharm.

You will need to pip install openai and gradio packages in your terminal.

Now we have the packages we can paste our code into a main.py file.

What does the code do. Well, of course we replace the word redacted with your own API key. From there you can run the code.

For reference, it creates a function using the ChatGPT 3.5 turbo.

Gradio is our package that creates the front end.

You will see that you can pass various things through it, including a title, and various inputs and outputs.

When we click run you will see the local host load.

Here is what that looks like.

In the above example it creates an input, and then to the right will have the output.

I’ve put in a draft question asking how to get more involved in the Tableau community?

If we click flag – it will log the response in a flagged folder.

You will see our input, the output response from chatGPT and the time that the query was sent.

Hopefully this sparks some creativity in your own journey.

A quick bonus, why not amend share to True

Now we can load the site url on the phone, we are no longer using a local host.

Going further:

  • Try adding in some more elements to the Gradio to improve userability
  • Why not create the interface using CSS?
  • Try hosting the content live instead of locally
  • Try making the questions unique to a specific subject content matter

LOGGING OFF,

CJ