lavanjv commited on
Commit
a140fe2
0 Parent(s):

Duplicate from lavanjv/HealsmindAI

Browse files
.gitattributes ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ vectorstore/db_faiss/index.faiss filter=lfs diff=lfs merge=lfs -text
Dockerfile ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use the official Python image as the base image
2
+ FROM python:3.10
3
+
4
+ # Set the working directory in the container
5
+ WORKDIR /app
6
+
7
+ # Create a non-root user
8
+ RUN useradd -ms /bin/bash myuser
9
+
10
+ # Give the user ownership of the working directory and home directory
11
+ RUN chown -R myuser:myuser /app /home/myuser
12
+
13
+ # Switch to the non-root user
14
+ USER myuser
15
+
16
+ # Copy the entire contents of the local directory into the container
17
+ COPY . .
18
+
19
+ # Download the model file
20
+ RUN wget https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGML/resolve/main/llama-2-7b-chat.ggmlv3.q8_0.bin
21
+
22
+ # Install chainlit and add it to PATH
23
+ RUN pip install chainlit --user
24
+
25
+ # Set the PATH to include user-specific binaries
26
+ ENV PATH="/home/myuser/.local/bin:${PATH}"
27
+
28
+ # Install the required Python packages
29
+ RUN pip install -r requirements.txt
30
+
31
+ # Expose port 7860 internally in the container
32
+ EXPOSE 7860
33
+
34
+ # Run the ChainlIt command
35
+ CMD ["chainlit", "run", "model.py", "-w", "--port", "7860"]
LICENSE ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Copyright (c) 2023 HealMindAI
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
README.md ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: HealsMindAI
3
+ emoji: ⚡
4
+ colorFrom: red
5
+ colorTo: red
6
+ sdk: docker
7
+ pinned: false
8
+ license: mit
9
+ duplicated_from: lavanjv/HealsmindAI
10
+ ---
11
+
12
+ # HealsMindAI: AI-Powered Wellness Advisor
13
+
14
+
15
+
16
+ Welcome to HealsMindAI, an AI-powered wellness advisor that provides personalized healthcare insights using the power of Natural Language Processing (NLP) and open-source data. This repository contains the source code and resources for the HealsMindAI project.
17
+
18
+ ## Overview
19
+
20
+ HealsMindAI is designed to offer users personalized healthcare information, focusing on topics like yoga, natural remedies, and holistic wellness. The project leverages the capabilities of fine-tuned Large Language Models (LLMs) to generate human-like responses and engage users in meaningful conversations about their health-related inquiries.
21
+
22
+ ## Features
23
+
24
+ - AI-Powered Conversations: Engage in informative and natural conversations with the HealsMindAI to get personalized healthcare insights.
25
+ - Open-Source Dataset: The project is built on a dataset sourced from Project Gutenberg, offering a foundation for comprehensive health-related information.
26
+ - User Customization: Integrate your own health-related documents into the system, allowing HealsMindAI to provide insights based on your unique information.
27
+ - Transparent AI: HealsMindAI focuses on transparency and explainability, ensuring that the AI-generated responses are understandable and informative.
28
+
29
+ ## Getting Started for deploying locally:
30
+
31
+ 1. git lfs install
32
+ 2. git clone 'https://huggingface.co/spaces/lavanjv/HealsmindAI`
33
+ 3. Download 'llama-2-7b-chat.ggmlv3.q8_0.bin' from https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGML/tree/main
34
+ 4. Install the required dependencies: `pip install -r requirements.txt`
35
+ 5. Run the Streamlit app: `streamlit run app.py -w`
36
+ 6. Interact with HealsMindAI through the provided UI and explore its capabilities.
37
+
38
+ ## For fine tunning using custom pdf:
39
+ 1. Place the pdf files in data folder
40
+ 2. Run 'python ingest.py'
41
+ 3. Then run `streamlit run app.py -w`
42
+
43
+ ## Contributing
44
+
45
+ We welcome contributions to enhance and expand HealsMindAI' knowledge base. If you have health-related documents or insights, feel free to contribute by submitting a pull request.
46
+
47
+ ## License
48
+
49
+ This project is licensed under the [MIT License](LICENSE).
50
+
51
+ ## Contact
52
+
53
+ For questions or inquiries, please contact [jvlavan01@gmail.com](mailto:jvlavan01@gmail.com).
54
+ Created with Love by Lavan
chainlit.md ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # HealsMindAI: AI-Powered Wellness Advisor
2
+
3
+
4
+
5
+ Welcome to HealsMindAI, an AI-powered wellness advisor that provides personalized healthcare insights using the power of Natural Language Processing (NLP) and open-source data. This repository contains the source code and resources for the HealsMindAI project.
6
+
7
+ ## Overview
8
+
9
+ HealsMindAI is designed to offer users personalized healthcare information, focusing on topics like yoga, natural remedies, and holistic wellness. The project leverages the capabilities of fine-tuned Large Language Models (LLMs) to generate human-like responses and engage users in meaningful conversations about their health-related inquiries.
10
+
11
+ ## Features
12
+
13
+ - AI-Powered Conversations: Engage in informative and natural conversations with the HealsMindAI to get personalized healthcare insights.
14
+ - Open-Source Dataset: The project is built on a dataset sourced from Project Gutenberg, offering a foundation for comprehensive health-related information.
15
+ - User Customization: Integrate your own health-related documents into the system, allowing HealsMindAI to provide insights based on your unique information.
16
+ - Transparent AI: HealsMindAI focuses on transparency and explainability, ensuring that the AI-generated responses are understandable and informative.
17
+
18
+ ## Getting Started for deploying locally:
19
+
20
+ 1. git lfs install
21
+ 2. git clone 'https://huggingface.co/spaces/lavanjv/HealsmindAI`
22
+ 3. Download 'llama-2-7b-chat.ggmlv3.q8_0.bin' from https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGML/tree/main
23
+ 4. Install the required dependencies: `pip install -r requirements.txt`
24
+ 5. Run the Streamlit app: `streamlit run app.py -w`
25
+ 6. Interact with HealsMindAI through the provided UI and explore its capabilities.
26
+
27
+ ## For fine tunning using custom pdf:
28
+ 1. Place the pdf files in data folder
29
+ 2. Run 'python ingest.py'
30
+ 3. Then run `streamlit run app.py -w`
31
+
32
+ ## Contributing
33
+
34
+ We welcome contributions to enhance and expand HealsMindAI' knowledge base. If you have health-related documents or insights, feel free to contribute by submitting a pull request.
35
+
36
+ ## License
37
+
38
+ This project is licensed under the [MIT License](LICENSE).
39
+
40
+ ## Contact
41
+
42
+ For questions or inquiries, please contact [jvlavan01@gmail.com](mailto:jvlavan01@gmail.com).
43
+ Created with Love by Lavan
data/yoga-ayurvedha.pdf ADDED
Binary file (776 kB). View file
 
