ppsingh commited on
Commit
3829a5f
1 Parent(s): 5be75f1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -8
app.py CHANGED
@@ -20,7 +20,7 @@ from dotenv import load_dotenv
20
  load_dotenv()
21
  HF_token = os.environ["HF_TOKEN"]
22
  # process all files and get the vectorstores collections
23
- #vectorstores = process_pdf()
24
 
25
  # -------------------------------------------------------------
26
  # Functions
@@ -83,18 +83,33 @@ async def chat(query,history,sources,reports,subtype,year):
83
  #print(f"audience:{audience}")
84
  print(f"sources:{sources}")
85
  print(f"reports:{reports}")
86
- print(f"reports:{subtype}")
87
- print(f"reports:{year}")
88
  docs_html = ""
89
  output_query = ""
90
 
91
-
92
  if len(reports) == 0:
93
- print(sources)
94
- #vectorstore = vectorstores[sources]
95
  else:
96
- print(reports)
97
- #vectorstore = vectorstores["allreports"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
 
99
 
100
  yield history,docs_html
 
20
  load_dotenv()
21
  HF_token = os.environ["HF_TOKEN"]
22
  # process all files and get the vectorstores collections
23
+ process_pdf()
24
 
25
  # -------------------------------------------------------------
26
  # Functions
 
83
  #print(f"audience:{audience}")
84
  print(f"sources:{sources}")
85
  print(f"reports:{reports}")
86
+ print(f"subtype:{subtype}")
87
+ print(f"year:{year}")
88
  docs_html = ""
89
  output_query = ""
90
 
91
+ ##------------------------decide which collection to fetch------------------------------
92
  if len(reports) == 0:
93
+ vectorstore = vectorstores[sources]
 
94
  else:
95
+ vectorstore = vectorstores["allreports"]
96
+
97
+ ##------------------------------get context----------------------------------------------------
98
+ context_retrieved_lst = []
99
+ question_lst= [query]
100
+ for question in question_lst:
101
+ retriever = vectorstore.as_retriever(
102
+ search_type="similarity_score_threshold", search_kwargs={"score_threshold": 0.6, "k": 3})
103
+
104
+ context_retrieved = retriever.invoke(question)
105
+
106
+ def format_docs(docs):
107
+ return "\n\n".join(doc.page_content for doc in docs)
108
+
109
+ context_retrieved_formatted = format_docs(context_retrieved)
110
+ context_retrieved_lst.append(context_retrieved_formatted)
111
+ print(context_retrieved_lst)
112
+
113
 
114
 
115
  yield history,docs_html