scholarly360 commited on
Commit
ab26643
·
1 Parent(s): 0db862b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -11
app.py CHANGED
@@ -14,19 +14,25 @@ from langchain.schema import Document
14
  from langchain.vectorstores import Chroma
15
  from langchain.embeddings import HuggingFaceEmbeddings
16
  embedding = HuggingFaceEmbeddings(model_name='BAAI/bge-base-en-v1.5')
17
-
 
18
  import spacy
19
  # Load the English model from SpaCy
20
  nlp = spacy.load("en_core_web_md")
21
 
22
- def util_upload_file_and_return_list_docs(uploaded_file):
23
  #util_del_cwd()
24
- save_path = Path(os.getcwd(), uploaded_file.name)
25
- with open(save_path, mode='wb') as w:
26
- w.write(uploaded_file.getvalue())
27
- print('save_path:', save_path)
28
- docs = fitz.open(save_path)
29
- return(docs, save_path)
 
 
 
 
 
30
  #### Helper Functions to Split using Rolling Window (recomm : use smaller rolling window )
31
  def split_txt_file_synthetic_sentence_rolling(ctxt, sentence_size_in_chars, sliding_size_in_chars,debug=False):
32
  sliding_size_in_chars = sentence_size_in_chars - sliding_size_in_chars
@@ -246,9 +252,13 @@ with st.form("my_form"):
246
  ** Attempt is made for appropriate page and passage retrieval ** \n
247
  '''
248
  st.markdown(multi)
249
- uploaded_file = st.file_uploader("Choose a file")
250
- if uploaded_file is not None:
251
- docs, save_path = util_upload_file_and_return_list_docs(uploaded_file)
 
 
 
 
252
  page_documents , passage_documents = util_get_list_page_and_passage(docs)
253
  print('len(page_documents) len(passage_documents ', len(page_documents), len(passage_documents))
254
  single_example_passage = st.text_area('Enter Query Here',"What is Governing Law ")
 
14
  from langchain.vectorstores import Chroma
15
  from langchain.embeddings import HuggingFaceEmbeddings
16
  embedding = HuggingFaceEmbeddings(model_name='BAAI/bge-base-en-v1.5')
17
+ from FlagEmbedding import FlagReranker
18
+ reranker = FlagReranker('BAAI/bge-reranker-base')
19
  import spacy
20
  # Load the English model from SpaCy
21
  nlp = spacy.load("en_core_web_md")
22
 
23
+ def util_upload_file_and_return_list_docs(uploaded_files):
24
  #util_del_cwd()
25
+ list_docs = []
26
+ list_save_path = []
27
+ for uploaded_file in uploaded_files:
28
+ save_path = Path(os.getcwd(), uploaded_file.name)
29
+ with open(save_path, mode='wb') as w:
30
+ w.write(uploaded_file.getvalue())
31
+ print('save_path:', save_path)
32
+ docs = fitz.open(save_path)
33
+ list_docs.append(docs)
34
+ list_save_path.append(save_path)
35
+ return(list_docs, list_save_path)
36
  #### Helper Functions to Split using Rolling Window (recomm : use smaller rolling window )
37
  def split_txt_file_synthetic_sentence_rolling(ctxt, sentence_size_in_chars, sliding_size_in_chars,debug=False):
38
  sliding_size_in_chars = sentence_size_in_chars - sliding_size_in_chars
 
252
  ** Attempt is made for appropriate page and passage retrieval ** \n
253
  '''
254
  st.markdown(multi)
255
+ #uploaded_file = st.file_uploader("Choose a file")
256
+ uploaded_files = st.file_uploader('Upload Multiple files',accept_multiple_files=True)
257
+ if uploaded_files is not None:
258
+ list_docs, list_save_path = util_upload_file_and_return_list_docs(uploaded_files)
259
+ print('list_docs ' ,list_docs)
260
+ print('list_save_path ' , list_save_path)
261
+
262
  page_documents , passage_documents = util_get_list_page_and_passage(docs)
263
  print('len(page_documents) len(passage_documents ', len(page_documents), len(passage_documents))
264
  single_example_passage = st.text_area('Enter Query Here',"What is Governing Law ")