Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -12,14 +12,19 @@ import glob
|
|
12 |
def delete_files_except(folder_path):
|
13 |
delfile=None
|
14 |
files = glob.glob(os.path.join(folder_path, '*'))
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
|
|
17 |
return delfile
|
|
|
18 |
|
19 |
|
20 |
def MOP(path):
|
21 |
embeddings = HuggingFaceEmbeddings(model_name="BAAI/bge-m3")
|
22 |
-
template_vectors = FAISS.load_local('
|
23 |
text_chunks1=8
|
24 |
vectors_template=template_vectors
|
25 |
docs=[]
|
@@ -29,10 +34,7 @@ def MOP(path):
|
|
29 |
text_chunks2 = text_splitter.split_documents(docs)
|
30 |
vector_Document = FAISS.from_documents(text_chunks2, embedding=embeddings)
|
31 |
vectors_template.merge_from(vector_Document)
|
32 |
-
# filename_to_keep = 'Dummy_standard MoP_template_new.pdf'
|
33 |
-
|
34 |
prompt_file = delete_files_except(path)
|
35 |
-
# prompt_file=delete_files_except(filename_to_keep,path)
|
36 |
repo_id="mistralai/Mixtral-8x7B-Instruct-v0.1"
|
37 |
llm = HuggingFaceHub(repo_id=repo_id, model_kwargs={"temperature": 0.001, "max_new_tokens": 5000})
|
38 |
retriever = vectors_template.as_retriever(search_type="similarity",search_kwargs={"k": text_chunks1+len(text_chunks2)})
|
@@ -40,7 +42,7 @@ def MOP(path):
|
|
40 |
|
41 |
|
42 |
|
43 |
-
message1= f"""<s> [INST] You have two documents:
|
44 |
|
45 |
Template Document: "Standard_MoP_template.pdf"
|
46 |
Content Document: "{prompt_file}"
|
@@ -53,9 +55,9 @@ Assess whether the Content Document ("{prompt_file}") incorporates the necessary
|
|
53 |
Provide a "Yes" if the Content Document effectively integrates most of the points listed under the "Pre-Check Procedures", considering both explicit and implicit coverage.
|
54 |
If the integration is lacking or incomplete, carefully reconsider whether the points are adequately addressed within the Content Document.
|
55 |
If you provide a "Yes," provide a detailed explanation highlighting how the Content Document integrates the Pre-Check Procedures effectively. Discuss both explicit mentions and any implicit coverage that contributes to their implementation.
|
56 |
-
Make sure to accurately evaluate the alignment of the "Pre-Check Procedures" provided in the Template Document with their presence or coverage in the Content Document. [/INST] </s>"""
|
57 |
|
58 |
-
message2= f"""<s> [INST] You have two documents:
|
59 |
|
60 |
Template Document: "Standard_MoP_template.pdf"
|
61 |
Content Document: "{prompt_file}"
|
@@ -68,7 +70,7 @@ Assess whether the Content Document ("{prompt_file}") incorporates the necessary
|
|
68 |
Provide a "Yes" if the Content Document effectively integrates most of the points listed under the "Post-Check Procedures", considering both explicit and implicit coverage.
|
69 |
If the integration is lacking or incomplete, carefully reconsider whether the points are adequately addressed within the Content Document.
|
70 |
If you provide a "Yes," provide a detailed explanation highlighting how the Content Document integrates the Post-Check Procedures effectively. Discuss both explicit mentions and any implicit coverage that contributes to their implementation.
|
71 |
-
Make sure to accurately evaluate the alignment of the "Post-Check Procedures" provided in the Template Document with their presence or coverage in the Content Document. [/INST] </s>"""
|
72 |
|
73 |
result1=qa.run(message1)
|
74 |
result2=qa.run(message2)
|
@@ -96,7 +98,7 @@ Make sure to accurately evaluate the alignment of the "Post-Check Procedures" p
|
|
96 |
|
97 |
|
98 |
def process_file(fileobj):
|
99 |
-
destination_folder="
|
100 |
file_name = os.path.basename(fileobj)
|
101 |
destination_path = os.path.join(destination_folder, file_name)
|
102 |
shutil.copyfile(fileobj.name, destination_path)
|
|
|
12 |
def delete_files_except(folder_path):
|
13 |
delfile=None
|
14 |
files = glob.glob(os.path.join(folder_path, '*'))
|
15 |
+
for file in files:
|
16 |
+
if file.endswith('.pdf'):
|
17 |
+
delfile=os.path.basename(file)
|
18 |
+
os.remove(file)
|
19 |
+
else:
|
20 |
+
continue
|
21 |
return delfile
|
22 |
+
|
23 |
|
24 |
|
25 |
def MOP(path):
|
26 |
embeddings = HuggingFaceEmbeddings(model_name="BAAI/bge-m3")
|
27 |
+
template_vectors = FAISS.load_local('vector_database', embeddings, allow_dangerous_deserialization=True)
|
28 |
text_chunks1=8
|
29 |
vectors_template=template_vectors
|
30 |
docs=[]
|
|
|
34 |
text_chunks2 = text_splitter.split_documents(docs)
|
35 |
vector_Document = FAISS.from_documents(text_chunks2, embedding=embeddings)
|
36 |
vectors_template.merge_from(vector_Document)
|
|
|
|
|
37 |
prompt_file = delete_files_except(path)
|
|
|
38 |
repo_id="mistralai/Mixtral-8x7B-Instruct-v0.1"
|
39 |
llm = HuggingFaceHub(repo_id=repo_id, model_kwargs={"temperature": 0.001, "max_new_tokens": 5000})
|
40 |
retriever = vectors_template.as_retriever(search_type="similarity",search_kwargs={"k": text_chunks1+len(text_chunks2)})
|
|
|
42 |
|
43 |
|
44 |
|
45 |
+
message1= f """<s> [INST] You have two documents:
|
46 |
|
47 |
Template Document: "Standard_MoP_template.pdf"
|
48 |
Content Document: "{prompt_file}"
|
|
|
55 |
Provide a "Yes" if the Content Document effectively integrates most of the points listed under the "Pre-Check Procedures", considering both explicit and implicit coverage.
|
56 |
If the integration is lacking or incomplete, carefully reconsider whether the points are adequately addressed within the Content Document.
|
57 |
If you provide a "Yes," provide a detailed explanation highlighting how the Content Document integrates the Pre-Check Procedures effectively. Discuss both explicit mentions and any implicit coverage that contributes to their implementation.
|
58 |
+
Make sure to accurately evaluate the alignment of the "Pre-Check Procedures" provided in the Template Document with their presence or coverage in the Content Document. [/INST] </s> """
|
59 |
|
60 |
+
message2= f """<s> [INST] You have two documents:
|
61 |
|
62 |
Template Document: "Standard_MoP_template.pdf"
|
63 |
Content Document: "{prompt_file}"
|
|
|
70 |
Provide a "Yes" if the Content Document effectively integrates most of the points listed under the "Post-Check Procedures", considering both explicit and implicit coverage.
|
71 |
If the integration is lacking or incomplete, carefully reconsider whether the points are adequately addressed within the Content Document.
|
72 |
If you provide a "Yes," provide a detailed explanation highlighting how the Content Document integrates the Post-Check Procedures effectively. Discuss both explicit mentions and any implicit coverage that contributes to their implementation.
|
73 |
+
Make sure to accurately evaluate the alignment of the "Post-Check Procedures" provided in the Template Document with their presence or coverage in the Content Document. [/INST] </s> """
|
74 |
|
75 |
result1=qa.run(message1)
|
76 |
result2=qa.run(message2)
|
|
|
98 |
|
99 |
|
100 |
def process_file(fileobj):
|
101 |
+
destination_folder="data"
|
102 |
file_name = os.path.basename(fileobj)
|
103 |
destination_path = os.path.join(destination_folder, file_name)
|
104 |
shutil.copyfile(fileobj.name, destination_path)
|