ShivanshMathur007 commited on
Commit
51081c4
1 Parent(s): 024e407

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -11
app.py CHANGED
@@ -10,17 +10,15 @@ import re
10
  import shutil
11
  import glob
12
  def delete_files_except(filename, folder_path):
 
13
  files = glob.glob(os.path.join(folder_path, '*'))
14
  for file in files:
15
  if os.path.basename(file) == filename:
16
  continue
17
  else:
18
- try:
19
- os.remove(file)
20
- print(f"Deleted: {file}")
21
- except Exception as e:
22
- print(f"Error deleting {file}: {e}")
23
-
24
  def MOP(path):
25
  docs=[]
26
  loader = PyPDFDirectoryLoader(path)
@@ -30,15 +28,15 @@ def MOP(path):
30
  embeddings = HuggingFaceEmbeddings(model_name="thenlper/gte-base")
31
  vector_store = FAISS.from_documents(text_chunks, embedding=embeddings)
32
  filename_to_keep = 'Dummy_standard MoP_template_new.pdf'
33
- delete_files_except(filename_to_keep,path)
34
  repo_id="mistralai/Mixtral-8x7B-Instruct-v0.1"
35
  llm = HuggingFaceHub(repo_id=repo_id, model_kwargs={"temperature": 0.1, "max_new_tokens": 2048})
36
  retriever = vector_store.as_retriever(search_type="similarity",search_kwargs={"k": len(text_chunks)})
37
  qa = RetrievalQA.from_chain_type(llm=llm, chain_type="stuff", retriever=retriever,verbose=True)
38
- message= """<s> [INST] You have two documents:
39
 
40
  Template Document: "Dummy_standard MoP_template_new.pdf"
41
- Content Document: "Fully_Standard_MOP_of_Activation_Carrier_Aggregaton_in_v1.pdf"
42
 
43
  Your task is to determine whether the Content Document effectively incorporates the context and instructions of the Pre-Check Procedures and Post-Check Procedures specified in the Template Document, without the requirement for them to be under specified labels. The focus should be on the presence of the context and instructions rather than their exact placement.
44
 
@@ -49,10 +47,10 @@ Additionally, identify any missing elements related to the context and instructi
49
  Instructions:
50
 
51
  Review the context and instructions of the Pre-Check Procedures and Post-Check Procedures detailed in the Template Document ("Dummy_standard MoP_template_new.pdf").
52
- Assess whether the Content Document ("Fully_Standard_MOP_of_Activation_Carrier_Aggregaton_in_v1.pdf") includes the necessary context and instructions for the Pre-Check Procedures and Post-Check Procedures, regardless of their specific placement or labeling.
53
  Provide a "Yes" if the Content Document adequately integrates the context and instructions of the Pre-Check Procedures and Post-Check Procedures, or "No" if there are significant gaps or omissions.
54
  If the answer is "No," specify any missing elements related to the context and instructions of the Pre-Check Procedures and Post-Check Procedures, emphasizing their importance in the Content Document.
55
- Ensure careful consideration of the context and instructions provided in the Template Document ("Dummy_standard MoP_template_new.pdf") while evaluating the alignment of the Content Document ("Fully_Standard_MOP_of_Activation_Carrier_Aggregaton_in_v1.pdf"). [/INST] </s>"""
56
  result=qa.run(message)
57
  pattern = r"Helpful Answer:\n\n(.*)"
58
  match = re.search(pattern, result, re.DOTALL)
 
10
  import shutil
11
  import glob
12
  def delete_files_except(filename, folder_path):
13
+ delfile=None
14
  files = glob.glob(os.path.join(folder_path, '*'))
15
  for file in files:
16
  if os.path.basename(file) == filename:
17
  continue
18
  else:
19
+ delfile=os.path.basename(file)
20
+ os.remove(file)
21
+ return delfile
 
 
 
22
  def MOP(path):
23
  docs=[]
24
  loader = PyPDFDirectoryLoader(path)
 
28
  embeddings = HuggingFaceEmbeddings(model_name="thenlper/gte-base")
29
  vector_store = FAISS.from_documents(text_chunks, embedding=embeddings)
30
  filename_to_keep = 'Dummy_standard MoP_template_new.pdf'
31
+ prompt_file=delete_files_except(filename_to_keep,path)
32
  repo_id="mistralai/Mixtral-8x7B-Instruct-v0.1"
33
  llm = HuggingFaceHub(repo_id=repo_id, model_kwargs={"temperature": 0.1, "max_new_tokens": 2048})
34
  retriever = vector_store.as_retriever(search_type="similarity",search_kwargs={"k": len(text_chunks)})
35
  qa = RetrievalQA.from_chain_type(llm=llm, chain_type="stuff", retriever=retriever,verbose=True)
36
+ message= f"""<s> [INST] You have two documents:
37
 
38
  Template Document: "Dummy_standard MoP_template_new.pdf"
39
+ Content Document: {prompt_file}
40
 
41
  Your task is to determine whether the Content Document effectively incorporates the context and instructions of the Pre-Check Procedures and Post-Check Procedures specified in the Template Document, without the requirement for them to be under specified labels. The focus should be on the presence of the context and instructions rather than their exact placement.
42
 
 
47
  Instructions:
48
 
49
  Review the context and instructions of the Pre-Check Procedures and Post-Check Procedures detailed in the Template Document ("Dummy_standard MoP_template_new.pdf").
50
+ Assess whether the Content Document ({prompt_file}) includes the necessary context and instructions for the Pre-Check Procedures and Post-Check Procedures, regardless of their specific placement or labeling.
51
  Provide a "Yes" if the Content Document adequately integrates the context and instructions of the Pre-Check Procedures and Post-Check Procedures, or "No" if there are significant gaps or omissions.
52
  If the answer is "No," specify any missing elements related to the context and instructions of the Pre-Check Procedures and Post-Check Procedures, emphasizing their importance in the Content Document.
53
+ Ensure careful consideration of the context and instructions provided in the Template Document ("Dummy_standard MoP_template_new.pdf") while evaluating the alignment of the Content Document ({prompt_file}). [/INST] </s>"""
54
  result=qa.run(message)
55
  pattern = r"Helpful Answer:\n\n(.*)"
56
  match = re.search(pattern, result, re.DOTALL)