Shabdobhedi commited on
Commit
2883d0c
·
verified ·
1 Parent(s): 0cb8bbb

Upload 4 files

Browse files
Files changed (4) hide show
  1. .env +1 -0
  2. .gitignore +162 -0
  3. app.py +102 -0
  4. requirements.txt +16 -0
.env ADDED
@@ -0,0 +1 @@
 
 
1
+ GROQ_API_KEY = "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"
.gitignore ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
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
+ # poetry
98
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
+ #poetry.lock
103
+
104
+ # pdm
105
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106
+ #pdm.lock
107
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
+ # in version control.
109
+ # https://pdm.fming.dev/#use-with-ide
110
+ .pdm.toml
111
+
112
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113
+ __pypackages__/
114
+
115
+ # Celery stuff
116
+ celerybeat-schedule
117
+ celerybeat.pid
118
+
119
+ # SageMath parsed files
120
+ *.sage.py
121
+
122
+ # Environments
123
+ .env
124
+ .venv
125
+ env/
126
+ venv/
127
+ ENV/
128
+ env.bak/
129
+ venv.bak/
130
+
131
+ # Spyder project settings
132
+ .spyderproject
133
+ .spyproject
134
+
135
+ # Rope project settings
136
+ .ropeproject
137
+
138
+ # mkdocs documentation
139
+ /site
140
+
141
+ # mypy
142
+ .mypy_cache/
143
+ .dmypy.json
144
+ dmypy.json
145
+
146
+ # Pyre type checker
147
+ .pyre/
148
+
149
+ # pytype static type analyzer
150
+ .pytype/
151
+
152
+ # Cython debug symbols
153
+ cython_debug/
154
+
155
+ # PyCharm
156
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
159
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
160
+ #.idea/
161
+
162
+ model/llama-2-7b-chat.ggmlv3.q4_0.bin
app.py ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, render_template, jsonify, request
2
+ from src.helper import download_hugging_face_embeddings
3
+
4
+ from langchain_community.vectorstores import FAISS
5
+
6
+ from langchain.prompts import PromptTemplate
7
+ from langchain_groq import ChatGroq
8
+ # from langchain.llms import CTransformers
9
+ from langchain.chains import RetrievalQA
10
+ from langchain_core.prompts import ChatPromptTemplate
11
+ from dotenv import load_dotenv
12
+ from src.prompt import *
13
+ import os
14
+ from store_index import create_vector_db
15
+ app = Flask(__name__)
16
+
17
+ # load_dotenv()
18
+
19
+ # PINECONE_API_KEY = os.environ.get('PINECONE_API_KEY')
20
+ # PINECONE_API_ENV = os.environ.get('PINECONE_API_ENV')
21
+
22
+
23
+ # DATA_PATH = '/kaggle/input/book-pdf'
24
+ # DB_FAISS_PATH = r'G:\Chatbot\data\vector'
25
+
26
+ # Create vector database
27
+ create_vector_db()
28
+ print("###333")
29
+ # Call the function directly in the cell
30
+
31
+ '''#Initializing the Pinecone
32
+ pinecone.init(api_key=PINECONE_API_KEY,
33
+ environment=PINECONE_API_ENV)
34
+
35
+ index_name="medical-bot"'''
36
+
37
+ embeddings = download_hugging_face_embeddings()
38
+ # Load the FAISS vector database
39
+
40
+ # also i change here
41
+ # db = FAISS.load_local(DB_FAISS_PATH, embeddings)
42
+ DB_FAISS_PATH = r'G:\Chatbot\data\vector'
43
+ print("vector_base is loading from the folder")
44
+ db = FAISS.load_local(DB_FAISS_PATH, embeddings,
45
+ allow_dangerous_deserialization=True)
46
+ # Loading the index
47
+ # db = FAISS.load_local(r"G:\Chatbot\DB_FAISS_PATH",embeddings, allow_dangerous_deserialization=True)
48
+
49
+
50
+ # docsearch=Pinecone.from_existing_index(index_name, embeddings)
51
+
52
+ # Create a ChatPromptTemplate
53
+ prompt = ChatPromptTemplate.from_template(prompt_template)
54
+
55
+ chain_type_kwargs = {"prompt": prompt}
56
+
57
+ '''PROMPT = PromptTemplate(template=prompt_template,
58
+ input_variables=["context", "question"])
59
+
60
+ chain_type_kwargs = {"prompt": PROMPT}'''
61
+
62
+ '''llm = CTransformers(model=r"G:\Chatbot\model\llama-2-7b-chat.ggmlv3.q4_0.bin",
63
+ model_type="llama",
64
+ config={'max_new_tokens': 512,
65
+ 'temperature': 0.8})'''
66
+
67
+ # Initialize the LLM
68
+ # llm = ChatGroq(groq_api_key=groq_api_key, model_name="Llama3-8b-8192")
69
+ # groq_api_key = ('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')
70
+ # Load the GROQ and OpenAI API keys
71
+ groq_api_key = os.getenv('GROQ_API_KEY')
72
+ # os.environ["GOOGLE_API_KEY"] = os.getenv("GOOGLE_API_KEY")
73
+ # Initialize the LLM
74
+ llm = ChatGroq(groq_api_key=groq_api_key,
75
+ model_name="Llama3-8b-8192")
76
+
77
+
78
+ qa = RetrievalQA.from_chain_type(
79
+ llm=llm,
80
+ chain_type="stuff",
81
+ retriever=db.as_retriever(search_kwargs={'k': 2}),
82
+ return_source_documents=True,
83
+ chain_type_kwargs=chain_type_kwargs)
84
+
85
+
86
+ @app.route("/")
87
+ def index():
88
+ return render_template('chat.html')
89
+
90
+
91
+ @app.route("/get", methods=["GET", "POST"])
92
+ def chat():
93
+ msg = request.form["msg"]
94
+ input = msg
95
+ print(input)
96
+ result = qa({"query": input})
97
+ print("Response : ", result["result"])
98
+ return str(result["result"])
99
+
100
+
101
+ if __name__ == '__main__':
102
+ app.run(host="0.0.0.0", port=8080, debug=True)
requirements.txt ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ctransformers==0.2.5
2
+ #sentence-transformers==2.2.2
3
+ faiss-cpu
4
+ #langchain==0.0.225
5
+ flask
6
+ pypdf
7
+ python-dotenv
8
+ gradio
9
+ #faiss-cpu
10
+ sentence-transformers
11
+ langchain_community
12
+ langchain
13
+ langchain_groq
14
+ langchain_openai
15
+
16
+ -e .