Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,7 +8,6 @@ import difflib
|
|
8 |
from sklearn.feature_extraction.text import TfidfVectorizer
|
9 |
from sklearn.metrics.pairwise import cosine_similarity
|
10 |
from sentence_transformers import SentenceTransformer, util
|
11 |
-
from fpdf import FPDF
|
12 |
|
13 |
# ========== CONFIGURATION ==========
|
14 |
st.set_page_config(
|
@@ -105,32 +104,6 @@ def calculate_similarity(text1, text2):
|
|
105 |
st.error(f"Similarity calculation error: {e}")
|
106 |
return 0.0
|
107 |
|
108 |
-
def generate_pdf_report(similarity_score, doc1, doc2):
|
109 |
-
pdf = FPDF()
|
110 |
-
pdf.add_page()
|
111 |
-
pdf.set_auto_page_break(auto=True, margin=15)
|
112 |
-
|
113 |
-
pdf.set_font("Arial", 'B', 16)
|
114 |
-
pdf.cell(0, 10, "Contract Comparison Report", ln=True, align="C")
|
115 |
-
|
116 |
-
pdf.set_font("Arial", '', 12)
|
117 |
-
pdf.ln(10)
|
118 |
-
pdf.multi_cell(0, 10, f"Document Similarity Score: {similarity_score:.2f}%")
|
119 |
-
|
120 |
-
pdf.ln(5)
|
121 |
-
pdf.set_font("Arial", 'B', 12)
|
122 |
-
pdf.cell(0, 10, "Document 1 Excerpt:", ln=True)
|
123 |
-
pdf.set_font("Arial", '', 10)
|
124 |
-
pdf.multi_cell(0, 10, doc1[:1000])
|
125 |
-
|
126 |
-
pdf.ln(5)
|
127 |
-
pdf.set_font("Arial", 'B', 12)
|
128 |
-
pdf.cell(0, 10, "Document 2 Excerpt:", ln=True)
|
129 |
-
pdf.set_font("Arial", '', 10)
|
130 |
-
pdf.multi_cell(0, 10, doc2[:1000])
|
131 |
-
|
132 |
-
return pdf.output(dest='S').encode('latin1')
|
133 |
-
|
134 |
def load_contract(file):
|
135 |
if file is None:
|
136 |
return ""
|
@@ -229,20 +202,6 @@ def main():
|
|
229 |
st.markdown("### Modified Document")
|
230 |
st.markdown(f'<div style="border:1px solid #ccc; padding:10px; white-space: pre-wrap; font-family: monospace; font-size: 0.9em; max-height: 500px; overflow-y: auto;">{st.session_state.comparison_results["highlighted_diff2"]}</div>', unsafe_allow_html=True)
|
231 |
|
232 |
-
if st.button("Download PDF Report"):
|
233 |
-
with st.spinner("Generating report..."):
|
234 |
-
pdf_bytes = generate_pdf_report(
|
235 |
-
st.session_state.comparison_results['similarity_score'],
|
236 |
-
contract_text1,
|
237 |
-
contract_text2
|
238 |
-
)
|
239 |
-
st.download_button(
|
240 |
-
label="Click to download PDF",
|
241 |
-
data=pdf_bytes,
|
242 |
-
file_name="contract_comparison_report.pdf",
|
243 |
-
mime="application/pdf"
|
244 |
-
)
|
245 |
-
|
246 |
st.header("3. Clause Analysis")
|
247 |
|
248 |
try:
|
@@ -293,4 +252,4 @@ def main():
|
|
293 |
st.success(st.session_state.analysis_results.get('doc2', 'No analysis performed yet'))
|
294 |
|
295 |
if __name__ == "__main__":
|
296 |
-
main()
|
|
|
8 |
from sklearn.feature_extraction.text import TfidfVectorizer
|
9 |
from sklearn.metrics.pairwise import cosine_similarity
|
10 |
from sentence_transformers import SentenceTransformer, util
|
|
|
11 |
|
12 |
# ========== CONFIGURATION ==========
|
13 |
st.set_page_config(
|
|
|
104 |
st.error(f"Similarity calculation error: {e}")
|
105 |
return 0.0
|
106 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
def load_contract(file):
|
108 |
if file is None:
|
109 |
return ""
|
|
|
202 |
st.markdown("### Modified Document")
|
203 |
st.markdown(f'<div style="border:1px solid #ccc; padding:10px; white-space: pre-wrap; font-family: monospace; font-size: 0.9em; max-height: 500px; overflow-y: auto;">{st.session_state.comparison_results["highlighted_diff2"]}</div>', unsafe_allow_html=True)
|
204 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
205 |
st.header("3. Clause Analysis")
|
206 |
|
207 |
try:
|
|
|
252 |
st.success(st.session_state.analysis_results.get('doc2', 'No analysis performed yet'))
|
253 |
|
254 |
if __name__ == "__main__":
|
255 |
+
main()
|