ingest.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain.embeddings import HuggingFaceEmbeddings
2
+ from langchain.vectorstores import FAISS
3
+ from langchain.document_loaders import PyPDFLoader, DirectoryLoader
4
+ from langchain.text_splitter import RecursiveCharacterTextSplitter
5
+
6
+ DATA_PATH = 'data/'
7
+ DB_FAISS_PATH = 'vectorstore/db_faiss'
8
+
9
+ # Create vector database
10
+ def create_vector_db():
11
+ loader = DirectoryLoader(DATA_PATH,
12
+ glob='*.pdf',
13
+ loader_cls=PyPDFLoader)
14
+
15
+ documents = loader.load()
16
+ text_splitter = RecursiveCharacterTextSplitter(chunk_size=500,
17
+ chunk_overlap=50)
18
+ texts = text_splitter.split_documents(documents)
19
+
20
+ embeddings = HuggingFaceEmbeddings(model_name='sentence-transformers/all-MiniLM-L6-v2',
21
+ model_kwargs={'device': 'cpu'})
22
+
23
+ db = FAISS.from_documents(texts, embeddings)
24
+ db.save_local(DB_FAISS_PATH)
25
+
26
+ if __name__ == "__main__":
27
+ create_vector_db()
28
+
model.py ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain.document_loaders import PyPDFLoader, DirectoryLoader
2
+ from langchain import PromptTemplate
3
+ from langchain.embeddings import HuggingFaceEmbeddings
4
+ from langchain.vectorstores import FAISS
5
+ from langchain.llms import CTransformers
6
+ from langchain.chains import RetrievalQA
7
+ import chainlit as cl
8
+
9
+ DB_FAISS_PATH = 'vectorstore/db_faiss'
10
+
11
+ custom_prompt_template = """Use the following pieces of information to answer the user's question.
12
+ If you don't know the answer, just say that you don't know, don't try to make up an answer.
13
+
14
+ Context: {context}
15
+ Question: {question}
16
+
17
+ Only return the helpful answer below and nothing else.
18
+ Helpful answer:
19
+ """
20
+
21
+ def set_custom_prompt():
22
+ """
23
+ Prompt template for QA retrieval for each vectorstore
24
+ """
25
+ prompt = PromptTemplate(template=custom_prompt_template,
26
+ input_variables=['context', 'question'])
27
+ return prompt
28
+
29
+ #Retrieval QA Chain
30
+ def retrieval_qa_chain(llm, prompt, db):
31
+ qa_chain = RetrievalQA.from_chain_type(llm=llm,
32
+ chain_type='stuff',
33
+ retriever=db.as_retriever(search_kwargs={'k': 2}),
34
+ return_source_documents=True,
35
+ chain_type_kwargs={'prompt': prompt}
36
+ )
37
+ return qa_chain
38
+
39
+ #Loading the model
40
+ def load_llm():
41
+ # Load the locally downloaded model here
42
+ llm = CTransformers(
43
+ model = "llama-2-7b-chat.ggmlv3.q8_0.bin",
44
+ model_type="llama",
45
+ max_new_tokens = 512,
46
+ temperature = 0.5
47
+ )
48
+ return llm
49
+
50
+ #QA Model Function
51
+ def qa_bot():
52
+ embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2",
53
+ model_kwargs={'device': 'cpu'})
54
+ db = FAISS.load_local(DB_FAISS_PATH, embeddings)
55
+ llm = load_llm()
56
+ qa_prompt = set_custom_prompt()
57
+ qa = retrieval_qa_chain(llm, qa_prompt, db)
58
+
59
+ return qa
60
+
61
+ #output function
62
+ def final_result(query):
63
+ qa_result = qa_bot()
64
+ response = qa_result({'query': query})
65
+ return response
66
+
67
+ #chainlit code
68
+ @cl.on_chat_start
69
+ async def start():
70
+ chain = qa_bot()
71
+ msg = cl.Message(content="Starting the bot...")
72
+ await msg.send()
73
+ msg.content = "Hi, Welcome to HealsMindAI. What is your query?"
74
+ await msg.update()
75
+
76
+ cl.user_session.set("chain", chain)
77
+
78
+ @cl.on_message
79
+ async def main(message):
80
+ chain = cl.user_session.get("chain")
81
+ cb = cl.AsyncLangchainCallbackHandler(
82
+ stream_final_answer=True, answer_prefix_tokens=["FINAL", "ANSWER"]
83
+ )
84
+ cb.answer_reached = True
85
+ res = await chain.acall(message, callbacks=[cb])
86
+ answer = res["result"]
87
+ sources = res["source_documents"]
88
+
89
+ if sources:
90
+ answer += f"\nSources:" + str(sources)
91
+ else:
92
+ answer += "\nNo sources found"
93
+
94
+ await cl.Message(content=answer).send()
95
+
requirements.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ pypdf
2
+ langchain
3
+ torch
4
+ accelerate
5
+ transformers
6
+ sentence_transformers
7
+ faiss_cpu
8
+ chainlit
9
+ ctransformers
vectorstore/db_faiss/index.faiss ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bed7b526714fd31111a0aff4a0d7ac3c60d537fb991e1a0632c810c635fc6cf9
3
+ size 3657261
vectorstore/db_faiss/index.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:13614b35d8ae6db0bf0702c92735f8801ded062a97b53ab1f1dc2a1fb3e7781f
3
+ size 1316371