Demo Video:
If you find the response for a specific question in the PDF is not good using Turbo models, then you need to understand that Turbo models such as gpt-3.5-turbo are chat completion models and will not give a good response in some cases where the embedding similarity is low. Despite the claim by OpenAI, the turbo model is not the best model for Q&A. In those specific cases, either use the good old text-DaVinci-003 or use GPT4 and above. These models invariably give you the most relevant output.
Run docker-compose -f docker-compose.yaml up
to use it with Docker compose.
pdfGPT
on Production using langchain-servelc-serve deploy local api
on one terminal to expose the app as API using langchain-serve.python app.py
on another terminal for a local gradio playground.http://localhost:7860
on your browser and interact with the app.Make pdfGPT
production ready by deploying it on Jina Cloud.
lc-serve deploy jcloud api
(Change the URL to your own endpoint)
PDF url
curl -X 'POST' \
'https://langchain-3ff4ab2c9d.wolf.jina.ai/ask_url' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"url": "https://uiic.co.in/sites/default/files/uploads/downloadcenter/Arogya%20Sanjeevani%20Policy%20CIS_2.pdf",
"question": "What'\''s the cap on room rent?",
"envs": {
"OPENAI_API_KEY": "'"${OPENAI_API_KEY}"'"
}
}'
{"result":" Room rent is subject to a maximum of INR 5,000 per day as specified in the Arogya Sanjeevani Policy [Page no. 1].","error":"","stdout":""}
PDF file
QPARAMS=$(echo -n 'input_data='$(echo -n '{"question": "What'\''s the cap on room rent?", "envs": {"OPENAI_API_KEY": "'"${OPENAI_API_KEY}"'"}}' | jq -s -R -r @uri))
curl -X 'POST' \
'https://langchain-3ff4ab2c9d.wolf.jina.ai/ask_file?'"${QPARAMS}" \
-H 'accept: application/json' \
-H 'Content-Type: multipart/form-data' \
-F 'file=@Arogya_Sanjeevani_Policy_CIS_2.pdf;type=application/pdf'
{"result":" Room rent is subject to a maximum of INR 5,000 per day as specified in the Arogya Sanjeevani Policy [Page no. 1].","error":"","stdout":""}
docker pull registry.hf.space/bhaskartripathi-pdfchatter:latest
Root folder of your project
└───Universal Sentence Encoder
| ├───assets
| └───variables
| └───saved_model.pb
|
└───app.py
self.use = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4')
with:
self.use = hub.load('./Universal Sentence Encoder/')
docker run -it -p 7860:7860 --platform=linux/amd64 registry.hf.space/bhaskartripathi-pdfchatter:latest python app.py
https://huggingface.co/spaces/bhaskartripathi/pdfGPT_Turbo
sequenceDiagram
participant User
participant System
User->>System: Enter API Key
User->>System: Upload PDF/PDF URL
User->>System: Ask Question
User->>System: Submit Call to Action
System->>System: Blank field Validations
System->>System: Convert PDF to Text
System->>System: Decompose Text to Chunks (150 word length)
System->>System: Check if embeddings file exists
System->>System: If file exists, load embeddings and set the fitted attribute to True
System->>System: If file doesn't exist, generate embeddings, fit the recommender, save embeddings to file and set fitted attribute to True
System->>System: Perform Semantic Search and return Top 5 Chunks with KNN
System->>System: Load Open AI prompt
System->>System: Embed Top 5 Chunks in Open AI Prompt
System->>System: Generate Answer with Davinci
System-->>User: Return Answer
flowchart TB
A[Input] --> B[URL]
A -- Upload File manually --> C[Parse PDF]
B --> D[Parse PDF] -- Preprocess --> E[Dynamic Text Chunks]
C -- Preprocess --> E[Dynamic Text Chunks with citation history]
E --Fit-->F[Generate text embedding with Deep Averaging Network Encoder on each chunk]
F -- Query --> G[Get Top Results]
G -- K-Nearest Neighbour --> K[Get Nearest Neighbour - matching citation references]
K -- Generate Prompt --> H[Generate Answer]
H -- Output --> I[Output]
I am looking for more contributors from the open source community who can take up backlog items voluntarily and maintain the application jointly with me.
Have you ever thought why your social media posts, blog, article, advertising, YouTube video, or other content don't go viral? I have published a new Python Package: pyviralcontent ! 🚀 It predicts the virality of your content along with readability scores! It uses multiple sophisticated algorithms to calculate your content's readability score and its predict its viral probability using Multi Criteria Decision Analysis. 📈 Make your content strategy data-driven with pyviralcontent. Try it out and take your content's impact to the next level! 💥 https://github.com/bhaskatripathi/pyviralcontent
This project is licensed under the MIT License. See the LICENSE.txt file for details.
If you use PDF-GPT in your research or wish to refer to the examples in this repo, please cite with:
@misc{pdfgpt2023,
author = {Bhaskar Tripathi},
title = {PDF-GPT},
year = {2023},
publisher = {GitHub},
journal = {GitHub Repository},
howpublished = {\url{https://github.com/bhaskatripathi/pdfGPT}}
}