JBHF commited on
Commit
3337e93
1 Parent(s): b553d40

Create app_27-03-2024_0

Browse files
Files changed (1) hide show
  1. app_27-03-2024_0 +431 -0
app_27-03-2024_0 ADDED
@@ -0,0 +1,431 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # NonToxicGlazeAdvisor_Chat_with_Docs_Groq_Edition_1 - app.py - 27-03-2024 11u16m CET
2
+ # https://huggingface.co/spaces/JBHF/NonToxicGlazeAdvisor_Chat_with_Docs_Groq_Edition_1/blob/main/app.py
3
+ # C:\Users\HP\Documents\Adviseur voor niet-giftige glazuren
4
+
5
+ # NonToxicGlazeAdvisor_Chat_with_Docs_Groq_Edition_1 - app.py - 27-03-2024
6
+
7
+ # STREAMLIT:
8
+ # https://www.datacamp.com/tutorial/streamlit:
9
+ #
10
+ # st.title(): This function allows you to add the title of the app.
11
+ # st.header(): This function is used to set header of a section.
12
+ # st.markdown(): This function is used to set a markdown of a section.
13
+ # st.subheader(): This function is used to set sub-header of a section.
14
+ # st.caption(): This function is used to write caption.
15
+ # st.code(): This function is used to set a code.
16
+ # st.latex(): This function is used to display mathematical expressions formatted as LaTeX.
17
+ #
18
+ # st.title ("this is the app title")
19
+ # st.header("this is the header ")
20
+ # st.markdown("this is the markdown")
21
+ # st.subheader("this is the subheader")
22
+ # st.caption("this is the caption")
23
+ # st.code("x=2021")
24
+ # st.latex(r''' a+a r^1+a r^2+a r^3 ''')
25
+
26
+
27
+
28
+ # JB:
29
+ # LangChainDeprecationWarning: Importing embeddings from langchain is deprecated.
30
+ # Importing from langchain will no longer be supported as of langchain==0.2.0.
31
+ # Please import from langchain-community instead:
32
+ # `from langchain_community.embeddings import FastEmbedEmbeddings`.
33
+ # To install langchain-community run `pip install -U langchain-community`.
34
+ from langchain_community.embeddings import FastEmbedEmbeddings
35
+
36
+ import os
37
+ import streamlit as st
38
+ from langchain_groq import ChatGroq
39
+ from langchain_community.document_loaders import WebBaseLoader
40
+ # JB:
41
+ from langchain_community.document_loaders import PyPDFLoader
42
+ from langchain_community.embeddings import OllamaEmbeddings
43
+
44
+ # JB:
45
+ from langchain_community.embeddings import FastEmbedEmbeddings
46
+ from langchain_community.document_loaders import PyPDFDirectoryLoader
47
+
48
+ # JB:
49
+ # File Directory
50
+ # This covers how to load all documents in a directory.
51
+ # Under the hood, by default this uses the UnstructuredLoader.
52
+ from langchain_community.document_loaders import DirectoryLoader
53
+ from langchain_community.document_loaders import TextLoader
54
+ import chardet
55
+
56
+ from langchain_community.vectorstores import FAISS
57
+ # from langchain.vectorstores import Chroma
58
+ # from langchain_community.vectorstores import Chroma
59
+
60
+ from langchain.text_splitter import RecursiveCharacterTextSplitter
61
+ from langchain.chains.combine_documents import create_stuff_documents_chain
62
+ from langchain_core.prompts import ChatPromptTemplate
63
+ from langchain.chains import create_retrieval_chain
64
+ import time
65
+ from dotenv import load_dotenv
66
+
67
+ import glob
68
+
69
+ load_dotenv() #
70
+
71
+ groq_api_key = os.environ['GROQ_API_KEY']
72
+ # groq_api_key = "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" # os.environ['GROQ_API_KEY']
73
+ # groq_api_key = "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" # JB OK 24-03-2024
74
+ # print("groq_api_key: ", groq_api_key)
75
+
76
+ # st.title("Chat with Docs - Groq Edition :) ")
77
+ # # st.title ("this is the app title")
78
+ # st.title("Non-Toxic Glaze Advisor:")
79
+ # st.subheader("A tool for getting advicgroqe on non-toxic ceramic glazes for earthenware temperature ranges.")
80
+ # st.subheader("Victor Benchuijsen : (Glaze techniques / Ceramics)")
81
+ # st.subheader("Jan Bours : Artificial Intelligence / Data Science / Natural Language Processing (ALL RIGHTS RESERVED)")
82
+ # st.write("---------------------------------")
83
+ # st.subheader("Chat with Docs - Using AI: 'mixtral-8x7b-32768' Groq Edition (Very Fast!) - VERSION 1 - March 18, 2024")
84
+ # st.write("---------------------------------")
85
+
86
+ st.title("Adviseur voor niet-giftige glazuren:")
87
+ st.subheader("Een gereedschap gebaseerd op Kunstmatige Intelligentie (AI) om advies te krijgen over niet-giftige keramische glazuren voor aardewerk temperatuur bereiken.")
88
+ st.write("---------------------------------")
89
+ st.subheader("Victor Benckhuijsen : (Glazuur technieken / Keramiek)")
90
+ st.subheader("(ALL RIGHTS RESERVED)")
91
+ st.image('Victor_Benckhuijsen_2.png', caption='Victor Benckhuijsen')
92
+ # st.subheader("---------------------------------")
93
+ # st.write("---------------------------------")
94
+ st.subheader("Jan Bours : Artificial Intelligence / Data Science / Natural Language Processing")
95
+ st.subheader("(ALL RIGHTS RESERVED)")
96
+ st.image('Jan_Bours_2.png', caption='Jan Bours')
97
+ st.write("---------------------------------")
98
+ st.subheader("Chat with Docs - Using AI: 'mixtral-8x7b-32768' Groq Edition (Very Fast!) - VERSION 1 - March 26, 2024")
99
+ st.write("---------------------------------")
100
+
101
+ # st.header("LIST OF ALL THE LOADED DOCUMENTS: ")
102
+ st.header("LIJST MET ALLE ACTUEEL GELADEN DOCUMENTEN: ")
103
+
104
+ st.write("")
105
+ pdf_files = glob.glob("*.pdf")
106
+ # word_files = glob.glob("*.docx")
107
+ for file in pdf_files:
108
+ # for file in word_files:
109
+ st.subheader(file)
110
+
111
+ st.write("---------------------------------")
112
+
113
+
114
+ start1 = time.process_time()
115
+
116
+ if "vector" not in st.session_state:
117
+
118
+ st.write("Even geduld a.u.b. ........")
119
+ # st.header("Chunking, embedding, storing in FAISS vectorstore (Can take a long time!).")
120
+ # st.subheader("Wait till this hase been done before you can enter your query! .......")
121
+
122
+ # st.session_state.embeddings = OllamaEmbeddings() # ORIGINAL
123
+ st.session_state.embeddings = FastEmbedEmbeddings() # JB
124
+
125
+
126
+ # st.session_state.loader = WebBaseLoader("https://paulgraham.com/greatwork.html") # ORIGINAL
127
+ # st.session_state.docs = st.session_state.loader.load() # ORIGINAL
128
+ # https://api.python.langchain.com/en/latest/document_loaders/langchain_community.document_loaders.pdf.PyPDFLoader.html
129
+ # https://python.langchain.com/docs/integrations/document_loaders/merge_doc
130
+ # from langchain_community.document_loaders import PyPDFLoader
131
+ # loader_pdf = PyPDFLoader("../MachineLearning-Lecture01.pdf")
132
+ #
133
+ # https://stackoverflow.com/questions/60215731/pypdf-to-read-each-pdf-in-a-folder
134
+ #
135
+ # https://api.python.langchain.com/en/latest/document_loaders/langchain_community.document_loaders.pdf.PyPDFDirectoryLoader.html
136
+ # https://python.langchain.com/docs/modules/data_connection/document_loaders/pdf#pypdf-directory
137
+ # !!!!!
138
+ # PyPDF Directory
139
+ # Load PDFs from directory
140
+ # from langchain_community.document_loaders import PyPDFDirectoryLoader
141
+ # loader = PyPDFDirectoryLoader("example_data/")
142
+ # docs = loader.load()
143
+ #
144
+ # ZIE OOK:
145
+ # https://python.langchain.com/docs/modules/data_connection/document_loaders/pdf#using-pypdf
146
+ # Using MathPix
147
+ # Inspired by Daniel Gross's https://gist.github.com/danielgross/3ab4104e14faccc12b49200843adab21
148
+ # from langchain_community.document_loaders import MathpixPDFLoader
149
+ # loader = MathpixPDFLoader("example_data/layout-parser-paper.pdf")
150
+ # data = loader.load()
151
+ # pdf_file_path = "*.pdf" # JB
152
+ # st.session_state.loader = PyPDFLoader(file_path=pdf_file_path).load() # JB
153
+ # st.session_state.loader = PyPDFLoader(*.pdf).load() # JB syntax error *.pdf !
154
+ # st.session_state.loader = PyPDFDirectoryLoader("*.pdf") # JB PyPDFDirectoryLoader("example_data/")
155
+ # chunks = self.text_splitter.split_documents(docs)
156
+ # chunks = filter_complex_metadata(chunks)
157
+
158
+ # JB:
159
+ # https://python.langchain.com/docs/modules/data_connection/document_loaders/pdf#pypdf-directory
160
+ # st.session_state.docs = st.session_state.loader.load()
161
+ # loader = PyPDFDirectoryLoader(".")
162
+ # docs = loader.load()
163
+ # st.session_state.docs = docs
164
+
165
+
166
+ # https://docs.streamlit.io/library/api-reference/status/st.status
167
+ # st.status(label, *, expanded=False, state="running")
168
+ with st.status("Laden van de PDF documenten / Splitting de teksten / Genereer de Vector Store ...", expanded=True) as status:
169
+ # st.write("Searching for data...")
170
+ # time.sleep(2)
171
+ # st.write("Found URL.")
172
+ # time.sleep(1)
173
+ # st.write("Downloading data...")
174
+ # time.sleep(1)
175
+ #status.update(label="Download complete!", state="complete", expanded=False)
176
+
177
+ st.write("Laden van de PDF documenten...")
178
+ # JB:
179
+ # https://python.langchain.com/docs/modules/data_connection/document_loaders/file_directory
180
+ # text_loader_kwargs={'autodetect_encoding': True}
181
+ text_loader_kwargs={'autodetect_encoding': False}
182
+ path = '../'
183
+ # loader = DirectoryLoader(path, glob="**/*.pdf", loader_cls=TextLoader, loader_kwargs=text_loader_kwargs)
184
+ # PyPDFDirectoryLoader (TEST):
185
+ # loader = PyPDFDirectoryLoader(path, glob="**/*.pdf", loader_cls=TextLoader, loader_kwargs=text_loader_kwargs)
186
+ # loader = PyPDFDirectoryLoader(path, glob="**/*.pdf", loader_kwargs=text_loader_kwargs)
187
+ loader = PyPDFDirectoryLoader(path, glob="**/*.pdf")
188
+ docs = loader.load()
189
+ st.session_state.docs = docs
190
+
191
+ # JB 18-03-2024:
192
+ # https://python.langchain.com/docs/integrations/document_loaders/
193
+ # MICROSOFT WORD:
194
+ # https://python.langchain.com/docs/integrations/document_loaders/microsoft_word
195
+ # 1 - Using Docx2txt
196
+ # Load .docx using Docx2txt into a document.
197
+ # %pip install --upgrade --quiet docx2txt
198
+ # from langchain_community.document_loaders import Docx2txtLoader
199
+ # loader = Docx2txtLoader("example_data/fake.docx")
200
+ # data = loader.load()
201
+ # data
202
+ # [Document(page_content='Lorem ipsum dolor sit amet.', metadata={'source': 'example_data/fake.docx'})]
203
+ #
204
+ # 2A - Using Unstructured
205
+ # from langchain_community.document_loaders import UnstructuredWordDocumentLoader
206
+ # loader = UnstructuredWordDocumentLoader("example_data/fake.docx")
207
+ # data = loader.load()
208
+ # data
209
+ # [Document(page_content='Lorem ipsum dolor sit amet.', lookup_str='', metadata={'source': 'fake.docx'}, lookup_index=0)]
210
+ #
211
+ # 2B - Retain Elements
212
+ # Under the hood, Unstructured creates different “elements” for different chunks of text.
213
+ # By default we combine those together, but you can easily keep that separation by specifying mode="elements".
214
+ # loader = UnstructuredWordDocumentLoader("example_data/fake.docx", mode="elements")
215
+ # data = loader.load()
216
+ # data[0]
217
+ # Document(page_content='Lorem ipsum dolor sit amet.', lookup_str='', metadata={'source': 'fake.docx', 'filename': 'fake.docx', 'category': 'Title'}, lookup_index=0)
218
+ #
219
+ # 2A - Using Unstructured
220
+ # from langchain_community.document_loaders import UnstructuredWordDocumentLoader
221
+ # loader = UnstructuredWordDocumentLoader(path, glob="**/*.docx")
222
+ # docs = loader.load()
223
+ # st.session_state.docs = docs
224
+
225
+
226
+ st.write("Splitting / chunking de teksten...")
227
+ st.session_state.text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=200)
228
+ st.session_state.documents = st.session_state.text_splitter.split_documents(st.session_state.docs)
229
+
230
+ st.write("Genereer de Vector Store (kan enige minuten duren)...")
231
+ # https://python.langchain.com/docs/integrations/vectorstores/faiss
232
+ # docs_and_scores = db.similarity_search_with_score(query)
233
+ # Saving and loading
234
+ # You can also save and load a FAISS index.
235
+ # This is useful so you don’t have to recreate it everytime you use it.
236
+ # db.save_local("faiss_index")
237
+ # new_db = FAISS.load_local("faiss_index", embeddings)
238
+ # docs = new_db.similarity_search(query)
239
+ # docs[0]
240
+ # Document(page_content='Tonight. I call on the Senate to: Pass the Freedom to Vote Act. Pass the John Lewis Voting Rights Act. And while you’re at it, pass the Disclose Act so Americans can know who is funding our elections. \n\nTonight, I’d like to honor someone who has dedicated his life to serve this country: Justice Stephen Breyer—an Army veteran, Constitutional scholar, and retiring Justice of the United States Supreme Court. Justice Breyer, thank you for your service. \n\nOne of the most serious constitutional responsibilities a President has is nominating someone to serve on the United States Supreme Court. \n\nAnd I did that 4 days ago, when I nominated Circuit Court of Appeals Judge Ketanji Brown Jackson. One of our nation’s top legal minds, who will continue Justice Breyer’s legacy of excellence.', metadata={'source': '../../../state_of_the_union.txt'})
241
+ #
242
+ st.session_state.vector = FAISS.from_documents(st.session_state.documents, st.session_state.embeddings) # ORIGINAL
243
+
244
+ # st.session_state.vector = FAISS.from_documents(st.session_state.documents, st.session_state.embeddings) # ORIGINAL
245
+ #st.session_state.vector.save_local("faiss_index")
246
+ # The de-serialization relies loading a pickle file.
247
+ # Pickle files can be modified to deliver a malicious payload that results in execution of arbitrary code on your machine.
248
+ # You will need to set `allow_dangerous_deserialization` to `True` to enable deserialization. If you do this, make sure that you trust the source of the data.
249
+
250
+ #st.session_state.vector = FAISS.load_local("faiss_index", st.session_state.embeddings, allow_dangerous_deserialization=True)
251
+
252
+ # ZIE:
253
+ # ZIE VOOR EEN APP MET CHROMADB:
254
+ # https://github.com/vndee/local-rag-example/blob/main/rag.py
255
+ # https://raw.githubusercontent.com/vndee/local-rag-example/main/rag.py
256
+ # Chroma.from_documents(documents=chunks, embedding=FastEmbedEmbeddings())
257
+ # st.session_state.vector = Chroma.from_documents(st.session_state.documents, st.session_state.embeddings) # JB
258
+
259
+ # st.write(f"Response time van de LLM: {elapsed_time:.1f} seconds")
260
+ # print(f"Response time: {time.process_time() - start}")
261
+ elapsed_time = time.process_time() - start1
262
+ st.write(f"Response time voor: Laden van de PDF documenten / Splitting de teksten / Genereer de Vector Store: {elapsed_time:.1f} seconds")
263
+
264
+ st.write("---------------------------------")
265
+
266
+ # st.title("Chat with Docs - Groq Edition :) ")
267
+ # st.title("Literature Based Research (LBR) - A. Unzicker and J. Bours - Chat with Docs - Groq Edition (Very Fast!) - VERSION 3 - March 8 2024")
268
+
269
+ llm = ChatGroq(
270
+ temperature=0.2,
271
+ groq_api_key=groq_api_key,
272
+ model_name='mixtral-8x7b-32768'
273
+ )
274
+
275
+ prompt = ChatPromptTemplate.from_template("""
276
+ Answer the following question based only on the provided context.
277
+ Think step by step before providing a detailed answer.
278
+ I will tip you $200 if the user finds the answer helpful.
279
+ <context>
280
+ {context}
281
+ </context>
282
+ Question: {input}""")
283
+
284
+ document_chain = create_stuff_documents_chain(llm, prompt)
285
+
286
+ retriever = st.session_state.vector.as_retriever()
287
+ retrieval_chain = create_retrieval_chain(retriever, document_chain)
288
+
289
+ ## prompt = st.text_input("Input your prompt here") #, key=key)
290
+ #prompt = st.text_input("Stel hieronder Uw vraag:") #, key=key)
291
+ #
292
+ ## If the user hits enter
293
+ #if prompt:
294
+ # # Then pass the prompt to the LLM
295
+ # start = time.process_time()
296
+ # response = retrieval_chain.invoke({"input": prompt})
297
+ # # print(f"Response time: {time.process_time() - start}")
298
+ # st.write(f"Response time: {time.process_time() - start} seconds")
299
+ #
300
+ # st.write(response["answer"])
301
+ #
302
+ # # With a streamlit expander
303
+ # with st.expander("Document Similarity Search"):
304
+ # # Find the relevant chunks
305
+ # for i, doc in enumerate(response["context"]):
306
+ # # print(doc)
307
+ # # st.write(f"Source Document # {i+1} : {doc.metadata['source'].split('/')[-1]}")
308
+ # st.write(doc)
309
+ # st.write(f"Source Document # {i+1} : {doc.metadata['source'].split('/')[-1]}")
310
+ #
311
+ #
312
+ # st.write(doc.page_content)
313
+ # st.write("--------------------------------")
314
+ #
315
+ #st.write("---------------------------------")
316
+
317
+
318
+ # ZIE:
319
+ # https://raw.githubusercontent.com/streamlit/llm-examples/main/Chatbot.py
320
+ # from openai import OpenAI
321
+ # import streamlit as st
322
+
323
+ with st.sidebar:
324
+ # openai_api_key = st.text_input("OpenAI API Key", key="chatbot_api_key", type="password")
325
+ UserEmailAdress = st.text_input("Vul Uw email adres hier in: ", key="UserEmailAdress", type="password")
326
+ "[Zelf keramische glazuren NON TOXIC samenstellen vanuit 1 basisglazuur](http://www.ceramicconcepts.nl/)"
327
+ "[Keramische ateliers Victor Benckhuijsen](https://victorglazuren.nl/)"
328
+ "[Keramiek Victor Glazuren Victor Benckhuijsen - Instagram](https://www.instagram.com/benckhuijsenvictor/?hl=am-et)"
329
+ "[Keramiek Victor Glazuren Victor Benckhuijsen - Facebook](https://www.facebook.com/harryjamaar)"
330
+ "[Keramiek Victor Glazuren Victor Benckhuijsen - YouTube](https://www.youtube.com/@kleienhoop/videos)"
331
+
332
+ st.title("💬 Chatbot")
333
+ st.caption("🚀 A streamlit chatbot powered by mixtral-8x7b-32768 Groq LLM (VERY FAST !). temperature=0.2")
334
+
335
+ if "messages" not in st.session_state:
336
+ st.session_state["messages"] = [{"role": "assistant", "content": "Hoe kan ik U helpen?"}]
337
+
338
+ for msg in st.session_state.messages:
339
+ st.chat_message(msg["role"]).write(msg["content"])
340
+
341
+ if prompt := st.chat_input():
342
+ #if not openai_api_key:
343
+ # st.info("Please add your OpenAI API key to continue.")
344
+ # st.stop()
345
+
346
+ # Then pass the prompt to the LLM
347
+ start = time.process_time()
348
+ response = retrieval_chain.invoke({"input": prompt})
349
+ # print(f"Response time: {time.process_time() - start}")
350
+ elapsed_time = time.process_time() - start
351
+ st.write(f"Response time van de LLM: {elapsed_time:.1f} seconds")
352
+
353
+ # st.write(response["answer"])
354
+
355
+ # https://docs.streamlit.io/library/api-reference/chat/st.chat_message
356
+ # st.chat_message(name, *, avatar=None)
357
+ # The avatar shown next to the message. Can be one of:
358
+ # - A single emoji, e.g. "🧑‍💻", "🤖", "🦖". Shortcodes are not supported.
359
+ # - An image using one of the formats allowed for st.image: path of a local image file;
360
+ # URL to fetch the image from; an SVG image; array of shape (w,h) or (w,h,1) for a monochrome image,
361
+ # (w,h,3) for a color image, or (w,h,4) for an RGBA image.
362
+ # If None (default), uses default icons if name is "user", "assistant", "ai", "human" or the first letter of the name value.
363
+
364
+ #client = OpenAI(api_key=openai_api_key)
365
+ st.session_state.messages.append({"role": "user", "content": prompt})
366
+ st.chat_message("user").write(prompt)
367
+ # response = client.chat.completions.create(model="gpt-3.5-turbo", messages=st.session_state.messages)
368
+ # msg = response.choices[0].message.content
369
+ msg = response["answer"]
370
+ st.session_state.messages.append({"role": "assistant", "content": msg})
371
+ # st.chat_message("assistant").write(msg)
372
+ # MET ALS AVATAR EEN IMAGE VAN VICTOR:
373
+ st.chat_message("assistant", avatar="Victor_Benckhuisen_20_percent.jpg").write(msg)
374
+
375
+ # With a streamlit expander
376
+ with st.expander("Document Similarity Search"):
377
+ # Find the relevant chunks
378
+ for i, doc in enumerate(response["context"]):
379
+ # print(doc)
380
+ # st.write(f"Source Document # {i+1} : {doc.metadata['source'].split('/')[-1]}")
381
+ st.write(doc)
382
+ st.write(f"Source Document # {i+1} : {doc.metadata['source'].split('/')[-1]}")
383
+
384
+
385
+ st.write(doc.page_content)
386
+ st.write("--------------------------------")
387
+
388
+ st.write("---------------------------------")
389
+
390
+
391
+
392
+ #i=0
393
+ #while True:
394
+ #
395
+ # # data = ["input1", "input2", "input3"]
396
+ #
397
+ # #for i, item in enumerate(data):
398
+ # key = f"input_{i}"
399
+ # # text_input = st.text_input(f"Enter value for {item}", key=key)
400
+ # # Access the value directly
401
+ # print(f"Value for key: {key}")
402
+ #
403
+ # i=i+1
404
+ #
405
+ # prompt = st.text_input("Input your prompt here", key=key)
406
+ #
407
+ #
408
+ # # If the user hits enter
409
+ # if prompt:
410
+ # # Then pass the prompt to the LLM
411
+ # start = time.process_time()
412
+ # response = retrieval_chain.invoke({"input": prompt})
413
+ # # print(f"Response time: {time.process_time() - start}")
414
+ # st.write(f"Response time: {time.process_time() - start} seconds")
415
+ #
416
+ # st.write(response["answer"])
417
+ #
418
+ # # With a streamlit expander
419
+ # with st.expander("Document Similarity Search"):
420
+ # # Find the relevant chunks
421
+ # for i, doc in enumerate(response["context"]):
422
+ # # print(doc)
423
+ # # st.write(f"Source Document # {i+1} : {doc.metadata['source'].split('/')[-1]}")
424
+ # st.write(doc)
425
+ # st.write(f"Source Document # {i+1} : {doc.metadata['source'].split('/')[-1]}")
426
+ #
427
+ #
428
+ # st.write(doc.page_content)
429
+ # st.write("--------------------------------")
430
+ #
431
+ # st.write("---------------------------------")