Spaces:
Build error
Build error
Commit ·
7c5a5dc
1
Parent(s): 3a4af69
update readme
Browse files
README.md
CHANGED
|
@@ -1,174 +1,9 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
3.
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
1. PDF GPT allows you to chat with an uploaded PDF file using GPT functionalities.
|
| 11 |
-
2. The application intelligently breaks the document into smaller chunks and employs a powerful Deep Averaging Network Encoder to generate embeddings.
|
| 12 |
-
3. A semantic search is first performed on your pdf content and the most relevant embeddings are passed to the Open AI.
|
| 13 |
-
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.
|
| 14 |
-
5. Andrej Karpathy mentioned in this post that KNN algorithm is most appropriate for similar problems: https://twitter.com/karpathy/status/1647025230546886658
|
| 15 |
-
6. Enables APIs on Production using **[langchain-serve](https://github.com/jina-ai/langchain-serve)**.
|
| 16 |
-
|
| 17 |
-
### Demo
|
| 18 |
-
1. **Demo URL**: https://bit.ly/41ZXBJM
|
| 19 |
-
2. **Original Source code** (for demo hosted in Hugging Face) : https://huggingface.co/spaces/bhaskartripathi/pdfChatter/blob/main/app.py
|
| 20 |
-
|
| 21 |
-
**NOTE**: Please star this project if you like it!
|
| 22 |
-
|
| 23 |
-
### Docker
|
| 24 |
-
Run `docker-compose -f docker-compose.yaml up` to use it with Docker compose.
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
## Use `pdfGPT` on Production using [langchain-serve](https://github.com/jina-ai/langchain-serve)
|
| 28 |
-
|
| 29 |
-
#### Local playground
|
| 30 |
-
1. Run `lc-serve deploy local api` on one terminal to expose the app as API using langchain-serve.
|
| 31 |
-
2. Run `python app.py` on another terminal for a local gradio playground.
|
| 32 |
-
3. Open `http://localhost:7860` on your browser and interact with the app.
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
#### Cloud deployment
|
| 36 |
-
|
| 37 |
-
Make `pdfGPT` production ready by deploying it on [Jina Cloud](https://cloud.jina.ai/).
|
| 38 |
-
|
| 39 |
-
`lc-serve deploy jcloud api`
|
| 40 |
-
|
| 41 |
-
<details>
|
| 42 |
-
<summary>Show command output</summary>
|
| 43 |
-
|
| 44 |
-
```text
|
| 45 |
-
╭──────────────┬──────────────────────────────────────────────────────────────────────────────────────╮
|
| 46 |
-
│ App ID │ langchain-3ff4ab2c9d │
|
| 47 |
-
├──────────────┼──────────────────────────────────────────────────────────────────────────────────────┤
|
| 48 |
-
│ Phase │ Serving │
|
| 49 |
-
├──────────────┼──────────────────────────────────────────────────────────────────────────────────────┤
|
| 50 |
-
│ Endpoint │ https://langchain-3ff4ab2c9d.wolf.jina.ai │
|
| 51 |
-
├──────────────┼──────────────────────────────────────────────────────────────────────────────────────┤
|
| 52 |
-
│ App logs │ dashboards.wolf.jina.ai │
|
| 53 |
-
├──────────────┼──────────────────────────────────────────────────────────────────────────────────────┤
|
| 54 |
-
│ Swagger UI │ https://langchain-3ff4ab2c9d.wolf.jina.ai/docs │
|
| 55 |
-
├──────────────┼──────────────────────────────��───────────────────────────────────────────────────────┤
|
| 56 |
-
│ OpenAPI JSON │ https://langchain-3ff4ab2c9d.wolf.jina.ai/openapi.json │
|
| 57 |
-
╰──────────────┴──────────────────────────────────────────────────────────────────────────────────────╯
|
| 58 |
-
```
|
| 59 |
-
|
| 60 |
-
</details>
|
| 61 |
-
|
| 62 |
-
#### Interact using cURL
|
| 63 |
-
|
| 64 |
-
(Change the URL to your own endpoint)
|
| 65 |
-
|
| 66 |
-
**PDF url**
|
| 67 |
-
```bash
|
| 68 |
-
curl -X 'POST' \
|
| 69 |
-
'https://langchain-3ff4ab2c9d.wolf.jina.ai/ask_url' \
|
| 70 |
-
-H 'accept: application/json' \
|
| 71 |
-
-H 'Content-Type: application/json' \
|
| 72 |
-
-d '{
|
| 73 |
-
"url": "https://uiic.co.in/sites/default/files/uploads/downloadcenter/Arogya%20Sanjeevani%20Policy%20CIS_2.pdf",
|
| 74 |
-
"question": "What'\''s the cap on room rent?",
|
| 75 |
-
"envs": {
|
| 76 |
-
"OPENAI_API_KEY": "'"${OPENAI_API_KEY}"'"
|
| 77 |
-
}
|
| 78 |
-
}'
|
| 79 |
-
|
| 80 |
-
{"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":""}
|
| 81 |
-
```
|
| 82 |
-
|
| 83 |
-
**PDF file**
|
| 84 |
-
```bash
|
| 85 |
-
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))
|
| 86 |
-
curl -X 'POST' \
|
| 87 |
-
'https://langchain-3ff4ab2c9d.wolf.jina.ai/ask_file?'"${QPARAMS}" \
|
| 88 |
-
-H 'accept: application/json' \
|
| 89 |
-
-H 'Content-Type: multipart/form-data' \
|
| 90 |
-
-F 'file=@Arogya_Sanjeevani_Policy_CIS_2.pdf;type=application/pdf'
|
| 91 |
-
|
| 92 |
-
{"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":""}
|
| 93 |
-
```
|
| 94 |
-
|
| 95 |
-
## Running on localhost
|
| 96 |
-
### Credits : [Adithya S](https://github.com/200901002)
|
| 97 |
-
1. Pull the image by entering the following command in your terminal or command prompt:
|
| 98 |
-
```bash
|
| 99 |
-
docker pull registry.hf.space/bhaskartripathi-pdfchatter:latest
|
| 100 |
-
```
|
| 101 |
-
2. 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.
|
| 102 |
-
3. Download the encoder using this [link](https://tfhub.dev/google/universal-sentence-encoder/4?tf-hub-format=compressed).
|
| 103 |
-
4. Extract the downloaded file and place it in your project's root folder as shown below:
|
| 104 |
-
```text
|
| 105 |
-
Root folder of your project
|
| 106 |
-
└───Universal Sentence Encoder
|
| 107 |
-
| ├───assets
|
| 108 |
-
| └───variables
|
| 109 |
-
| └───saved_model.pb
|
| 110 |
-
|
|
| 111 |
-
└───app.py
|
| 112 |
-
```
|
| 113 |
-
5. If you have downloaded it locally, replace the code on line 68 in the API file:
|
| 114 |
-
```python
|
| 115 |
-
self.use = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4')
|
| 116 |
-
```
|
| 117 |
-
with:
|
| 118 |
-
```python
|
| 119 |
-
self.use = hub.load('./Universal Sentence Encoder/')
|
| 120 |
-
```
|
| 121 |
-
6. Now, To run PDF-GPT, enter the following command:
|
| 122 |
-
|
| 123 |
-
```bash
|
| 124 |
-
docker run -it -p 7860:7860 --platform=linux/amd64 registry.hf.space/bhaskartripathi-pdfchatter:latest python app.py
|
| 125 |
-
```
|
| 126 |
-
|
| 127 |
-
## UML
|
| 128 |
-
```mermaid
|
| 129 |
-
sequenceDiagram
|
| 130 |
-
participant User
|
| 131 |
-
participant System
|
| 132 |
-
|
| 133 |
-
User->>System: Enter API Key
|
| 134 |
-
User->>System: Upload PDF/PDF URL
|
| 135 |
-
User->>System: Ask Question
|
| 136 |
-
User->>System: Submit Call to Action
|
| 137 |
-
|
| 138 |
-
System->>System: Blank field Validations
|
| 139 |
-
System->>System: Convert PDF to Text
|
| 140 |
-
System->>System: Decompose Text to Chunks (150 word length)
|
| 141 |
-
System->>System: Check if embeddings file exists
|
| 142 |
-
System->>System: If file exists, load embeddings and set the fitted attribute to True
|
| 143 |
-
System->>System: If file doesn't exist, generate embeddings, fit the recommender, save embeddings to file and set fitted attribute to True
|
| 144 |
-
System->>System: Perform Semantic Search and return Top 5 Chunks with KNN
|
| 145 |
-
System->>System: Load Open AI prompt
|
| 146 |
-
System->>System: Embed Top 5 Chunks in Open AI Prompt
|
| 147 |
-
System->>System: Generate Answer with Davinci
|
| 148 |
-
|
| 149 |
-
System-->>User: Return Answer
|
| 150 |
-
```
|
| 151 |
-
|
| 152 |
-
### Flowchart
|
| 153 |
-
```mermaid
|
| 154 |
-
flowchart TB
|
| 155 |
-
A[Input] --> B[URL]
|
| 156 |
-
A -- Upload File manually --> C[Parse PDF]
|
| 157 |
-
B --> D[Parse PDF] -- Preprocess --> E[Dynamic Text Chunks]
|
| 158 |
-
C -- Preprocess --> E[Dynamic Text Chunks with citation history]
|
| 159 |
-
E --Fit-->F[Generate text embedding with Deep Averaging Network Encoder on each chunk]
|
| 160 |
-
F -- Query --> G[Get Top Results]
|
| 161 |
-
G -- K-Nearest Neighbour --> K[Get Nearest Neighbour - matching citation references]
|
| 162 |
-
K -- Generate Prompt --> H[Generate Answer]
|
| 163 |
-
H -- Output --> I[Output]
|
| 164 |
-
```
|
| 165 |
-
## Star History
|
| 166 |
-
|
| 167 |
-
[](https://star-history.com/#bhaskatripathi/pdfGPT&Date)
|
| 168 |
-
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.
|
| 169 |
-
|
| 170 |
-
## Also Try:
|
| 171 |
-
This app creates schematic architecture diagrams, UML, flowcharts, Gantt charts and many more. You simple need to mention the usecase in natural language and it will create the desired diagram.
|
| 172 |
-
https://github.com/bhaskatripathi/Text2Diagram
|
| 173 |
-
|
| 174 |
-
|
|
|
|
| 1 |
+
title: pdfADPM
|
| 2 |
+
emoji: 🏢
|
| 3 |
+
colorFrom: indigo
|
| 4 |
+
colorTo: green
|
| 5 |
+
sdk: gradio
|
| 6 |
+
sdk_version: 3.20.1
|
| 7 |
+
app_file: app.py
|
| 8 |
+
pinned: false
|
| 9 |
+
license: afl-3.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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