Spaces:
Runtime error
Runtime error
Upload files
Browse files- DB/DB_all/chroma-collections.parquet +3 -0
- DB/DB_all/chroma-embeddings.parquet +3 -0
- DB/DB_all/index/id_to_uuid_61c24b03-a8f4-4d40-bc30-7f650769cd22.pkl +3 -0
- DB/DB_all/index/index_61c24b03-a8f4-4d40-bc30-7f650769cd22.bin +3 -0
- DB/DB_all/index/index_metadata_61c24b03-a8f4-4d40-bc30-7f650769cd22.pkl +3 -0
- DB/DB_all/index/uuid_to_id_61c24b03-a8f4-4d40-bc30-7f650769cd22.pkl +3 -0
- DB/DB_frankl/chroma-collections.parquet +3 -0
- DB/DB_frankl/chroma-embeddings.parquet +3 -0
- DB/DB_frankl/index/id_to_uuid_62717c7e-f4cc-4694-9c9d-1ecff6d90992.pkl +3 -0
- DB/DB_frankl/index/index_62717c7e-f4cc-4694-9c9d-1ecff6d90992.bin +3 -0
- DB/DB_frankl/index/index_metadata_62717c7e-f4cc-4694-9c9d-1ecff6d90992.pkl +3 -0
- DB/DB_frankl/index/uuid_to_id_62717c7e-f4cc-4694-9c9d-1ecff6d90992.pkl +3 -0
- DB/DB_inst/chroma-collections.parquet +3 -0
- DB/DB_inst/chroma-embeddings.parquet +3 -0
- DB/DB_inst/index/id_to_uuid_391a18fb-29fa-4b72-8de2-00ee2d6c3c1b.pkl +3 -0
- DB/DB_inst/index/index_391a18fb-29fa-4b72-8de2-00ee2d6c3c1b.bin +3 -0
- DB/DB_inst/index/index_metadata_391a18fb-29fa-4b72-8de2-00ee2d6c3c1b.pkl +3 -0
- DB/DB_inst/index/uuid_to_id_391a18fb-29fa-4b72-8de2-00ee2d6c3c1b.pkl +3 -0
- app.py +129 -0
- auth_config.yaml +13 -0
- backend.py +122 -0
- constants.py +23 -0
- db.py +21 -0
- htmlTemplates.py +33 -0
- requirements.txt +13 -0
- sources.py +101 -0
DB/DB_all/chroma-collections.parquet
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a7ead729f74ca0f8dc5408f9388eae0768fad962c2f658022f2c9650daf52f43
|
3 |
+
size 557
|
DB/DB_all/chroma-embeddings.parquet
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:5b75ea6502cbdf4d33e505f63fefadc476430a9b900737294983fcadb08aa52f
|
3 |
+
size 83062356
|
DB/DB_all/index/id_to_uuid_61c24b03-a8f4-4d40-bc30-7f650769cd22.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3144550db91b875a9334cd90ee67f8a88ffcbb1bc73a49a4543e588d855f8262
|
3 |
+
size 524025
|
DB/DB_all/index/index_61c24b03-a8f4-4d40-bc30-7f650769cd22.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7572cf9ff552a321a66ace754ca7e09596b472b587a5f119be375fe3287fb37a
|
3 |
+
size 51939940
|
DB/DB_all/index/index_metadata_61c24b03-a8f4-4d40-bc30-7f650769cd22.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3187ed0663ab649d4e870003dfbc3d7324b917efb8640fc1ef38f11715003ed3
|
3 |
+
size 74
|
DB/DB_all/index/uuid_to_id_61c24b03-a8f4-4d40-bc30-7f650769cd22.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ab6f7d92e372a27943dd4149b45c21fb6d619d63c60b3471c9487998ae7606bd
|
3 |
+
size 612700
|
DB/DB_frankl/chroma-collections.parquet
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:98b52f6ec521eaa3ae0ee1acfc13bf8480370d9279371a02a952cf7f0fe5abcc
|
3 |
+
size 557
|
DB/DB_frankl/chroma-embeddings.parquet
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3cc3a79a5ef368d5bc03f95a5825885d90a62108da11ed41e1cdebc4fe2e11aa
|
3 |
+
size 4781096
|
DB/DB_frankl/index/id_to_uuid_62717c7e-f4cc-4694-9c9d-1ecff6d90992.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7d7c946bcc40b0e7bf76155f09a92c753fef8259d9c09a2336ba5c3c63f7d189
|
3 |
+
size 29755
|
DB/DB_frankl/index/index_62717c7e-f4cc-4694-9c9d-1ecff6d90992.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:44909a57988273fb838ef8e84550c5a810039cdf76696cbb176af3caa627507f
|
3 |
+
size 2969532
|
DB/DB_frankl/index/index_metadata_62717c7e-f4cc-4694-9c9d-1ecff6d90992.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:0c962a970ca1e1d40b97e0d8467320d21a22bce5b7975f5d51770d638817b817
|
3 |
+
size 74
|
DB/DB_frankl/index/uuid_to_id_62717c7e-f4cc-4694-9c9d-1ecff6d90992.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:eebe3c211e23643a279ebdcafb841cbc9260a501d4ab465dfdff84cf701184af
|
3 |
+
size 34797
|
DB/DB_inst/chroma-collections.parquet
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:08a41f49335723fdd4d98c38ee57aaceabc0c20a869355f7db44cbbad4b3a13a
|
3 |
+
size 557
|
DB/DB_inst/chroma-embeddings.parquet
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:1f3738f1686fbe43c1b25fbc3a4204ed55bb0d9d89211a6d7e012e156055b64b
|
3 |
+
size 78277404
|
DB/DB_inst/index/id_to_uuid_391a18fb-29fa-4b72-8de2-00ee2d6c3c1b.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:db5adf662c6f79e04e9d8b63aaf53cd2a1845521eefba0c2ec20d28defe692b2
|
3 |
+
size 493945
|
DB/DB_inst/index/index_391a18fb-29fa-4b72-8de2-00ee2d6c3c1b.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:329eb0c905035c5ff573bcaae3f7420016877b64ea0ccc577e046dc60436830f
|
3 |
+
size 48970640
|
DB/DB_inst/index/index_metadata_391a18fb-29fa-4b72-8de2-00ee2d6c3c1b.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ccde5de99e38ed6ca1de89f0c41b30446558b9e79366087a907574c397455096
|
3 |
+
size 74
|
DB/DB_inst/index/uuid_to_id_391a18fb-29fa-4b72-8de2-00ee2d6c3c1b.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7043c4712ef55e123b6e66742932ec002c00f57870cdcbd2efa8d362a527fa5a
|
3 |
+
size 577653
|
app.py
ADDED
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import time
|
2 |
+
from os.path import basename
|
3 |
+
import yaml
|
4 |
+
|
5 |
+
import streamlit as st
|
6 |
+
from yaml.loader import SafeLoader
|
7 |
+
from streamlit_authenticator import Authenticate
|
8 |
+
|
9 |
+
from htmlTemplates import css, bot_template, user_template
|
10 |
+
from sources import sources_ref
|
11 |
+
import constants
|
12 |
+
import backend
|
13 |
+
|
14 |
+
|
15 |
+
import torch
|
16 |
+
print(f"Is CUDA available: {torch.cuda.is_available()}")
|
17 |
+
# True
|
18 |
+
if torch.cuda.is_available():
|
19 |
+
print(f"CUDA device: {torch.cuda.get_device_name(torch.cuda.current_device())}")
|
20 |
+
# Tesla T4
|
21 |
+
|
22 |
+
|
23 |
+
def on_query():
|
24 |
+
constants.question = st.session_state.InputText
|
25 |
+
st.session_state.InputText = ""
|
26 |
+
|
27 |
+
|
28 |
+
def handle_userinput(user_question):
|
29 |
+
res = st.session_state.model({'query': user_question})
|
30 |
+
answer, docs = res["result"], res["source_documents"]
|
31 |
+
source = sources_ref[basename(docs[0].metadata["source"])]
|
32 |
+
|
33 |
+
st.session_state.chat_history.insert(0, user_question)
|
34 |
+
st.session_state.chat_history.insert(1, answer + "<br><br><em>Source: " + source)
|
35 |
+
|
36 |
+
for i, message in enumerate(st.session_state.chat_history):
|
37 |
+
if i % 2 == 0:
|
38 |
+
st.write(user_template.replace("{{MSG}}", message), unsafe_allow_html=True)
|
39 |
+
else:
|
40 |
+
st.write(bot_template.replace("{{MSG}}", message), unsafe_allow_html=True)
|
41 |
+
|
42 |
+
|
43 |
+
def login_page():
|
44 |
+
st.set_page_config(page_title="logotherapyGPT",
|
45 |
+
page_icon=":books:")
|
46 |
+
|
47 |
+
with open('auth_config.yaml') as file:
|
48 |
+
config = yaml.load(file, Loader=SafeLoader)
|
49 |
+
|
50 |
+
authenticator = Authenticate(
|
51 |
+
config['credentials'],
|
52 |
+
config['cookie']['name'],
|
53 |
+
config['cookie']['key'],
|
54 |
+
config['cookie']['expiry_days'],
|
55 |
+
config['preauthorized']
|
56 |
+
)
|
57 |
+
|
58 |
+
name, authentication_status, username = authenticator.login('Login', 'main')
|
59 |
+
|
60 |
+
if authentication_status:
|
61 |
+
|
62 |
+
if 'db_clicked' not in st.session_state:
|
63 |
+
st.session_state.db_clicked = False
|
64 |
+
|
65 |
+
placeholder_box = st.empty()
|
66 |
+
placeholder_button = st.empty()
|
67 |
+
placeholder_box.selectbox(
|
68 |
+
'Choose a Database',
|
69 |
+
("All", "Frankl's Works", "Journal of Search for Meaning"),
|
70 |
+
key="database"
|
71 |
+
)
|
72 |
+
placeholder_button.button(
|
73 |
+
"Enter",
|
74 |
+
on_click=db_button_clicked
|
75 |
+
)
|
76 |
+
|
77 |
+
if st.session_state.db_clicked:
|
78 |
+
placeholder_box.empty()
|
79 |
+
placeholder_button.empty()
|
80 |
+
main_page()
|
81 |
+
|
82 |
+
elif not authentication_status:
|
83 |
+
st.error('Username/password is incorrect')
|
84 |
+
|
85 |
+
elif authentication_status is None:
|
86 |
+
st.warning('Please enter your username and password')
|
87 |
+
|
88 |
+
|
89 |
+
def db_button_clicked():
|
90 |
+
st.session_state.db_clicked = True
|
91 |
+
|
92 |
+
|
93 |
+
def main_page():
|
94 |
+
st.write(css, unsafe_allow_html=True)
|
95 |
+
|
96 |
+
st.markdown("# logotherapyGPT")
|
97 |
+
st.markdown("Chosen Database: " + st.session_state.database)
|
98 |
+
st.markdown("An AI chatbot to quickly access logotherapy information. Trained on the works of Viktor "
|
99 |
+
"Frankl and The International Forum for Logotherapy.")
|
100 |
+
|
101 |
+
if "model" not in st.session_state:
|
102 |
+
with st.spinner("Loading Database..."):
|
103 |
+
st.session_state.model = backend.load_qa(st.session_state.database)
|
104 |
+
|
105 |
+
if "chat_history" not in st.session_state:
|
106 |
+
st.session_state.chat_history = []
|
107 |
+
|
108 |
+
st.text_input(
|
109 |
+
"Input",
|
110 |
+
label_visibility="collapsed",
|
111 |
+
placeholder="Ask a Question...",
|
112 |
+
on_change=on_query,
|
113 |
+
key="InputText"
|
114 |
+
)
|
115 |
+
|
116 |
+
print(constants.question)
|
117 |
+
|
118 |
+
if st.session_state.model is not None and constants.question is not None:
|
119 |
+
start = time.time()
|
120 |
+
|
121 |
+
with st.spinner("Processing..."):
|
122 |
+
handle_userinput(constants.question)
|
123 |
+
|
124 |
+
end = time.time()
|
125 |
+
print(f"\n> Answer (took {round(end - start, 2)} s.):")
|
126 |
+
|
127 |
+
|
128 |
+
if __name__ == '__main__':
|
129 |
+
login_page()
|
auth_config.yaml
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
credentials:
|
2 |
+
usernames:
|
3 |
+
user:
|
4 |
+
email: [email protected]
|
5 |
+
name: User
|
6 |
+
password: $2b$12$x.TrOZp0U38wdAkZX3i29eB0yCt/z2pV55DKfU3836rC/wtzqRfgi
|
7 |
+
|
8 |
+
cookie:
|
9 |
+
expiry_days: 0
|
10 |
+
key: random_signature_key # Must be string
|
11 |
+
name: random_cookie_name
|
12 |
+
preauthorized:
|
13 |
+
emails:
|
backend.py
ADDED
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import time
|
2 |
+
import streamlit as st
|
3 |
+
import torch
|
4 |
+
from langchain.chains import RetrievalQA
|
5 |
+
from langchain.embeddings import HuggingFaceInstructEmbeddings
|
6 |
+
from langchain.llms import HuggingFacePipeline
|
7 |
+
from constants import EMBEDDING_MODEL_NAME, db_all, db_frankl, db_inst
|
8 |
+
from langchain.vectorstores import Chroma
|
9 |
+
from transformers import (
|
10 |
+
AutoModelForCausalLM,
|
11 |
+
AutoTokenizer,
|
12 |
+
GenerationConfig,
|
13 |
+
LlamaForCausalLM,
|
14 |
+
LlamaTokenizer,
|
15 |
+
pipeline,
|
16 |
+
)
|
17 |
+
|
18 |
+
|
19 |
+
@st.cache_resource(show_spinner=False)
|
20 |
+
def load_model(device_type, model_id):
|
21 |
+
if device_type.lower() == "cuda": # cuda
|
22 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
23 |
+
|
24 |
+
model = AutoModelForCausalLM.from_pretrained(
|
25 |
+
model_id,
|
26 |
+
device_map="auto",
|
27 |
+
torch_dtype=torch.float16,
|
28 |
+
low_cpu_mem_usage=True,
|
29 |
+
trust_remote_code=True,
|
30 |
+
)
|
31 |
+
model.tie_weights()
|
32 |
+
else: # cpu
|
33 |
+
tokenizer = LlamaTokenizer.from_pretrained(model_id)
|
34 |
+
model = LlamaForCausalLM.from_pretrained(model_id)
|
35 |
+
|
36 |
+
generation_config = GenerationConfig.from_pretrained(model_id)
|
37 |
+
|
38 |
+
pipe = pipeline(
|
39 |
+
"text-generation",
|
40 |
+
model=model,
|
41 |
+
tokenizer=tokenizer,
|
42 |
+
max_length=2048,
|
43 |
+
temperature=0.1,
|
44 |
+
top_p=0.95,
|
45 |
+
repetition_penalty=1.5,
|
46 |
+
generation_config=generation_config,
|
47 |
+
)
|
48 |
+
|
49 |
+
local_llm = HuggingFacePipeline(pipeline=pipe)
|
50 |
+
|
51 |
+
return local_llm
|
52 |
+
|
53 |
+
|
54 |
+
@st.cache_data(persist=True, show_spinner=False)
|
55 |
+
def get_embeddings():
|
56 |
+
if torch.cuda.is_available():
|
57 |
+
device_type = "cuda"
|
58 |
+
else:
|
59 |
+
device_type = "cpu"
|
60 |
+
|
61 |
+
embeddings = HuggingFaceInstructEmbeddings(
|
62 |
+
model_name=EMBEDDING_MODEL_NAME,
|
63 |
+
model_kwargs={"device": device_type}
|
64 |
+
)
|
65 |
+
|
66 |
+
return embeddings
|
67 |
+
|
68 |
+
|
69 |
+
def get_llm():
|
70 |
+
if torch.cuda.is_available():
|
71 |
+
device_type = "cuda"
|
72 |
+
else:
|
73 |
+
device_type = "cpu"
|
74 |
+
|
75 |
+
model_id = "psmathur/orca_mini_3b"
|
76 |
+
|
77 |
+
llm = load_model(
|
78 |
+
device_type,
|
79 |
+
model_id=model_id
|
80 |
+
)
|
81 |
+
return llm
|
82 |
+
|
83 |
+
|
84 |
+
def load_qa(db_option):
|
85 |
+
db_instance = db_inst
|
86 |
+
|
87 |
+
match db_option:
|
88 |
+
case "All":
|
89 |
+
db_instance = db_all
|
90 |
+
print("loading db_all")
|
91 |
+
case "Frankl's Works":
|
92 |
+
db_instance = db_frankl
|
93 |
+
print("loading db_frankl")
|
94 |
+
case "Journal of Search for Meaning":
|
95 |
+
db_instance = db_inst
|
96 |
+
print("loading db_inst")
|
97 |
+
|
98 |
+
load_start = time.time()
|
99 |
+
|
100 |
+
embeddings = get_embeddings()
|
101 |
+
|
102 |
+
db = Chroma(
|
103 |
+
persist_directory=db_instance.get_directory(),
|
104 |
+
embedding_function=embeddings,
|
105 |
+
client_settings=db_instance.get_chroma_settings(),
|
106 |
+
)
|
107 |
+
|
108 |
+
retriever = db.as_retriever()
|
109 |
+
|
110 |
+
llm = get_llm()
|
111 |
+
|
112 |
+
qa = RetrievalQA.from_chain_type(
|
113 |
+
llm=llm,
|
114 |
+
chain_type="stuff",
|
115 |
+
retriever=retriever,
|
116 |
+
return_source_documents=True,
|
117 |
+
)
|
118 |
+
|
119 |
+
load_end = time.time()
|
120 |
+
print(f"\n> Completed Initial Load (took {round(load_end - load_start, 2)} s.)")
|
121 |
+
|
122 |
+
return qa
|
constants.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from langchain.document_loaders import PDFMinerLoader, TextLoader
|
3 |
+
from db import db
|
4 |
+
|
5 |
+
question = None
|
6 |
+
|
7 |
+
root = os.path.dirname(os.path.realpath(__file__))
|
8 |
+
|
9 |
+
SOURCE_DIRECTORY = f"{root}/SOURCE_DOCUMENTS"
|
10 |
+
|
11 |
+
db_all = db("all", root)
|
12 |
+
db_frankl = db("frankl", root)
|
13 |
+
db_inst = db("inst", root)
|
14 |
+
|
15 |
+
INGEST_THREADS = os.cpu_count()
|
16 |
+
|
17 |
+
DOCUMENT_MAP = {
|
18 |
+
".txt": TextLoader,
|
19 |
+
".pdf": PDFMinerLoader,
|
20 |
+
}
|
21 |
+
|
22 |
+
# Default Instructor Model
|
23 |
+
EMBEDDING_MODEL_NAME = "hkunlp/instructor-large"
|
db.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from chromadb.config import Settings
|
2 |
+
|
3 |
+
|
4 |
+
class db:
|
5 |
+
def __init__(self, name, root):
|
6 |
+
self.name = name
|
7 |
+
self.directory = f"{root}/DB/DB_{name}"
|
8 |
+
self.chroma_settings = Settings(
|
9 |
+
chroma_db_impl="duckdb+parquet",
|
10 |
+
persist_directory=self.directory,
|
11 |
+
anonymized_telemetry=False
|
12 |
+
)
|
13 |
+
|
14 |
+
def get_name(self):
|
15 |
+
return self.name
|
16 |
+
|
17 |
+
def get_directory(self):
|
18 |
+
return self.directory
|
19 |
+
|
20 |
+
def get_chroma_settings(self):
|
21 |
+
return self.chroma_settings
|
htmlTemplates.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
css = '''
|
2 |
+
<style>
|
3 |
+
.chat-message {
|
4 |
+
padding: 1.5rem;
|
5 |
+
border-radius: 0.5rem;
|
6 |
+
margin-bottom: 1rem;
|
7 |
+
display: flex
|
8 |
+
}
|
9 |
+
.chat-message.user {
|
10 |
+
background-color: #554763
|
11 |
+
}
|
12 |
+
.chat-message.bot {
|
13 |
+
background-color: #736383;
|
14 |
+
margin-bottom: 2.5rem;
|
15 |
+
}
|
16 |
+
.chat-message .message {
|
17 |
+
width: 100%;
|
18 |
+
padding: 0 1.5rem;
|
19 |
+
color: #fff;
|
20 |
+
}
|
21 |
+
'''
|
22 |
+
|
23 |
+
bot_template = '''
|
24 |
+
<div class="chat-message bot">
|
25 |
+
<div class="message">{{MSG}}</em></div>
|
26 |
+
</div>
|
27 |
+
'''
|
28 |
+
|
29 |
+
user_template = '''
|
30 |
+
<div class="chat-message user">
|
31 |
+
<div class="message">{{MSG}}</div>
|
32 |
+
</div>
|
33 |
+
'''
|
requirements.txt
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
PyYAML~=6.0.1
|
3 |
+
streamlit~=1.25.0
|
4 |
+
click~=8.1.6
|
5 |
+
|
6 |
+
--extra-index-url https://download.pytorch.org/whl/cu113
|
7 |
+
torch
|
8 |
+
transformers~=4.31.0
|
9 |
+
streamlit_authenticator
|
10 |
+
langchain
|
11 |
+
chromadb==0.3.22
|
12 |
+
InstructorEmbedding
|
13 |
+
sentence-transformers
|
sources.py
ADDED
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
sources_ref = {
|
2 |
+
"book_000.pdf": "Frankl, V. E. (2006). Man’s Search for Meaning. Beacon Press.",
|
3 |
+
"book_001.pdf": "Frankl, V. E., Winston, C., & Winston, R. (2019). The Doctor and the Soul: From Psychotherapy to Logotherapy. Vintage Books.",
|
4 |
+
"book_002.pdf": "Frankl, V. E. (2004). On the Theory and Therapy of Mental Disorders: An Introduction to Logotherapy and Existential Analysis. Brunner-Routledge.",
|
5 |
+
"book_003.pdf": "Frankl, V. E., & Crumbaugh, J. C. (1967). Psychotherapy and Existentialism. Simon & Schuster.",
|
6 |
+
"book_004.pdf": "Frankl, V. E. (1988). The Will to Meaning: Foundations and Applications of Logotherapy. Penguin.",
|
7 |
+
"book_005.pdf": "Frankl, V. E. (2002). The Unheard Cry for Meaning: Psychotherapy and Humanism. Washington Square Press/Pocket Books.",
|
8 |
+
"book_006.pdf": "Frankl, V. E. (2008). Recollections: An Autobiography. Basic Books.",
|
9 |
+
"book_007.pdf": "Frankl, V. E., & Emil, V. (1997). Man’s Search for Ultimate Meaning. Insight Books.",
|
10 |
+
"book_008.pdf": "Frankl, V. E., Goleman, D., & Franz Vesely. (2020). Yes to Life : In Spite of Everything. Beacon Press.",
|
11 |
+
"journal_002_1.txt": "Journal of Search for Meaning, Volume 02 Number 1 (Spring 1979) The International Forum for Logotherapy.",
|
12 |
+
"journal_002_2.txt": "Journal of Search for Meaning, Volume 02 Number 2 (Autumn 1979) The International Forum for Logotherapy.",
|
13 |
+
"journal_003_1.txt": "Journal of Search for Meaning, Volume 03 Number 1 (Spring 1980) The International Forum for Logotherapy.",
|
14 |
+
"journal_003_2.txt": "Journal of Search for Meaning, Volume 03 Number 2 (Autumn 1980) The International Forum for Logotherapy.",
|
15 |
+
"journal_004_1.txt": "Journal of Search for Meaning, Volume 04 Number 1 (Spring 1981) The International Forum for Logotherapy.",
|
16 |
+
"journal_004_2.txt": "Journal of Search for Meaning, Volume 04 Number 2 (Autumn 1981) The International Forum for Logotherapy.",
|
17 |
+
"journal_005_1.txt": "Journal of Search for Meaning, Volume 05 Number 1 (Spring 1982) The International Forum for Logotherapy.",
|
18 |
+
"journal_005_2.txt": "Journal of Search for Meaning, Volume 05 Number 2 (Autumn 1982) The International Forum for Logotherapy.",
|
19 |
+
"journal_006_1.txt": "Journal of Search for Meaning, Volume 06 Number 1 (Spring 1983) The International Forum for Logotherapy.",
|
20 |
+
"journal_006_2.txt": "Journal of Search for Meaning, Volume 06 Number 2 (Autumn 1983) The International Forum for Logotherapy.",
|
21 |
+
"journal_007_1.txt": "Journal of Search for Meaning, Volume 07 Number 1 (Spring 1984) The International Forum for Logotherapy.",
|
22 |
+
"journal_007_2.txt": "Journal of Search for Meaning, Volume 07 Number 2 (Autumn 1984) The International Forum for Logotherapy.",
|
23 |
+
"journal_008_1.txt": "Journal of Search for Meaning, Volume 08 Number 1 (Spring 1985) The International Forum for Logotherapy.",
|
24 |
+
"journal_008_2.txt": "Journal of Search for Meaning, Volume 08 Number 2 (Autumn 1985) The International Forum for Logotherapy.",
|
25 |
+
"journal_009_1.txt": "Journal of Search for Meaning, Volume 09 Number 1 (Spring 1986) The International Forum for Logotherapy.",
|
26 |
+
"journal_009_2.txt": "Journal of Search for Meaning, Volume 09 Number 2 (Autumn 1986) The International Forum for Logotherapy.",
|
27 |
+
"journal_010_1.txt": "Journal of Search for Meaning, Volume 10 Number 1 (Spring 1987) The International Forum for Logotherapy.",
|
28 |
+
"journal_010_2.txt": "Journal of Search for Meaning, Volume 10 Number 2 (Autumn 1987) The International Forum for Logotherapy.",
|
29 |
+
"journal_011_1.txt": "Journal of Search for Meaning, Volume 11 Number 1 (Spring 1988) The International Forum for Logotherapy.",
|
30 |
+
"journal_011_2.txt": "Journal of Search for Meaning, Volume 11 Number 2 (Autumn 1988) The International Forum for Logotherapy.",
|
31 |
+
"journal_012_1.txt": "Journal of Search for Meaning, Volume 12 Number 1 (Spring 1989) The International Forum for Logotherapy.",
|
32 |
+
"journal_012_2.txt": "Journal of Search for Meaning, Volume 12 Number 2 (Autumn 1989) The International Forum for Logotherapy.",
|
33 |
+
"journal_013_1.txt": "Journal of Search for Meaning, Volume 13 Number 1 (Spring 1990) The International Forum for Logotherapy.",
|
34 |
+
"journal_013_2.txt": "Journal of Search for Meaning, Volume 13 Number 2 (Autumn 1990) The International Forum for Logotherapy.",
|
35 |
+
"journal_014_1.txt": "Journal of Search for Meaning, Volume 14 Number 1 (Spring 1991) The International Forum for Logotherapy.",
|
36 |
+
"journal_014_2.txt": "Journal of Search for Meaning, Volume 14 Number 2 (Autumn 1991) The International Forum for Logotherapy.",
|
37 |
+
"journal_015_1.txt": "Journal of Search for Meaning, Volume 15 Number 1 (Spring 1992) The International Forum for Logotherapy.",
|
38 |
+
"journal_015_2.txt": "Journal of Search for Meaning, Volume 15 Number 2 (Autumn 1992) The International Forum for Logotherapy.",
|
39 |
+
"journal_016_1.txt": "Journal of Search for Meaning, Volume 16 Number 1 (Spring 1993) The International Forum for Logotherapy.",
|
40 |
+
"journal_016_2.txt": "Journal of Search for Meaning, Volume 16 Number 2 (Autumn 1993) The International Forum for Logotherapy.",
|
41 |
+
"journal_017_1.txt": "Journal of Search for Meaning, Volume 17 Number 1 (Spring 1994) The International Forum for Logotherapy.",
|
42 |
+
"journal_017_2.txt": "Journal of Search for Meaning, Volume 17 Number 2 (Autumn 1994) The International Forum for Logotherapy.",
|
43 |
+
"journal_018_1.txt": "Journal of Search for Meaning, Volume 18 Number 1 (Spring 1995) The International Forum for Logotherapy.",
|
44 |
+
"journal_018_2.txt": "Journal of Search for Meaning, Volume 18 Number 2 (Autumn 1995) The International Forum for Logotherapy.",
|
45 |
+
"journal_019_1.txt": "Journal of Search for Meaning, Volume 19 Number 1 (Spring 1996) The International Forum for Logotherapy.",
|
46 |
+
"journal_019_2.txt": "Journal of Search for Meaning, Volume 19 Number 2 (Autumn 1996) The International Forum for Logotherapy.",
|
47 |
+
"journal_020_1.txt": "Journal of Search for Meaning, Volume 20 Number 1 (Spring 1997) The International Forum for Logotherapy.",
|
48 |
+
"journal_020_2.txt": "Journal of Search for Meaning, Volume 20 Number 2 (Autumn 1997) The International Forum for Logotherapy.",
|
49 |
+
"journal_021_1.txt": "Journal of Search for Meaning, Volume 21 Number 1 (Spring 1998) The International Forum for Logotherapy.",
|
50 |
+
"journal_021_2.txt": "Journal of Search for Meaning, Volume 21 Number 2 (Autumn 1998) The International Forum for Logotherapy.",
|
51 |
+
"journal_022_1.txt": "Journal of Search for Meaning, Volume 22 Number 1 (Spring 1999) The International Forum for Logotherapy.",
|
52 |
+
"journal_022_2.txt": "Journal of Search for Meaning, Volume 22 Number 2 (Autumn 1999) The International Forum for Logotherapy.",
|
53 |
+
"journal_023_1.txt": "Journal of Search for Meaning, Volume 23 Number 1 (Spring 2000) The International Forum for Logotherapy.",
|
54 |
+
"journal_023_2.txt": "Journal of Search for Meaning, Volume 23 Number 2 (Autumn 2000) The International Forum for Logotherapy.",
|
55 |
+
"journal_024_1.txt": "Journal of Search for Meaning, Volume 24 Number 1 (Spring 2001) The International Forum for Logotherapy.",
|
56 |
+
"journal_024_2.txt": "Journal of Search for Meaning, Volume 24 Number 2 (Autumn 2001) The International Forum for Logotherapy.",
|
57 |
+
"journal_025_1.txt": "Journal of Search for Meaning, Volume 25 Number 1 (Spring 2002) The International Forum for Logotherapy.",
|
58 |
+
"journal_025_2.txt": "Journal of Search for Meaning, Volume 25 Number 2 (Autumn 2002) The International Forum for Logotherapy.",
|
59 |
+
"journal_026_1.txt": "Journal of Search for Meaning, Volume 26 Number 1 (Spring 2003) The International Forum for Logotherapy.",
|
60 |
+
"journal_026_2.txt": "Journal of Search for Meaning, Volume 26 Number 2 (Autumn 2003) The International Forum for Logotherapy.",
|
61 |
+
"journal_027_1.txt": "Journal of Search for Meaning, Volume 27 Number 1 (Spring 2004) The International Forum for Logotherapy.",
|
62 |
+
"journal_027_2.txt": "Journal of Search for Meaning, Volume 27 Number 2 (Autumn 2004) The International Forum for Logotherapy.",
|
63 |
+
"journal_028_1.txt": "Journal of Search for Meaning, Volume 28 Number 1 (Spring 2005) The International Forum for Logotherapy.",
|
64 |
+
"journal_028_2.txt": "Journal of Search for Meaning, Volume 28 Number 2 (Autumn 2005) The International Forum for Logotherapy.",
|
65 |
+
"journal_029_1.txt": "Journal of Search for Meaning, Volume 29 Number 1 (Spring 2006) The International Forum for Logotherapy.",
|
66 |
+
"journal_029_2.txt": "Journal of Search for Meaning, Volume 29 Number 2 (Autumn 2006) The International Forum for Logotherapy.",
|
67 |
+
"journal_030_1.txt": "Journal of Search for Meaning, Volume 30 Number 1 (Spring 2007) The International Forum for Logotherapy.",
|
68 |
+
"journal_030_2.txt": "Journal of Search for Meaning, Volume 30 Number 2 (Autumn 2007) The International Forum for Logotherapy.",
|
69 |
+
"journal_031_1.txt": "Journal of Search for Meaning, Volume 31 Number 1 (Spring 2008) The International Forum for Logotherapy.",
|
70 |
+
"journal_031_2.txt": "Journal of Search for Meaning, Volume 31 Number 2 (Autumn 2008) The International Forum for Logotherapy.",
|
71 |
+
"journal_032_1.txt": "Journal of Search for Meaning, Volume 32 Number 1 (Spring 2009) The International Forum for Logotherapy.",
|
72 |
+
"journal_032_2.txt": "Journal of Search for Meaning, Volume 32 Number 2 (Autumn 2009) The International Forum for Logotherapy.",
|
73 |
+
"journal_033_1.txt": "Journal of Search for Meaning, Volume 33 Number 1 (Spring 2010) The International Forum for Logotherapy.",
|
74 |
+
"journal_033_2.txt": "Journal of Search for Meaning, Volume 33 Number 2 (Autumn 2010) The International Forum for Logotherapy.",
|
75 |
+
"journal_034_1.pdf": "Journal of Search for Meaning, Volume 34 Number 1 (Spring 2011) The International Forum for Logotherapy.",
|
76 |
+
"journal_034_2.pdf": "Journal of Search for Meaning, Volume 34 Number 2 (Autumn 2011) The International Forum for Logotherapy.",
|
77 |
+
"journal_035_1.pdf": "Journal of Search for Meaning, Volume 35 Number 1 (Spring 2012) The International Forum for Logotherapy.",
|
78 |
+
"journal_035_2.pdf": "Journal of Search for Meaning, Volume 35 Number 2 (Autumn 2012) The International Forum for Logotherapy.",
|
79 |
+
"journal_036_1.pdf": "Journal of Search for Meaning, Volume 36 Number 1 (Spring 2013) The International Forum for Logotherapy.",
|
80 |
+
"journal_036_2.pdf": "Journal of Search for Meaning, Volume 36 Number 2 (Autumn 2013) The International Forum for Logotherapy.",
|
81 |
+
"journal_037_1.pdf": "Journal of Search for Meaning, Volume 37 Number 1 (Spring 2014) The International Forum for Logotherapy.",
|
82 |
+
"journal_037_2.pdf": "Journal of Search for Meaning, Volume 37 Number 2 (Autumn 2014) The International Forum for Logotherapy.",
|
83 |
+
"journal_038_1.pdf": "Journal of Search for Meaning, Volume 38 Number 1 (Spring 2015) The International Forum for Logotherapy.",
|
84 |
+
"journal_038_2.pdf": "Journal of Search for Meaning, Volume 38 Number 2 (Autumn 2015) The International Forum for Logotherapy.",
|
85 |
+
"journal_039_1.pdf": "Journal of Search for Meaning, Volume 39 Number 1 (Spring 2016) The International Forum for Logotherapy.",
|
86 |
+
"journal_039_2.pdf": "Journal of Search for Meaning, Volume 39 Number 2 (Autumn 2016) The International Forum for Logotherapy.",
|
87 |
+
"journal_040_1.pdf": "Journal of Search for Meaning, Volume 40 Number 1 (Spring 2017) The International Forum for Logotherapy.",
|
88 |
+
"journal_040_2.pdf": "Journal of Search for Meaning, Volume 40 Number 2 (Autumn 2017) The International Forum for Logotherapy.",
|
89 |
+
"journal_041_1.pdf": "Journal of Search for Meaning, Volume 41 Number 1 (Spring 2018) The International Forum for Logotherapy.",
|
90 |
+
"journal_041_2.pdf": "Journal of Search for Meaning, Volume 41 Number 2 (Autumn 2018) The International Forum for Logotherapy.",
|
91 |
+
"journal_042_1.pdf": "Journal of Search for Meaning, Volume 42 Number 1 (Spring 2019) The International Forum for Logotherapy.",
|
92 |
+
"journal_042_2.pdf": "Journal of Search for Meaning, Volume 42 Number 2 (Autumn 2019) The International Forum for Logotherapy.",
|
93 |
+
"journal_043_1.pdf": "Journal of Search for Meaning, Volume 43 Number 1 (Spring 2020) The International Forum for Logotherapy.",
|
94 |
+
"journal_043_2.pdf": "Journal of Search for Meaning, Volume 43 Number 2 (Autumn 2020) The International Forum for Logotherapy.",
|
95 |
+
"journal_044_1.pdf": "Journal of Search for Meaning, Volume 44 Number 1 (Spring 2021) The International Forum for Logotherapy.",
|
96 |
+
"journal_044_2.pdf": "Journal of Search for Meaning, Volume 44 Number 2 (Autumn 2021) The International Forum for Logotherapy.",
|
97 |
+
"journal_045_1.pdf": "Journal of Search for Meaning, Volume 45 Number 1 (Spring 2022) The International Forum for Logotherapy.",
|
98 |
+
"journal_045_2.pdf": "Journal of Search for Meaning, Volume 45 Number 2 (Autumn 2022) The International Forum for Logotherapy.",
|
99 |
+
"journal_046_1.pdf": "Journal of Search for Meaning, Volume 46 Number 1 (Spring 2023) The International Forum for Logotherapy.",
|
100 |
+
"journal_046_2.pdf": "Journal of Search for Meaning, Volume 46 Number 2 (Autumn 2023) The International Forum for Logotherapy.",
|
101 |
+
}
|