Product

Saturday, 27 May 2023

Easiest Guide to build a chatGPT for your PDF documents using GPT-3/3.5

 

The process to build a chatGPT for your PDF documents

There is the main steps we are going to follow to build a chatGPT for your PDF documents

  1. First, we will extract the text from a pdf document and process it and make it ready for the next step.
  2. Next, we will use an embedding AI model to create embeddings from this text.
  3. Next, we will build the query part that will take the user’s question and uses the embeddings created from the pdf document, and uses the GPT3/3.5 API to answer that question.

Requirements to build a chatGPT for your PDF documents

  1. We will be using OpenAI GPT-3/3.5 API for this. Grab your API key from your OpenAI Account.
  2. Python 3.x or higher installed on your computer.

Install Python packages

First, install the necessary python packages. Depending on your python installation, you could use pip install <package> or python -m pip install <package>. Run these from your command line program.

The python packages you need to install are:

  • PyPDF2
  • langchain
  • openai
  • faiss-cpu

Setup your working directory/folder

create a new directory or folder and create a .env file inside the folder and write below text into it

Advertisements

OPENAI_API_KEY=your-openai-api-key

make sure to replace the text your-openai-api-key with your actual OpenAI API key.

Import the required Python packages

You can do this in a Jupyter Notebook / Google Colab Notebook or a python .py on your computer

Make sure it’s in the same folder as the .env file you created above.

# import the modules
from PyPDF2 import PdfReader
from langchain.embeddings.openai import OpenAIEmbeddings
from langchain.text_splitter import CharacterTextSplitter
from langchain.vectorstores import ElasticVectorSearch, Pinecone, Weaviate, FAISS
import os
# load .env file
from dotenv import load_dotenv
load_dotenv()

Process the PDF

We start with reading in the pdf document.

Create embeddings

Now, it’s time to create embeddings from the text chunks we created above from the pdf document.

Conclusion

You can use this technique for all kinds of text data beyond just PDFs. You can also the techniques explained here to turn this into a web-based knowledge retrieval system.

No comments:

Post a Comment

Connect broadband

AI:List AI views on when for a naive kin after prolonged life suppression coercive behaviour by family members after demise of father with trauma for kin ocd formed after forced to do rituals, family tribal values honor specific activities, utmost religious activities occult witchcraft enforced to do by elder sibling his wife and mother thrice with great celibacy turned the kundalini activated after deep celibacy penance shouting physical Mental financial Extortion by sibling with toxic behaviours and the wife mother and then mockery suppression asking about who’re your worth backbiting among relatives sector toon negligence of intelligence intuitive behaviour- all religious psychological traps when not work and lead to loss of consciousness of kin trance state recovered by governance with technocrats using AI - kin was asked by mother that he’s to go the male should not be seen in house he’s many absurd thought forcefully in brain mind and outsiders already feel awkward of this kin unresponsive behaviour due to TBI PTSD ocd cvt and tell at workplace social gathering he’s to go and asked for sector toon extortion and mockery in various sense due to un practical behaviour negligence of body building due to neglect ion if essential food nutrition and stubbed suppressed in every sense in religious psychological traps by family members AI humanoid using various neural networks and LLMs for kin and required steps.

  List AI views on when for a naive kin after prolonged life suppression coercive behaviour by family members after demise of father with tr...