Daoneeee commited on
Commit
887b79e
·
1 Parent(s): 080c05e

Update app.py

Browse files
Files changed (4) hide show
  1. app.py +153 -0
  2. facebook_chat.json +217 -0
  3. htmlTemplates.py +44 -0
  4. requirements.txt +14 -0
app.py ADDED
@@ -0,0 +1,153 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from dotenv import load_dotenv
3
+ from PyPDF2 import PdfReader
4
+ from langchain.text_splitter import CharacterTextSplitter, RecursiveCharacterTextSplitter
5
+ from langchain.embeddings import OpenAIEmbeddings, HuggingFaceInstructEmbeddings
6
+ from langchain.vectorstores import FAISS, Chroma
7
+ from langchain.embeddings import HuggingFaceEmbeddings # General embeddings from HuggingFace models.
8
+ from langchain.chat_models import ChatOpenAI
9
+ from langchain.memory import ConversationBufferMemory
10
+ from langchain.chains import ConversationalRetrievalChain
11
+ from htmlTemplates import css, bot_template, user_template
12
+ from langchain.llms import HuggingFaceHub, LlamaCpp, CTransformers # For loading transformer models.
13
+ from langchain.document_loaders import PyPDFLoader, TextLoader, JSONLoader, CSVLoader
14
+ import tempfile # 임시 파일을 생성하기 위한 라이브러리입니다.
15
+ import os
16
+
17
+
18
+ # PDF 문서로부터 텍스트를 추출하는 함수입니다.
19
+ def get_pdf_text(pdf_docs):
20
+ temp_dir = tempfile.TemporaryDirectory() # 임시 디렉토리를 생성합니다.
21
+ temp_filepath = os.path.join(temp_dir.name, pdf_docs.name) # 임시 파일 경로를 생성합니다.
22
+ with open(temp_filepath, "wb") as f: # 임시 파일을 바이너리 쓰기 모드로 엽니다.
23
+ f.write(pdf_docs.getvalue()) # PDF 문서의 내용을 임시 파일에 씁니다.
24
+ pdf_loader = PyPDFLoader(temp_filepath) # PyPDFLoader를 사용해 PDF를 로드합니다.
25
+ pdf_doc = pdf_loader.load() # 텍스트를 추출합니다.
26
+ return pdf_doc # 추출한 텍스트를 반환합니다.
27
+
28
+ # 과제
29
+ # 아래 텍스트 추출 함수를 작성
30
+
31
+ def get_text_file(docs):
32
+ pass
33
+
34
+
35
+ def get_csv_file(docs):
36
+ pass
37
+
38
+ def get_json_file(docs):
39
+ pass
40
+
41
+
42
+ # 문서들을 처리하여 텍스트 청크로 나누는 함수입니다.
43
+ def get_text_chunks(documents):
44
+ text_splitter = RecursiveCharacterTextSplitter(
45
+ chunk_size=1000, # 청크의 크기를 지정합니다.
46
+ chunk_overlap=200, # 청크 사이의 중복을 지정합니다.
47
+ length_function=len # 텍스트의 길이를 측정하는 함수를 지정합니다.
48
+ )
49
+
50
+ documents = text_splitter.split_documents(documents) # 문서들을 청크로 나눕니다
51
+ return documents # 나눈 청크를 반환합니다.
52
+
53
+
54
+ # 텍스트 청크들로부터 벡터 스토어를 생성하는 함수입니다.
55
+ def get_vectorstore(text_chunks):
56
+ # OpenAI 임베딩 모델을 로드합니다. (Embedding models - Ada v2)
57
+
58
+ embeddings = OpenAIEmbeddings()
59
+ vectorstore = FAISS.from_documents(text_chunks, embeddings) # FAISS 벡터 스토어를 생성합니다.
60
+
61
+ return vectorstore # 생성된 벡터 스토어를 반환합니다.
62
+
63
+
64
+ def get_conversation_chain(vectorstore):
65
+ gpt_model_name = 'gpt-3.5-turbo'
66
+ llm = ChatOpenAI(model_name = gpt_model_name) #gpt-3.5 모델 로드
67
+
68
+ # 대화 기록을 저장하기 위한 메모리를 생성합니다.
69
+ memory = ConversationBufferMemory(
70
+ memory_key='chat_history', return_messages=True)
71
+ # 대화 검색 체인을 생성합니다.
72
+ conversation_chain = ConversationalRetrievalChain.from_llm(
73
+ llm=llm,
74
+ retriever=vectorstore.as_retriever(),
75
+ memory=memory
76
+ )
77
+ return conversation_chain
78
+
79
+ # 사용자 입력을 처리하는 함수입니다.
80
+ def handle_userinput(user_question):
81
+ # 대화 체인을 사용하여 사용자 질문에 대한 응답을 생성합니다.
82
+ response = st.session_state.conversation({'question': user_question})
83
+ # 대화 기록을 저장합니다.
84
+ st.session_state.chat_history = response['chat_history']
85
+
86
+ for i, message in enumerate(st.session_state.chat_history):
87
+ if i % 2 == 0:
88
+ st.write(user_template.replace(
89
+ "{{MSG}}", message.content), unsafe_allow_html=True)
90
+ else:
91
+ st.write(bot_template.replace(
92
+ "{{MSG}}", message.content), unsafe_allow_html=True)
93
+
94
+
95
+ def main():
96
+ load_dotenv()
97
+ st.set_page_config(page_title="Chat with multiple Files",
98
+ page_icon=":books:")
99
+ st.write(css, unsafe_allow_html=True)
100
+
101
+ if "conversation" not in st.session_state:
102
+ st.session_state.conversation = None
103
+ if "chat_history" not in st.session_state:
104
+ st.session_state.chat_history = None
105
+
106
+ st.header("Chat with multiple Files :")
107
+ user_question = st.text_input("Ask a question about your documents:")
108
+ if user_question:
109
+ handle_userinput(user_question)
110
+
111
+ with st.sidebar:
112
+ openai_key = st.text_input("Paste your OpenAI API key (sk-...)")
113
+ if openai_key:
114
+ os.environ["OPENAI_API_KEY"] = openai_key
115
+
116
+ st.subheader("Your documents")
117
+ docs = st.file_uploader(
118
+ "Upload your PDFs here and click on 'Process'", accept_multiple_files=True)
119
+ if st.button("Process"):
120
+ with st.spinner("Processing"):
121
+ # get pdf text
122
+ doc_list = []
123
+
124
+ for file in docs:
125
+ print('file - type : ', file.type)
126
+ if file.type == 'text/plain':
127
+ # file is .txt
128
+ doc_list.extend(get_text_file(file))
129
+ elif file.type in ['application/octet-stream', 'application/pdf']:
130
+ # file is .pdf
131
+ doc_list.extend(get_pdf_text(file))
132
+ elif file.type == 'text/csv':
133
+ # file is .csv
134
+ doc_list.extend(get_csv_file(file))
135
+ elif file.type == 'application/json':
136
+ # file is .json
137
+ doc_list.extend(get_json_file(file))
138
+
139
+ # get the text chunks
140
+ text_chunks = get_text_chunks(doc_list)
141
+
142
+ # create vector store
143
+ vectorstore = get_vectorstore(text_chunks)
144
+
145
+ # create conversation chain
146
+ st.session_state.conversation = get_conversation_chain(
147
+ vectorstore)
148
+
149
+
150
+ if __name__ == '__main__':
151
+ main()
152
+
153
+
facebook_chat.json ADDED
@@ -0,0 +1,217 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!pip install jq
2
+
3
+ from langchain.document_loaders import JSONLoader
4
+
5
+ import json
6
+ from pathlib import Path
7
+ from pprint import pprint
8
+
9
+
10
+ file_path='./example_data/facebook_chat.json'
11
+ data = json.loads(Path(file_path).read_text())
12
+
13
+ pprint(data)
14
+
15
+ {'image': {'creation_timestamp': 1675549016, 'uri': 'image_of_the_chat.jpg'},
16
+ 'is_still_participant': True,
17
+ 'joinable_mode': {'link': '', 'mode': 1},
18
+ 'magic_words': [],
19
+ 'messages': [{'content': 'Bye!',
20
+ 'sender_name': 'User 2',
21
+ 'timestamp_ms': 1675597571851},
22
+ {'content': 'Oh no worries! Bye',
23
+ 'sender_name': 'User 1',
24
+ 'timestamp_ms': 1675597435669},
25
+ {'content': 'No Im sorry it was my mistake, the blue one is not '
26
+ 'for sale',
27
+ 'sender_name': 'User 2',
28
+ 'timestamp_ms': 1675596277579},
29
+ {'content': 'I thought you were selling the blue one!',
30
+ 'sender_name': 'User 1',
31
+ 'timestamp_ms': 1675595140251},
32
+ {'content': 'Im not interested in this bag. Im interested in the '
33
+ 'blue one!',
34
+ 'sender_name': 'User 1',
35
+ 'timestamp_ms': 1675595109305},
36
+ {'content': 'Here is $129',
37
+ 'sender_name': 'User 2',
38
+ 'timestamp_ms': 1675595068468},
39
+ {'photos': [{'creation_timestamp': 1675595059,
40
+ 'uri': 'url_of_some_picture.jpg'}],
41
+ 'sender_name': 'User 2',
42
+ 'timestamp_ms': 1675595060730},
43
+ {'content': 'Online is at least $100',
44
+ 'sender_name': 'User 2',
45
+ 'timestamp_ms': 1675595045152},
46
+ {'content': 'How much do you want?',
47
+ 'sender_name': 'User 1',
48
+ 'timestamp_ms': 1675594799696},
49
+ {'content': 'Goodmorning! $50 is too low.',
50
+ 'sender_name': 'User 2',
51
+ 'timestamp_ms': 1675577876645},
52
+ {'content': 'Hi! Im interested in your bag. Im offering $50. Let '
53
+ 'me know if you are interested. Thanks!',
54
+ 'sender_name': 'User 1',
55
+ 'timestamp_ms': 1675549022673}],
56
+ 'participants': [{'name': 'User 1'}, {'name': 'User 2'}],
57
+ 'thread_path': 'inbox/User 1 and User 2 chat',
58
+ 'title': 'User 1 and User 2 chat'}
59
+
60
+ loader = JSONLoader(
61
+ file_path='./example_data/facebook_chat.json',
62
+ jq_schema='.messages[].content',
63
+ text_content=False)
64
+
65
+ data = loader.load()
66
+
67
+ pprint(data)
68
+
69
+ [Document(page_content='Bye!', metadata={'source': '/Users/avsolatorio/WBG/langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat.json', 'seq_num': 1}),
70
+ Document(page_content='Oh no worries! Bye', metadata={'source': '/Users/avsolatorio/WBG/langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat.json', 'seq_num': 2}),
71
+ Document(page_content='No Im sorry it was my mistake, the blue one is not for sale', metadata={'source': '/Users/avsolatorio/WBG/langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat.json', 'seq_num': 3}),
72
+ Document(page_content='I thought you were selling the blue one!', metadata={'source': '/Users/avsolatorio/WBG/langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat.json', 'seq_num': 4}),
73
+ Document(page_content='Im not interested in this bag. Im interested in the blue one!', metadata={'source': '/Users/avsolatorio/WBG/langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat.json', 'seq_num': 5}),
74
+ Document(page_content='Here is $129', metadata={'source': '/Users/avsolatorio/WBG/langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat.json', 'seq_num': 6}),
75
+ Document(page_content='', metadata={'source': '/Users/avsolatorio/WBG/langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat.json', 'seq_num': 7}),
76
+ Document(page_content='Online is at least $100', metadata={'source': '/Users/avsolatorio/WBG/langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat.json', 'seq_num': 8}),
77
+ Document(page_content='How much do you want?', metadata={'source': '/Users/avsolatorio/WBG/langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat.json', 'seq_num': 9}),
78
+ Document(page_content='Goodmorning! $50 is too low.', metadata={'source': '/Users/avsolatorio/WBG/langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat.json', 'seq_num': 10}),
79
+ Document(page_content='Hi! Im interested in your bag. Im offering $50. Let me know if you are interested. Thanks!', metadata={'source': '/Users/avsolatorio/WBG/langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat.json', 'seq_num': 11})]
80
+
81
+
82
+
83
+
84
+
85
+ file_path = './example_data/facebook_chat_messages.jsonl'
86
+ pprint(Path(file_path).read_text())
87
+
88
+ ('{"sender_name": "User 2", "timestamp_ms": 1675597571851, "content": "Bye!"}\n'
89
+ '{"sender_name": "User 1", "timestamp_ms": 1675597435669, "content": "Oh no '
90
+ 'worries! Bye"}\n'
91
+ '{"sender_name": "User 2", "timestamp_ms": 1675596277579, "content": "No Im '
92
+ 'sorry it was my mistake, the blue one is not for sale"}\n')
93
+
94
+ loader = JSONLoader(
95
+ file_path='./example_data/facebook_chat_messages.jsonl',
96
+ jq_schema='.content',
97
+ text_content=False,
98
+ json_lines=True)
99
+
100
+ data = loader.load()
101
+
102
+ pprint(data)
103
+
104
+ [Document(page_content='Bye!', metadata={'source': 'langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat_messages.jsonl', 'seq_num': 1}),
105
+ Document(page_content='Oh no worries! Bye', metadata={'source': 'langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat_messages.jsonl', 'seq_num': 2}),
106
+ Document(page_content='No Im sorry it was my mistake, the blue one is not for sale', metadata={'source': 'langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat_messages.jsonl', 'seq_num': 3})]
107
+
108
+
109
+
110
+
111
+
112
+ loader = JSONLoader(
113
+ file_path='./example_data/facebook_chat_messages.jsonl',
114
+ jq_schema='.',
115
+ content_key='sender_name',
116
+ json_lines=True)
117
+
118
+ data = loader.load()
119
+
120
+ pprint(data)
121
+
122
+ [Document(page_content='User 2', metadata={'source': 'langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat_messages.jsonl', 'seq_num': 1}),
123
+ Document(page_content='User 1', metadata={'source': 'langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat_messages.jsonl', 'seq_num': 2}),
124
+ Document(page_content='User 2', metadata={'source': 'langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat_messages.jsonl', 'seq_num': 3})]
125
+
126
+
127
+
128
+
129
+
130
+ .messages[].content
131
+
132
+ .messages[]
133
+
134
+ # Define the metadata extraction function.
135
+ def metadata_func(record: dict, metadata: dict) -> dict:
136
+
137
+ metadata["sender_name"] = record.get("sender_name")
138
+ metadata["timestamp_ms"] = record.get("timestamp_ms")
139
+
140
+ return metadata
141
+
142
+
143
+ loader = JSONLoader(
144
+ file_path='./example_data/facebook_chat.json',
145
+ jq_schema='.messages[]',
146
+ content_key="content",
147
+ metadata_func=metadata_func
148
+ )
149
+
150
+ data = loader.load()
151
+
152
+ pprint(data)
153
+
154
+ [Document(page_content='Bye!', metadata={'source': '/Users/avsolatorio/WBG/langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat.json', 'seq_num': 1, 'sender_name': 'User 2', 'timestamp_ms': 1675597571851}),
155
+ Document(page_content='Oh no worries! Bye', metadata={'source': '/Users/avsolatorio/WBG/langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat.json', 'seq_num': 2, 'sender_name': 'User 1', 'timestamp_ms': 1675597435669}),
156
+ Document(page_content='No Im sorry it was my mistake, the blue one is not for sale', metadata={'source': '/Users/avsolatorio/WBG/langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat.json', 'seq_num': 3, 'sender_name': 'User 2', 'timestamp_ms': 1675596277579}),
157
+ Document(page_content='I thought you were selling the blue one!', metadata={'source': '/Users/avsolatorio/WBG/langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat.json', 'seq_num': 4, 'sender_name': 'User 1', 'timestamp_ms': 1675595140251}),
158
+ Document(page_content='Im not interested in this bag. Im interested in the blue one!', metadata={'source': '/Users/avsolatorio/WBG/langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat.json', 'seq_num': 5, 'sender_name': 'User 1', 'timestamp_ms': 1675595109305}),
159
+ Document(page_content='Here is $129', metadata={'source': '/Users/avsolatorio/WBG/langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat.json', 'seq_num': 6, 'sender_name': 'User 2', 'timestamp_ms': 1675595068468}),
160
+ Document(page_content='', metadata={'source': '/Users/avsolatorio/WBG/langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat.json', 'seq_num': 7, 'sender_name': 'User 2', 'timestamp_ms': 1675595060730}),
161
+ Document(page_content='Online is at least $100', metadata={'source': '/Users/avsolatorio/WBG/langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat.json', 'seq_num': 8, 'sender_name': 'User 2', 'timestamp_ms': 1675595045152}),
162
+ Document(page_content='How much do you want?', metadata={'source': '/Users/avsolatorio/WBG/langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat.json', 'seq_num': 9, 'sender_name': 'User 1', 'timestamp_ms': 1675594799696}),
163
+ Document(page_content='Goodmorning! $50 is too low.', metadata={'source': '/Users/avsolatorio/WBG/langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat.json', 'seq_num': 10, 'sender_name': 'User 2', 'timestamp_ms': 1675577876645}),
164
+ Document(page_content='Hi! Im interested in your bag. Im offering $50. Let me know if you are interested. Thanks!', metadata={'source': '/Users/avsolatorio/WBG/langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat.json', 'seq_num': 11, 'sender_name': 'User 1', 'timestamp_ms': 1675549022673})]
165
+
166
+
167
+
168
+
169
+
170
+
171
+
172
+ # Define the metadata extraction function.
173
+ def metadata_func(record: dict, metadata: dict) -> dict:
174
+
175
+ metadata["sender_name"] = record.get("sender_name")
176
+ metadata["timestamp_ms"] = record.get("timestamp_ms")
177
+
178
+ if "source" in metadata:
179
+ source = metadata["source"].split("/")
180
+ source = source[source.index("langchain"):]
181
+ metadata["source"] = "/".join(source)
182
+
183
+ return metadata
184
+
185
+
186
+ loader = JSONLoader(
187
+ file_path='./example_data/facebook_chat.json',
188
+ jq_schema='.messages[]',
189
+ content_key="content",
190
+ metadata_func=metadata_func
191
+ )
192
+
193
+ data = loader.load()
194
+
195
+ pprint(data)
196
+
197
+ [Document(page_content='Bye!', metadata={'source': 'langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat.json', 'seq_num': 1, 'sender_name': 'User 2', 'timestamp_ms': 1675597571851}),
198
+ Document(page_content='Oh no worries! Bye', metadata={'source': 'langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat.json', 'seq_num': 2, 'sender_name': 'User 1', 'timestamp_ms': 1675597435669}),
199
+ Document(page_content='No Im sorry it was my mistake, the blue one is not for sale', metadata={'source': 'langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat.json', 'seq_num': 3, 'sender_name': 'User 2', 'timestamp_ms': 1675596277579}),
200
+ Document(page_content='I thought you were selling the blue one!', metadata={'source': 'langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat.json', 'seq_num': 4, 'sender_name': 'User 1', 'timestamp_ms': 1675595140251}),
201
+ Document(page_content='Im not interested in this bag. Im interested in the blue one!', metadata={'source': 'langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat.json', 'seq_num': 5, 'sender_name': 'User 1', 'timestamp_ms': 1675595109305}),
202
+ Document(page_content='Here is $129', metadata={'source': 'langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat.json', 'seq_num': 6, 'sender_name': 'User 2', 'timestamp_ms': 1675595068468}),
203
+ Document(page_content='', metadata={'source': 'langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat.json', 'seq_num': 7, 'sender_name': 'User 2', 'timestamp_ms': 1675595060730}),
204
+ Document(page_content='Online is at least $100', metadata={'source': 'langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat.json', 'seq_num': 8, 'sender_name': 'User 2', 'timestamp_ms': 1675595045152}),
205
+ Document(page_content='How much do you want?', metadata={'source': 'langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat.json', 'seq_num': 9, 'sender_name': 'User 1', 'timestamp_ms': 1675594799696}),
206
+ Document(page_content='Goodmorning! $50 is too low.', metadata={'source': 'langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat.json', 'seq_num': 10, 'sender_name': 'User 2', 'timestamp_ms': 1675577876645}),
207
+ Document(page_content='Hi! Im interested in your bag. Im offering $50. Let me know if you are interested. Thanks!', metadata={'source': 'langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat.json', 'seq_num': 11, 'sender_name': 'User 1', 'timestamp_ms': 1675549022673})]
208
+
209
+
210
+ JSON -> [{"text": ...}, {"text": ...}, {"text": ...}]
211
+ jq_schema -> ".[].text"
212
+
213
+ JSON -> {"key": [{"text": ...}, {"text": ...}, {"text": ...}]}
214
+ jq_schema -> ".key[].text"
215
+
216
+ JSON -> ["...", "...", "..."]
217
+ jq_schema -> ".[]"
htmlTemplates.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ css = '''
2
+ <style>
3
+ .chat-message {
4
+ padding: 1.5rem; border-radius: 0.5rem; margin-bottom: 1rem; display: flex
5
+ }
6
+ .chat-message.user {
7
+ background-color: #2b313e
8
+ }
9
+ .chat-message.bot {
10
+ background-color: #475063
11
+ }
12
+ .chat-message .avatar {
13
+ width: 20%;
14
+ }
15
+ .chat-message .avatar img {
16
+ max-width: 78px;
17
+ max-height: 78px;
18
+ border-radius: 50%;
19
+ object-fit: cover;
20
+ }
21
+ .chat-message .message {
22
+ width: 80%;
23
+ padding: 0 1.5rem;
24
+ color: #fff;
25
+ }
26
+ '''
27
+
28
+ bot_template = '''
29
+ <div class="chat-message bot">
30
+ <div class="avatar">
31
+ <img src="https://i.ibb.co/cN0nmSj/Screenshot-2023-05-28-at-02-37-21.png" style="max-height: 78px; max-width: 78px; border-radius: 50%; object-fit: cover;">
32
+ </div>
33
+ <div class="message">{{MSG}}</div>
34
+ </div>
35
+ '''
36
+
37
+ user_template = '''
38
+ <div class="chat-message user">
39
+ <div class="avatar">
40
+ <img src="https://i.ibb.co/rdZC7LZ/Photo-logo-1.png">
41
+ </div>
42
+ <div class="message">{{MSG}}</div>
43
+ </div>
44
+ '''
requirements.txt ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ langchain
2
+ llama-cpp-python
3
+ PyPDF2==3.0.1
4
+ faiss-cpu==1.7.4
5
+ ctransformers
6
+ pypdf
7
+ chromadb
8
+ tiktoken
9
+ pysqlite3-binary
10
+ streamlit-extras
11
+ InstructorEmbedding
12
+ sentence-transformers
13
+ jq
14
+ openai