pdfGPT

pdfGPT

基于GPT的PDF智能问答工具 提高文档阅读效率

pdfGPT是一个开源的PDF文档智能问答工具。它采用文本分割和深度平均网络编码技术,实现PDF内容的语义搜索。通过整合OpenAI功能,pdfGPT生成精确答案并提供页码引用。系统兼容多种模型如GPT-4,同时提供友好界面和API。这一工具显著提高了PDF文档的信息获取效率,适用于研究、学习等多种场景。

pdfGPTPDF处理OpenAI语义搜索嵌入Github开源项目

pdfGPT

Demo

  1. Demo URL: https://bhaskartripathi-pdfgpt-turbo.hf.space

  2. Demo Video:

    IMAGE ALT TEXT HERE

Version Updates (27 July, 2023):

  1. Improved error handling
  2. PDF GPT now supports Turbo models and GPT4 including 16K and 32K token model.
  3. Pre-defined questions for auto-filling the input.
  4. Implemented Chat History feature. image

Note on model performance

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.

Upcoming Release Pipeline:

  1. Support for Falcon, Vicuna, Meta Llama
  2. OCR Support
  3. Multiple PDF file support
  4. OCR Support
  5. Node.Js based Web Application - With no trial, no API fees. 100% Open source.

Problem Description :

  1. When you pass a large text to Open AI, it suffers from a 4K token limit. It cannot take an entire pdf file as an input
  2. Open AI sometimes becomes overtly chatty and returns irrelevant response not directly related to your query. This is because Open AI uses poor embeddings.
  3. ChatGPT cannot directly talk to external data. Some solutions use Langchain but it is token hungry if not implemented correctly.
  4. There are a number of solutions like https://www.chatpdf.com, https://www.bespacific.com/chat-with-any-pdf, https://www.filechat.io they have poor content quality and are prone to hallucination problem. One good way to avoid hallucinations and improve truthfulness is to use improved embeddings. To solve this problem, I propose to improve embeddings with Universal Sentence Encoder family of algorithms (Read more here: https://tfhub.dev/google/collections/universal-sentence-encoder/1).

Solution: What is PDF GPT ?

  1. PDF GPT allows you to chat with an uploaded PDF file using GPT functionalities.
  2. The application intelligently breaks the document into smaller chunks and employs a powerful Deep Averaging Network Encoder to generate embeddings.
  3. A semantic search is first performed on your pdf content and the most relevant embeddings are passed to the Open AI.
  4. A custom logic generates precise responses. The returned response can even cite the page number in square brackets([]) where the information is located, adding credibility to the responses and helping to locate pertinent information quickly. The Responses are much better than the naive responses by Open AI.
  5. Andrej Karpathy mentioned in this post that KNN algorithm is most appropriate for similar problems: https://twitter.com/karpathy/status/1647025230546886658
  6. Enables APIs on Production using langchain-serve.

Docker

Run docker-compose -f docker-compose.yaml up to use it with Docker compose.

Use pdfGPT on Production using langchain-serve

Local playground

  1. Run lc-serve deploy local api on one terminal to expose the app as API using langchain-serve.
  2. Run python app.py on another terminal for a local gradio playground.
  3. Open http://localhost:7860 on your browser and interact with the app.

Cloud deployment

Make pdfGPT production ready by deploying it on Jina Cloud.

lc-serve deploy jcloud api

<details> <summary>Show command output</summary>
╭──────────────┬──────────────────────────────────────────────────────────────────────────────────────╮ │ App ID │ langchain-3ff4ab2c9d │ ├──────────────┼──────────────────────────────────────────────────────────────────────────────────────┤ │ Phase │ Serving │ ├──────────────┼──────────────────────────────────────────────────────────────────────────────────────┤ │ Endpoint │ https://langchain-3ff4ab2c9d.wolf.jina.ai │ ├──────────────┼──────────────────────────────────────────────────────────────────────────────────────┤ │ App logs │ dashboards.wolf.jina.ai │ ├──────────────┼──────────────────────────────────────────────────────────────────────────────────────┤ │ Swagger UI │ https://langchain-3ff4ab2c9d.wolf.jina.ai/docs │ ├──────────────┼──────────────────────────────────────────────────────────────────────────────────────┤ │ OpenAPI JSON │ https://langchain-3ff4ab2c9d.wolf.jina.ai/openapi.json │ ╰──────────────┴──────────────────────────────────────────────────────────────────────────────────────╯
</details>

Interact using cURL

(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":""}

Running on localhost

Credits : Adithya S

  1. Pull the image by entering the following command in your terminal or command prompt:
docker pull registry.hf.space/bhaskartripathi-pdfchatter:latest
  1. Download the Universal Sentence Encoder locally to your project's root folder. This is important because otherwise, 915 MB will be downloaded at runtime everytime you run it.
  2. Download the encoder using this link.
  3. Extract the downloaded file and place it in your project's root folder as shown below:
Root folder of your project └───Universal Sentence Encoder | ├───assets | └───variables | └───saved_model.pb | └───app.py
  1. If you have downloaded it locally, replace the code on line 68 in the API file:
self.use = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4')

with:

self.use = hub.load('./Universal Sentence Encoder/')
  1. Now, To run PDF-GPT, enter the following command:
docker run -it -p 7860:7860 --platform=linux/amd64 registry.hf.space/bhaskartripathi-pdfchatter:latest python app.py

Original Source code with no integrations (for demo hosted in Hugging Face) :

https://huggingface.co/spaces/bhaskartripathi/pdfGPT_Turbo

UML

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

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]

