tmt3103 commited on
Commit
dc235a0
·
1 Parent(s): 394310f

first commit

Browse files
Files changed (13) hide show
  1. .gitignore +213 -0
  2. Dockerfile +16 -0
  3. LICENSE +21 -0
  4. README.md +99 -6
  5. app.py +66 -0
  6. requirements.txt +12 -0
  7. setup.py +11 -0
  8. src/__init__.py +0 -0
  9. src/helper.py +24 -0
  10. src/prompt.py +9 -0
  11. static/style.css +223 -0
  12. template.py +35 -0
  13. templates/chat.html +81 -0
.gitignore ADDED
@@ -0,0 +1,213 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py.cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ #uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ #poetry.lock
109
+ #poetry.toml
110
+
111
+ # pdm
112
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
113
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
114
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
115
+ #pdm.lock
116
+ #pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # pixi
121
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
122
+ #pixi.lock
123
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
124
+ # in the .venv directory. It is recommended not to include this directory in version control.
125
+ .pixi
126
+
127
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
128
+ __pypackages__/
129
+
130
+ # Celery stuff
131
+ celerybeat-schedule
132
+ celerybeat.pid
133
+
134
+ # SageMath parsed files
135
+ *.sage.py
136
+
137
+ # Environments
138
+ .env
139
+ .envrc
140
+ .venv
141
+ env/
142
+ venv/
143
+ ENV/
144
+ env.bak/
145
+ venv.bak/
146
+
147
+ # Spyder project settings
148
+ .spyderproject
149
+ .spyproject
150
+
151
+ # Rope project settings
152
+ .ropeproject
153
+
154
+ # mkdocs documentation
155
+ /site
156
+
157
+ # mypy
158
+ .mypy_cache/
159
+ .dmypy.json
160
+ dmypy.json
161
+
162
+ # Pyre type checker
163
+ .pyre/
164
+
165
+ # pytype static type analyzer
166
+ .pytype/
167
+
168
+ # Cython debug symbols
169
+ cython_debug/
170
+
171
+ # PyCharm
172
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
173
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
174
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
175
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
176
+ #.idea/
177
+
178
+ # Abstra
179
+ # Abstra is an AI-powered process automation framework.
180
+ # Ignore directories containing user credentials, local state, and settings.
181
+ # Learn more at https://abstra.io/docs
182
+ .abstra/
183
+
184
+ # Visual Studio Code
185
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
186
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
187
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
188
+ # you could uncomment the following to ignore the entire vscode folder
189
+ # .vscode/
190
+
191
+ # Ruff stuff:
192
+ .ruff_cache/
193
+
194
+ # PyPI configuration file
195
+ .pypirc
196
+
197
+ # Cursor
198
+ # Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
199
+ # exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
200
+ # refer to https://docs.cursor.com/context/ignore-files
201
+ .cursorignore
202
+ .cursorindexingignore
203
+
204
+ # Marimo
205
+ marimo/_static/
206
+ marimo/_lsp/
207
+ __marimo__/
208
+
209
+ # Virtual environments
210
+ # Virtual environments created by tools like venv, virtualenv, or conda.
211
+ # These directories contain the Python interpreter and installed packages, which are not needed
212
+ # in version control.
213
+ medchatbot/
Dockerfile ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9-slim
2
+
3
+ # Set working directory
4
+ WORKDIR /app
5
+
6
+ # Copy into container
7
+ COPY . /app
8
+
9
+ # dependencies
10
+ RUN pip install -r requirements.txt
11
+
12
+ # Expose port
13
+ EXPOSE 7860
14
+
15
+ # Run app
16
+ CMD ["python", "app.py"]
LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Tien Tran Minh
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
README.md CHANGED
@@ -1,12 +1,105 @@
1
  ---
2
  title: MedChatBot
3
- emoji: 🚀
4
- colorFrom: yellow
5
- colorTo: purple
6
  sdk: docker
7
  pinned: false
8
- license: mit
9
- short_description: A medical chatbot
10
  ---
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  title: MedChatBot
3
+ emoji: 💊
4
+ colorFrom: blue
5
+ colorTo: green
6
  sdk: docker
