Prerequisites
Open the below provided Colab link
Copying Code to your Google Drive
On the top left corner of Google Colab Notebook you can find File, click on it.

Click on Save a Copy in Drive

If you are not logged in to your Google Account, please log into it.
Once you are successfully logged in a new Google Colab Notebook with the given code will be opened
Click on the Run button to Install the Packages

Click on the Run button to import the required things to build the application

Get the OpenAI API Key and set it as environmental variable
Generate API Key
Replace your Open AI API Key with your own API Key

Click on the Run button

Assigning the values for template, prompt, and memory
You can update the first line of the template provided
Click on the Run button

Initializing LLM Chain using Open AI
Using ChatOpenAI we are creating an LLMChain
Click on the Run button

Define a function to generate the response for the question you ask:
Click on the Run button

Create a ChatInterface using the Gradio
We are creating the ChatInterface from gradio and providing a function get_text_reponse and also examples
Check for other arguments here
Click on the Run button to create an interface

Launch your ChatBot with Gradio APP

Now you can try asking questions in your ChatBot
If you are getting any errors:
Keep print statements to identify the issue
To identify the error you are getting please add debug=True while launching the gradio app.
if __name__ == "__main__":
demo.launch(debug=True)
def get_text_response(user_message,history):
try:
response = llm_chain.predict(user_message = user_message)
except Exception as e:
print("Error:", e)
try:
print("Error:", e.error.message)
response = "Failed to reply: " + e.error.message
except Exception as e:
response = "Failed to reply"
return response
Login to Hugging Face from Google Colab


Create HuggingFace API to push code from Google Colab
Click on the Run button to create API

Adding Hugging Face Repo ID
Copy Hugging Face Repo ID by opening the Hugging Face Repo Created

Replace your Repo ID

Click on Run button to assign hugging Face Repo ID
