Spaces:
Sleeping
Sleeping
karthikeyan-r
commited on
Commit
•
6c16a5c
1
Parent(s):
44eac94
Update app.py
Browse files
app.py
CHANGED
@@ -107,33 +107,31 @@ def save_uploaded_file(uploaded_file, path):
|
|
107 |
|
108 |
# Streamlit UI
|
109 |
st.title('PDF Similarity Checker')
|
110 |
-
|
111 |
col1, col2 = st.columns(2)
|
112 |
-
|
113 |
# Clear the templates and contracts folders before uploading new files
|
114 |
templates_folder = './templates'
|
115 |
contracts_folder = './contracts'
|
116 |
-
|
117 |
-
clear_folder(
|
118 |
-
clear_folder(contracts_folder)
|
119 |
|
120 |
with col1:
|
121 |
st.header("Upload Templates")
|
122 |
-
uploaded_files_templates = st.file_uploader("
|
123 |
os.makedirs(templates_folder, exist_ok=True)
|
124 |
for uploaded_file in uploaded_files_templates:
|
125 |
-
if save_uploaded_file(uploaded_file, templates_folder):
|
126 |
st.write(f"Saved: {uploaded_file.name}")
|
127 |
|
128 |
with col2:
|
129 |
st.header("Upload Contracts")
|
130 |
-
uploaded_files_contracts = st.file_uploader("
|
131 |
os.makedirs(contracts_folder, exist_ok=True)
|
132 |
for uploaded_file in uploaded_files_contracts:
|
133 |
-
if save_uploaded_file(uploaded_file, contracts_folder):
|
134 |
st.write(f"Saved: {uploaded_file.name}")
|
135 |
|
136 |
-
model_name = st.selectbox("Select Model", ['sentence-transformers/multi-qa-mpnet-base-dot-v1'], index=0)
|
137 |
|
138 |
if st.button("Compute Similarities"):
|
139 |
pdf_processor = PDFProcessor()
|
@@ -150,7 +148,7 @@ if st.button("Compute Similarities"):
|
|
150 |
contract_embeddings = embedding_processor.get_embeddings(contract_texts)
|
151 |
|
152 |
# Compute similarities
|
153 |
-
similarities = compute_similarity(template_embeddings, contract_embeddings)
|
154 |
|
155 |
# Display results in a table format
|
156 |
similarity_data = []
|
@@ -166,20 +164,23 @@ if st.button("Compute Similarities"):
|
|
166 |
# Create a DataFrame for the table
|
167 |
columns = ["SI No", "Contract"] + [os.path.basename(template_files[j]) for j in range(len(template_files))]
|
168 |
similarity_df = pd.DataFrame(similarity_data, columns=columns)
|
169 |
-
|
170 |
-
|
171 |
-
if st.checkbox("Maximize Table View"):
|
172 |
-
st.write("Similarity Scores Table (Maximized):")
|
173 |
-
st.dataframe(similarity_df) # Maximized view
|
174 |
else:
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
|
108 |
# Streamlit UI
|
109 |
st.title('PDF Similarity Checker')
|
110 |
+
confirmationEdit = Modal("Contract Comparizer", key= "popUp_edit")
|
111 |
col1, col2 = st.columns(2)
|
|
|
112 |
# Clear the templates and contracts folders before uploading new files
|
113 |
templates_folder = './templates'
|
114 |
contracts_folder = './contracts'
|
115 |
+
SimilarityCalculator.clear_folder(templates_folder)
|
116 |
+
SimilarityCalculator.clear_folder(contracts_folder)
|
|
|
117 |
|
118 |
with col1:
|
119 |
st.header("Upload Templates")
|
120 |
+
uploaded_files_templates = st.file_uploader("PDF Template", accept_multiple_files=True, type=['pdf'])
|
121 |
os.makedirs(templates_folder, exist_ok=True)
|
122 |
for uploaded_file in uploaded_files_templates:
|
123 |
+
if SimilarityCalculator.save_uploaded_file(uploaded_file, templates_folder):
|
124 |
st.write(f"Saved: {uploaded_file.name}")
|
125 |
|
126 |
with col2:
|
127 |
st.header("Upload Contracts")
|
128 |
+
uploaded_files_contracts = st.file_uploader("PDF Contracts", key="contracts", accept_multiple_files=True, type=['pdf'])
|
129 |
os.makedirs(contracts_folder, exist_ok=True)
|
130 |
for uploaded_file in uploaded_files_contracts:
|
131 |
+
if SimilarityCalculator.save_uploaded_file(uploaded_file, contracts_folder):
|
132 |
st.write(f"Saved: {uploaded_file.name}")
|
133 |
|
134 |
+
model_name = st.selectbox("Select Model", ['sentence-transformers/all-mpnet-base-v2','sentence-transformers/all-MiniLM-L6-v2','sentence-transformers/multi-qa-mpnet-base-dot-v1','sentence-transformers/multi-qa-MiniLM-L6-cos-v1'], index=0)
|
135 |
|
136 |
if st.button("Compute Similarities"):
|
137 |
pdf_processor = PDFProcessor()
|
|
|
148 |
contract_embeddings = embedding_processor.get_embeddings(contract_texts)
|
149 |
|
150 |
# Compute similarities
|
151 |
+
similarities = SimilarityCalculator.compute_similarity(template_embeddings, contract_embeddings)
|
152 |
|
153 |
# Display results in a table format
|
154 |
similarity_data = []
|
|
|
164 |
# Create a DataFrame for the table
|
165 |
columns = ["SI No", "Contract"] + [os.path.basename(template_files[j]) for j in range(len(template_files))]
|
166 |
similarity_df = pd.DataFrame(similarity_data, columns=columns)
|
167 |
+
if similarity_df.empty:
|
168 |
+
st.write("No similarities computed.")
|
|
|
|
|
|
|
169 |
else:
|
170 |
+
with confirmationEdit.container():
|
171 |
+
st.write("Similarity Scores Table:")
|
172 |
+
st.table(similarity_df.style.hide(axis="index"))
|
173 |
+
|
174 |
+
if st.button('Close Window'):
|
175 |
+
confirmationEdit.close()
|
176 |
+
|
177 |
+
submitted = st.button("Show Result")
|
178 |
+
if submitted:
|
179 |
+
confirmationEdit.open()
|
180 |
+
if confirmationEdit.is_open():
|
181 |
+
with confirmationEdit.container():
|
182 |
+
st.write("Similarity Scores Table:")
|
183 |
+
st.table(similarity_df.style.hide(axis="index"))
|
184 |
+
|
185 |
+
if st.button('Close Result'):
|
186 |
+
confirmationEdit.close()
|