7
  pinned: false
 
 
8
  ---
9
 
10
+ # MedChatBot
11
+
12
+ A medical chatbot application that uses RAG (Retrieval-Augmented Generation) architecture to answer medical questions based on medical literature. The system combines **Google Gemini 2.5 Pro** as the language model with **Pinecone** vector database for efficient document retrieval.
13
+
14
+ ## Technology Stack
15
+
16
+ - **Backend**: Flask
17
+ - **Language Model**: Google Gemini 2.5 Pro
18
+ - **Vector Database**: Pinecone
19
+ - **Embeddings**: HuggingFace sentence-transformers (all-MiniLM-L6-v2)
20
+ - **Document Processing**: LangChain, PyPDF
21
+ - **Frontend**: HTML/CSS/JavaScript
22
+
23
+ ## Installation & Setup
24
+
25
+ ### Step 1: Clone the Repository
26
+ ```bash
27
+ git clone https://github.com/TMTien31/MedChatBot.git
28
+ cd MedChatBot
29
+ ```
30
+
31
+ ### Step 2: Create Virtual Environment
32
+ ```bash
33
+ # Create virtual environment
34
+ python -m venv venv
35
+
36
+ # Activate virtual environment
37
+ # On Windows:
38
+ venv\Scripts\activate
39
+
40
+ # On macOS/Linux:
41
+ source venv/bin/activate
42
+ ```
43
+
44
+ ### Step 3: Install Dependencies
45
+ ```bash
46
+ pip install -r requirements.txt
47
+ ```
48
+
49
+ ### Step 4: Get API Keys
50
+
51
+ #### Google Gemini API Key:
52
+ 1. Go to [Google AI Studio](https://makersuite.google.com/app/apikey)
53
+ 2. Create a new API key
54
+ 3. Copy the generated key
55
+
56
+ #### Pinecone API Key:
57
+ 1. Sign up at [Pinecone](https://www.pinecone.io/)
58
+ 2. Go to your dashboard
59
+ 3. Copy your API key from the "API Keys" section
60
+
61
+ ### Step 5: Create Environment File
62
+ Create a `.env` file in the project root directory:
63
+ ```bash
64
+ # Create .env file
65
+ touch .env # On macOS/Linux
66
+ # or create manually on Windows
67
+ ```
68
+
69
+ Add your API keys to the `.env` file:
70
+ ```env
71
+ PINECONE_API_KEY=your_pinecone_api_key_here
72
+ GEMINI_API_KEY=your_gemini_api_key_here
73
+ ```
74
+
75
+ ### Step 6: Prepare Medical Documents
76
+ - Place your PDF medical documents in the `Data/` folder
77
+ - The project includes "Gale Encyclopedia of Medicine Vol. 1 (A-B).pdf" by default
78
+ - You can add more medical PDFs to expand the knowledge base
79
+
80
+ ### Step 7: Create Vector Index (Run Once)
81
+ **Important**: This step only needs to be run once initially, or whenever you add new documents to the `Data/` folder.
82
+
83
+ ```bash
84
+ python store_index.py
85
+ ```
86
+
87
+ This script will:
88
+ - Read all PDF files from the `Data/` directory
89
+ - Split text into 500-character chunks with 20-character overlap
90
+ - Generate embeddings using sentence-transformers
91
+ - Create and populate a Pinecone index named "medchatbot"
92
+
93
+ **Note**: This process may take several minutes depending on the size of your documents.
94
+
95
+ ## Running the Application
96
+
97
+ ### Start the Flask Server
98
+ ```bash
99
+ python app.py
100
+ ```
101
+
102
+ ### Access the Application
103
+ 1. Open your web browser
104
+ 2. Navigate to: `http://0.0.0.0:8080` or `http://localhost:8080`
105
+ 3. You should see the medical chatbot interface
app.py ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, render_template, jsonify, request
2
+ from src.helper import download_hugging_face_embeddings
3
+ from langchain_pinecone import PineconeVectorStore
4
+ from langchain_google_genai import ChatGoogleGenerativeAI
5
+ from langchain.chains import create_retrieval_chain
6
+ from langchain.chains.combine_documents import create_stuff_documents_chain
7
+ from langchain_core.prompts import ChatPromptTemplate
8
+ from dotenv import load_dotenv
9
+ from src.prompt import *
10
+ import os
11
+
12
+ app = Flask(__name__)
13
+
14
+ load_dotenv()
15
+
16
+ PINECONE_API_KEY=os.environ.get('PINECONE_API_KEY')
17
+ GEMINI_API_KEY=os.environ.get('GEMINI_API_KEY')
18
+
19
+ os.environ["PINECONE_API_KEY"] = PINECONE_API_KEY
20
+ os.environ["GEMINI_API_KEY"] = GEMINI_API_KEY
21
+
22
+ embeddings = download_hugging_face_embeddings()
23
+
24
+
25
+ index_name = "medchatbot"
26
+
27
+ # Embed each chunk and upsert the embeddings into your Pinecone index.
28
+ docsearch = PineconeVectorStore.from_existing_index(
29
+ index_name=index_name,
30
+ embedding=embeddings
31
+ )
32
+
33
+ retriever = docsearch.as_retriever(search_type="similarity", search_kwargs={"k":3})
34
+
35
+ llm = ChatGoogleGenerativeAI(
36
+ model="gemini-2.5-pro",
37
+ google_api_key=GEMINI_API_KEY,
38
+ temperature=0.4,
39
+ max_output_tokens=2048
40
+ )
41
+ prompt = ChatPromptTemplate.from_messages(
42
+ [
43
+ ("system", system_prompt),
44
+ ("human", "{input}"),
45
+ ]
46
+ )
47
+
48
+ question_answer_chain = create_stuff_documents_chain(llm, prompt)
49
+ rag_chain = create_retrieval_chain(retriever, question_answer_chain)
50
+
51
+
52
+ @app.route("/")
53
+ def index():
54
+ return render_template('chat.html')
55
+
56
+ @app.route("/get", methods=["GET", "POST"])
57
+ def chat():
58
+ msg = request.form["msg"]
59
+ input = msg
60
+ print(input)
61
+ response = rag_chain.invoke({"input": msg})
62
+ print("Response : ", response["answer"])
63
+ return str(response["answer"])
64
+
65
+ if __name__ == '__main__':
66
+ app.run(host="0.0.0.0", port= 7860, debug= True)
requirements.txt ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ sentence-transformers==2.2.2
2
+ langchain
3
+ flask
4
+ pypdf
5
+ python-dotenv
6
+ pinecone[grpc]
7
+ langchain-pinecone
8
+ langchain_community
9
+ langchain_openai
10
+ langchain_experimental
11
+ langchain_google_genai
12
+ -e .
setup.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from setuptools import find_packages, setup
2
+
3
+ setup(
4
+ name = 'Medical Chatbot Project',
5
+ version= '0.0.0',
6
+ author= 'Tien Tran Minh',
7
+ author_email= 'tmt31032005@gmail.com',
8
+ packages= find_packages(),
9
+ install_requires = []
10
+
11
+ )
src/__init__.py ADDED
File without changes
src/helper.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain.document_loaders import PyPDFLoader, DirectoryLoader
2
+ from langchain.text_splitter import RecursiveCharacterTextSplitter
3
+ from langchain.embeddings import HuggingFaceEmbeddings
4
+
5
+ #Extract Data From the PDF File
6
+ def load_pdf_file(data):
7
+ loader= DirectoryLoader(data,
8
+ glob="*.pdf",
9
+ loader_cls=PyPDFLoader)
10
+
11
+ documents=loader.load()
12
+
13
+ return documents
14
+
15
+ #Split the Data into Text Chunks
16
+ def text_split(extracted_data):
17
+ text_splitter=RecursiveCharacterTextSplitter(chunk_size=500, chunk_overlap=20)
18
+ text_chunks=text_splitter.split_documents(extracted_data)
19
+ return text_chunks
20
+
21
+ #Download the Embeddings from Hugging Face
22
+ def download_hugging_face_embeddings():
23
+ embeddings=HuggingFaceEmbeddings(model_name='sentence-transformers/all-MiniLM-L6-v2')
24
+ return embeddings
src/prompt.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ system_prompt = (
2
+ "You are an assistant for question-answering tasks. "
3
+ "Use the following pieces of retrieved context to answer "
4
+ "the question. If you don't know the answer, say that you "
5
+ "don't know. Use three sentences maximum and keep the "
6
+ "answer concise."
7
+ "\n\n"
8
+ "{context}"
9
+ )
static/style.css ADDED
@@ -0,0 +1,223 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ body,html{
2
+ height: 100%;
3
+ margin: 0;
4
+ background: rgb(44, 47, 59);
5
+ background: -webkit-linear-gradient(to right, rgb(40, 59, 34), rgb(54, 60, 70), rgb(32, 32, 43));
6
+ background: linear-gradient(to right, rgb(38, 51, 61), rgb(50, 55, 65), rgb(33, 33, 78));
7
+ }
8
+
9
+ .chat{
10
+ margin-top: auto;
11
+ margin-bottom: auto;
12
+ }
13
+ .card{
14
+ height: 500px;
15
+ border-radius: 15px !important;
16
+ background-color: rgba(0,0,0,0.4) !important;
17
+ }
18
+ .contacts_body{
19
+ padding: 0.75rem 0 !important;
20
+ overflow-y: auto;
21
+ white-space: nowrap;
22
+ }
23
+ .msg_card_body{
24
+ overflow-y: auto;
25
+ }
26
+ .card-header{
27
+ border-radius: 15px 15px 0 0 !important;
28
+ border-bottom: 0 !important;
29
+ }
30
+ .card-footer{
31
+ border-radius: 0 0 15px 15px !important;
32
+ border-top: 0 !important;
33
+ }
34
+ .container{
35
+ align-content: center;
36
+ }
37
+ .search{
38
+ border-radius: 15px 0 0 15px !important;
39
+ background-color: rgba(0,0,0,0.3) !important;
40
+ border:0 !important;
41
+ color:white !important;
42
+ }
43
+ .search:focus{
44
+ box-shadow:none !important;
45
+ outline:0px !important;
46
+ }
47
+ .type_msg{
48
+ background-color: rgba(0,0,0,0.3) !important;
49
+ border:0 !important;
50
+ color:white !important;
51
+ height: 60px !important;
52
+ overflow-y: auto;
53
+ }
54
+ .type_msg:focus{
55
+ box-shadow:none !important;
56
+ outline:0px !important;
57
+ }
58
+ .attach_btn{
59
+ border-radius: 15px 0 0 15px !important;
60
+ background-color: rgba(0,0,0,0.3) !important;
61
+ border:0 !important;
62
+ color: white !important;
63
+ cursor: pointer;
64
+ }
65
+ .send_btn{
66
+ border-radius: 0 15px 15px 0 !important;
67
+ background-color: rgba(0,0,0,0.3) !important;
68
+ border:0 !important;
69
+ color: white !important;
70
+ cursor: pointer;
71
+ }
72
+ .search_btn{
73
+ border-radius: 0 15px 15px 0 !important;
74
+ background-color: rgba(0,0,0,0.3) !important;
75
+ border:0 !important;
76
+ color: white !important;
77
+ cursor: pointer;
78
+ }
79
+ .contacts{
80
+ list-style: none;
81
+ padding: 0;
82
+ }
83
+ .contacts li{
84
+ width: 100% !important;
85
+ padding: 5px 10px;
86
+ margin-bottom: 15px !important;
87
+ }
88
+ .active{
89
+ background-color: rgba(0,0,0,0.3);
90
+ }
91
+ .user_img{
92
+ height: 70px;
93
+ width: 70px;
94
+ border:1.5px solid #f5f6fa;
95
+
96
+ }
97
+ .user_img_msg{
98
+ height: 40px;
99
+ width: 40px;
100
+ border:1.5px solid #f5f6fa;
101
+
102
+ }
103
+ .img_cont{
104
+ position: relative;
105
+ height: 70px;
106
+ width: 70px;
107
+ }
108
+ .img_cont_msg{
109
+ height: 40px;
110
+ width: 40px;
111
+ }
112
+ .online_icon{
113
+ position: absolute;
114
+ height: 15px;
115
+ width:15px;
116
+ background-color: #4cd137;
117
+ border-radius: 50%;
118
+ bottom: 0.2em;
119
+ right: 0.4em;
120
+ border:1.5px solid white;
121
+ }
122
+ .offline{
123
+ background-color: #c23616 !important;
124
+ }
125
+ .user_info{
126
+ margin-top: auto;
127
+ margin-bottom: auto;
128
+ margin-left: 15px;
129
+ }
130
+ .user_info span{
131
+ font-size: 20px;
132
+ color: white;
133
+ }
134
+ .user_info p{
135
+ font-size: 10px;
136
+ color: rgba(255,255,255,0.6);
137
+ }
138
+ .video_cam{
139
+ margin-left: 50px;
140
+ margin-top: 5px;
141
+ }
142
+ .video_cam span{
143
+ color: white;
144
+ font-size: 20px;
145
+ cursor: pointer;
146
+ margin-right: 20px;
147
+ }
148
+ .msg_cotainer{
149
+ margin-top: auto;
150
+ margin-bottom: auto;
151
+ margin-left: 10px;
152
+ border-radius: 25px;
153
+ background-color: rgb(82, 172, 255);
154
+ padding: 10px;
155
+ position: relative;
156
+ }
157
+ .msg_cotainer_send{
158
+ margin-top: auto;
159
+ margin-bottom: auto;
160
+ margin-right: 10px;
161
+ border-radius: 25px;
162
+ background-color: #58cc71;
163
+ padding: 10px;
164
+ position: relative;
165
+ }
166
+ .msg_time{
167
+ position: absolute;
168
+ left: 0;
169
+ bottom: -15px;
170
+ color: rgba(255,255,255,0.5);
171
+ font-size: 10px;
172
+ }
173
+ .msg_time_send{
174
+ position: absolute;
175
+ right:0;
176
+ bottom: -15px;
177
+ color: rgba(255,255,255,0.5);
178
+ font-size: 10px;
179
+ }
180
+ .msg_head{
181
+ position: relative;
182
+ }
183
+ #action_menu_btn{
184
+ position: absolute;
185
+ right: 10px;
186
+ top: 10px;
187
+ color: white;
188
+ cursor: pointer;
189
+ font-size: 20px;
190
+ }
191
+ .action_menu{
192
+ z-index: 1;
193
+ position: absolute;
194
+ padding: 15px 0;
195
+ background-color: rgba(0,0,0,0.5);
196
+ color: white;
197
+ border-radius: 15px;
198
+ top: 30px;
199
+ right: 15px;
200
+ display: none;
201
+ }
202
+ .action_menu ul{
203
+ list-style: none;
204
+ padding: 0;
205
+ margin: 0;
206
+ }
207
+ .action_menu ul li{
208
+ width: 100%;
209
+ padding: 10px 15px;
210
+ margin-bottom: 5px;
211
+ }
212
+ .action_menu ul li i{
213
+ padding-right: 10px;
214
+ }
215
+ .action_menu ul li:hover{
216
+ cursor: pointer;
217
+ background-color: rgba(0,0,0,0.2);
218
+ }
219
+ @media(max-width: 576px){
220
+ .contacts_card{
221
+ margin-bottom: 15px !important;
222
+ }
223
+ }
template.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from pathlib import Path
3
+ import logging
4
+
5
+ logging.basicConfig(level=logging.INFO, format='[%(asctime)s]: %(message)s:')
6
+
7
+
8
+ list_of_files = [
9
+ "src/__init__.py",
10
+ "src/helper.py",
11
+ "src/prompt.py",
12
+ ".env",
13
+ "setup.py",
14
+ "app.py",
15
+ "research/trials.ipynb",
16
+ ]
17
+
18
+
19
+ for filepath in list_of_files:
20
+ filepath = Path(filepath)
21
+ filedir, filename = os.path.split(filepath)
22
+
23
+
24
+ if filedir !="":
25
+ os.makedirs(filedir, exist_ok=True)
26
+ logging.info(f"Creating directory; {filedir} for the file: {filename}")
27
+
28
+ if (not os.path.exists(filepath)) or (os.path.getsize(filepath) == 0):
29
+ with open(filepath, "w") as f:
30
+ pass
31
+ logging.info(f"Creating empty file: {filepath}")
32
+
33
+
34
+ else:
35
+ logging.info(f"{filename} is already exists")
templates/chat.html ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
2
+ <script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
3
+ <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
4
+
5
+ <!DOCTYPE html>
6
+ <html>
7
+ <head>
8
+ <title>Chatbot</title>
9
+ <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
10
+ <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" integrity="sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU" crossorigin="anonymous">
11
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
12
+ <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css')}}"/>
13
+ </head>
14
+
15
+
16
+ <body>
17
+ <div class="container-fluid h-100">
18
+ <div class="row justify-content-center h-100">
19
+ <div class="col-md-8 col-xl-6 chat">
20
+ <div class="card">
21
+ <div class="card-header msg_head">
22
+ <div class="d-flex bd-highlight">
23
+ <div class="img_cont">
24
+ <img src="https://cdn-icons-png.flaticon.com/512/387/387569.png" class="rounded-circle user_img">
25
+ <!-- <img src="https://www.prdistribution.com/spirit/uploads/pressreleases/2019/newsreleases/d83341deb75c4c4f6b113f27b1e42cd8-chatbot-florence-already-helps-thousands-of-patients-to-remember-their-medication.png" class="rounded-circle user_img"> -->
26
+ <span class="online_icon"></span>
27
+ </div>
28
+ <div class="user_info">
29
+ <span>Medical Chatbot</span>
30
+ <p>Ask me anything!</p>
31
+ </div>
32
+ </div>
33
+ </div>
34
+ <div id="messageFormeight" class="card-body msg_card_body">
35
+
36
+
37
+ </div>
38
+ <div class="card-footer">
39
+ <form id="messageArea" class="input-group">
40
+ <input type="text" id="text" name="msg" placeholder="Type your message..." autocomplete="off" class="form-control type_msg" required/>
41
+ <div class="input-group-append">
42
+ <button type="submit" id="send" class="input-group-text send_btn"><i class="fas fa-location-arrow"></i></button>
43
+ </div>
44
+ </form>
45
+ </div>
46
+ </div>
47
+ </div>
48
+ </div>
49
+ </div>
50
+
51
+ <script>
52
+ $(document).ready(function() {
53
+ $("#messageArea").on("submit", function(event) {
54
+ const date = new Date();
55
+ const hour = date.getHours();
56
+ const minute = date.getMinutes();
57
+ const str_time = hour+":"+minute;
58
+ var rawText = $("#text").val();
59
+
60
+ var userHtml = '<div class="d-flex justify-content-end mb-4"><div class="msg_cotainer_send">' + rawText + '<span class="msg_time_send">'+ str_time + '</span></div><div class="img_cont_msg"><img src="https://i.ibb.co/d5b84Xw/Untitled-design.png" class="rounded-circle user_img_msg"></div></div>';
61
+
62
+ $("#text").val("");
63
+ $("#messageFormeight").append(userHtml);
64
+
65
+ $.ajax({
66
+ data: {
67
+ msg: rawText,
68
+ },
69
+ type: "POST",
70
+ url: "/get",
71
+ }).done(function(data) {
72
+ var botHtml = '<div class="d-flex justify-content-start mb-4"><div class="img_cont_msg"><img src="https://cdn-icons-png.flaticon.com/512/387/387569.png" class="rounded-circle user_img_msg"></div><div class="msg_cotainer">' + data + '<span class="msg_time">' + str_time + '</span></div></div>';
73
+ $("#messageFormeight").append($.parseHTML(botHtml));
74
+ });
75
+ event.preventDefault();
76
+ });
77
+ });
78
+ </script>
79
+
80
+ </body>
81
+ </html>