inflaton commited on
Commit
1aea7e7
1 Parent(s): d5edf96

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +1 -121
README.md CHANGED
@@ -1,5 +1,5 @@
1
  ---
2
- title: Chat with SMU LibBot
3
  emoji: 👀
4
  colorFrom: indigo
5
  colorTo: blue
@@ -10,123 +10,3 @@ pinned: false
10
  license: apache-2.0
11
  duplicated_from: inflaton/smu-ai
12
  ---
13
-
14
- # ChatPDF - Talk to Your PDF Files
15
-
16
- This project uses Open AI and open-source large language models (LLMs) to enable you to talk to your own PDF files.
17
-
18
- ## How it works
19
-
20
- We're using an AI design pattern, namely "in-context learning" which uses LLMs off the shelf (i.e., without any fine-tuning), then controls their behavior through clever prompting and conditioning on private “contextual” data, e.g., texts extracted from your PDF files.
21
-
22
- At a very high level, the workflow can be divided into three stages:
23
-
24
- 1. Data preprocessing / embedding: This stage involves storing private data (your PDF files) to be retrieved later. Typically, the documents are broken into chunks, passed through an embedding model, then stored the created embeddings in a vectorstore.
25
-
26
- 2. Prompt construction / retrieval: When a user submits a query, the application constructs a series of prompts to submit to the language model. A compiled prompt typically combines a prompt template and a set of relevant documents retrieved from the vectorstore.
27
-
28
- 3. Prompt execution / inference: Once the prompts have been compiled, they are submitted to a pre-trained LLM for inference—including both proprietary model APIs and open-source or self-trained models.
29
-
30
- ![In-context Learning - Workflow Overview](./assets/Workflow-Overview.png)
31
-
32
- Tech stack used includes LangChain, Gradio, Chroma and FAISS.
33
- - LangChain is an open-source framework that makes it easier to build scalable AI/LLM apps and chatbots.
34
- - Gradio is an open-source Python library that is used to build machine learning and data science demos and web applications.
35
- - Chroma and FAISS are open-source vectorstores for storing embeddings for your files.
36
-
37
- ## Running Locally
38
-
39
- 1. Check pre-conditions:
40
-
41
- - [Git Large File Storage (LFS)](https://git-lfs.com/) must have been installed.
42
- - Run `python --version` to make sure you're running Python version 3.10 or above.
43
- - The latest PyTorch with GPU support must have been installed. Here is a sample `conda` command:
44
- ```
45
- conda install -y pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia
46
- ```
47
- - [CMake](https://cmake.org/) must have been installed. Here is a sample command to install `CMake` on `ubuntu`:
48
- ```
49
- sudo apt install cmake
50
- ```
51
-
52
- 2. Clone the repo
53
-
54
- ```
55
- git lfs install
56
- git clone https://huggingface.co/spaces/inflaton/learn-ai
57
- ```
58
-
59
-
60
- 3. Install packages
61
-
62
- ```
63
- pip install -U -r requirements.txt
64
- ```
65
-
66
- 4. Set up your environment variables
67
-
68
- - By default, environment variables are loaded `.env.example` file
69
- - If you don't want to use the default settings, copy `.env.example` into `.env`. Your can then update it for your local runs.
70
-
71
-
72
- 5. Start the local server at `http://localhost:7860`:
73
-
74
- ```
75
- python app.py
76
- ```
77
-
78
- ## Duplicate This Space
79
-
80
- Duplicate this HuggingFace Space from the UI or click the following link:
81
-
82
- - [Duplicate this space](https://huggingface.co/spaces/inflaton/learn-ai?duplicate=true)
83
-
84
- Once duplicated, you can set up environment variables from the space settings. The values there will take precedence of those in `.env.example`.
85
-
86
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
87
-
88
- ## Talk to Your Own PDF Files
89
-
90
- - The sample PDF books & documents are downloaded from the internet (for SMU LibBot) and [PCI DSS official website](https://www.pcisecuritystandards.org/document_library/?category=pcidss) and the corresponding embeddings are stored in folders `data/ai_books` and `data/pci_dss_v4` respectively, which allows you to run locally without any additional effort.
91
-
92
- - You can also put your own PDF files into any folder specified in `SOURCE_PDFS_PATH` and run the command below to generate embeddings which will be stored in folder `FAISS_INDEX_PATH` or `CHROMADB_INDEX_PATH`. If both `*_INDEX_PATH` env vars are set, `FAISS_INDEX_PATH` takes precedence. Make sure the folder specified by `*_INDEX_PATH` doesn't exist; other wise the command will simply try to load index from the folder and do a simple similarity search, as a way to verify if embeddings are generated and stored properly. Please note the HuggingFace Embedding model specified by `HF_EMBEDDINGS_MODEL_NAME` will be used to generate the embeddings.
93
-
94
- ```
95
- python ingest.py
96
- ```
97
-
98
- - Once embeddings are generated, you can test them out locally, or check them into your duplicated space. Please note HF Spaces git server does not allow PDF files to be checked in.
99
-
100
- ## Play with Different Large Language Models
101
-
102
- The source code supports different LLM types - as shown at the top of `.env.example`
103
-
104
- ```
105
- # LLM_MODEL_TYPE=openai
106
- # LLM_MODEL_TYPE=gpt4all-j
107
- # LLM_MODEL_TYPE=gpt4all
108
- # LLM_MODEL_TYPE=llamacpp
109
- LLM_MODEL_TYPE=huggingface
110
- # LLM_MODEL_TYPE=mosaicml
111
- # LLM_MODEL_TYPE=stablelm
112
- # LLM_MODEL_TYPE=openllm
113
- # LLM_MODEL_TYPE=hftgi
114
- ```
115
-
116
- - By default, the app runs `lmsys/fastchat-t5-3b-v1.0` model with HF Transformers, which works well with most PCs/laptops with 32GB or more RAM, without any GPU. It also works on HF Spaces with their free-tier: 2 vCPU, 16GB RAM and 500GB hard disk, though the inference speed is very slow.
117
-
118
- - Uncomment/comment the above to play with different LLM types. You may also want to update other related env vars. E.g., here's the list of HF models which have been tested with the code:
119
-
120
- ```
121
- # HUGGINGFACE_MODEL_NAME_OR_PATH="databricks/dolly-v2-3b"
122
- # HUGGINGFACE_MODEL_NAME_OR_PATH="databricks/dolly-v2-7b"
123
- # HUGGINGFACE_MODEL_NAME_OR_PATH="databricks/dolly-v2-12b"
124
- # HUGGINGFACE_MODEL_NAME_OR_PATH="TheBloke/wizardLM-7B-HF"
125
- # HUGGINGFACE_MODEL_NAME_OR_PATH="TheBloke/vicuna-7B-1.1-HF"
126
- # HUGGINGFACE_MODEL_NAME_OR_PATH="nomic-ai/gpt4all-j"
127
- # HUGGINGFACE_MODEL_NAME_OR_PATH="nomic-ai/gpt4all-falcon"
128
- HUGGINGFACE_MODEL_NAME_OR_PATH="lmsys/fastchat-t5-3b-v1.0"
129
- # HUGGINGFACE_MODEL_NAME_OR_PATH="meta-llama/Llama-2-7b-chat-hf"
130
- # HUGGINGFACE_MODEL_NAME_OR_PATH="meta-llama/Llama-2-13b-chat-hf"
131
- # HUGGINGFACE_MODEL_NAME_OR_PATH="meta-llama/Llama-2-70b-chat-hf"
132
- ```
 
1
  ---
2
+ title: Chat with SMU Library Chatbot
3
  emoji: 👀
4
  colorFrom: indigo
5
  colorTo: blue
 
10
  license: apache-2.0
11
  duplicated_from: inflaton/smu-ai
12
  ---