Star History

Star History Chart 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.

Also Try PyViralContent:

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

License

This project is licensed under the MIT License. See the LICENSE.txt file for details.

Citation

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}} }

编辑推荐精选

讯飞智文

讯飞智文

一键生成PPT和Word,让学习生活更轻松

讯飞智文是一个利用 AI 技术的项目,能够帮助用户生成 PPT 以及各类文档。无论是商业领域的市场分析报告、年度目标制定,还是学生群体的职业生涯规划、实习避坑指南,亦或是活动策划、旅游攻略等内容,它都能提供支持,帮助用户精准表达,轻松呈现各种信息。

AI办公办公工具AI工具讯飞智文AI在线生成PPTAI撰写助手多语种文档生成AI自动配图热门
讯飞星火

讯飞星火

深度推理能力全新升级,全面对标OpenAI o1

科大讯飞的星火大模型,支持语言理解、知识问答和文本创作等多功能,适用于多种文件和业务场景,提升办公和日常生活的效率。讯飞星火是一个提供丰富智能服务的平台,涵盖科技资讯、图像创作、写作辅助、编程解答、科研文献解读等功能,能为不同需求的用户提供便捷高效的帮助,助力用户轻松获取信息、解决问题,满足多样化使用场景。

热门AI开发模型训练AI工具讯飞星火大模型智能问答内容创作多语种支持智慧生活
Spark-TTS

Spark-TTS

一种基于大语言模型的高效单流解耦语音令牌文本到语音合成模型

Spark-TTS 是一个基于 PyTorch 的开源文本到语音合成项目,由多个知名机构联合参与。该项目提供了高效的 LLM(大语言模型)驱动的语音合成方案,支持语音克隆和语音创建功能,可通过命令行界面(CLI)和 Web UI 两种方式使用。用户可以根据需求调整语音的性别、音高、速度等参数,生成高质量的语音。该项目适用于多种场景,如有声读物制作、智能语音助手开发等。

Trae

Trae

字节跳动发布的AI编程神器IDE

Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。

AI工具TraeAI IDE协作生产力转型热门
咔片PPT

咔片PPT

AI助力,做PPT更简单!

咔片是一款轻量化在线演示设计工具,借助 AI 技术,实现从内容生成到智能设计的一站式 PPT 制作服务。支持多种文档格式导入生成 PPT,提供海量模板、智能美化、素材替换等功能,适用于销售、教师、学生等各类人群,能高效制作出高品质 PPT,满足不同场景演示需求。

讯飞绘文

讯飞绘文

选题、配图、成文,一站式创作,让内容运营更高效

讯飞绘文,一个AI集成平台,支持写作、选题、配图、排版和发布。高效生成适用于各类媒体的定制内容,加速品牌传播,提升内容营销效果。

热门AI辅助写作AI工具讯飞绘文内容运营AI创作个性化文章多平台分发AI助手
材料星

材料星

专业的AI公文写作平台,公文写作神器

AI 材料星,专业的 AI 公文写作辅助平台,为体制内工作人员提供高效的公文写作解决方案。拥有海量公文文库、9 大核心 AI 功能,支持 30 + 文稿类型生成,助力快速完成领导讲话、工作总结、述职报告等材料,提升办公效率,是体制打工人的得力写作神器。

openai-agents-python

openai-agents-python

OpenAI Agents SDK,助力开发者便捷使用 OpenAI 相关功能。

openai-agents-python 是 OpenAI 推出的一款强大 Python SDK,它为开发者提供了与 OpenAI 模型交互的高效工具,支持工具调用、结果处理、追踪等功能,涵盖多种应用场景,如研究助手、财务研究等,能显著提升开发效率,让开发者更轻松地利用 OpenAI 的技术优势。

Hunyuan3D-2

Hunyuan3D-2

高分辨率纹理 3D 资产生成

Hunyuan3D-2 是腾讯开发的用于 3D 资产生成的强大工具,支持从文本描述、单张图片或多视角图片生成 3D 模型,具备快速形状生成能力,可生成带纹理的高质量 3D 模型,适用于多个领域,为 3D 创作提供了高效解决方案。

3FS

3FS

一个具备存储、管理和客户端操作等多种功能的分布式文件系统相关项目。

3FS 是一个功能强大的分布式文件系统项目,涵盖了存储引擎、元数据管理、客户端工具等多个模块。它支持多种文件操作,如创建文件和目录、设置布局等,同时具备高效的事件循环、节点选择和协程池管理等特性。适用于需要大规模数据存储和管理的场景,能够提高系统的性能和可靠性,是分布式存储领域的优质解决方案。

下拉加载更多