Spaces:
Sleeping
Sleeping
Add __init__.py to output/ to fix import error and include output/ in repo
Browse files- output/__init__.py +0 -0
- output/pdf_generator.py +82 -0
- output/report.json +23 -0
- output/report_generator.py +5 -0
output/__init__.py
ADDED
|
File without changes
|
output/pdf_generator.py
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
from reportlab.lib.pagesizes import letter
|
| 3 |
+
from reportlab.pdfgen import canvas
|
| 4 |
+
from reportlab.lib import colors
|
| 5 |
+
from reportlab.platypus import SimpleDocTemplate, Table, TableStyle, Paragraph, Spacer
|
| 6 |
+
from reportlab.lib.styles import getSampleStyleSheet
|
| 7 |
+
from .output.pdf_generator import generate_pdf_report
|
| 8 |
+
import io
|
| 9 |
+
|
| 10 |
+
def generate_pdf_report(results):
|
| 11 |
+
"""
|
| 12 |
+
Generates a PDF report from analysis results.
|
| 13 |
+
Args:
|
| 14 |
+
results: List of dictionaries containing analysis findings.
|
| 15 |
+
Returns:
|
| 16 |
+
bytes: PDF file content.
|
| 17 |
+
"""
|
| 18 |
+
buffer = io.BytesIO()
|
| 19 |
+
doc = SimpleDocTemplate(buffer, pagesize=letter)
|
| 20 |
+
elements = []
|
| 21 |
+
|
| 22 |
+
styles = getSampleStyleSheet()
|
| 23 |
+
title_style = styles['Title']
|
| 24 |
+
heading_style = styles['Heading2']
|
| 25 |
+
normal_style = styles['Normal']
|
| 26 |
+
|
| 27 |
+
# Title
|
| 28 |
+
elements.append(Paragraph("Semantic Integrity Analysis Report", title_style))
|
| 29 |
+
elements.append(Spacer(1, 12))
|
| 30 |
+
|
| 31 |
+
if not results:
|
| 32 |
+
elements.append(Paragraph("No integrity issues detected.", normal_style))
|
| 33 |
+
else:
|
| 34 |
+
# Summary
|
| 35 |
+
elements.append(Paragraph(f"Total Potential Issues Found: {len(results)}", normal_style))
|
| 36 |
+
elements.append(Spacer(1, 12))
|
| 37 |
+
|
| 38 |
+
# Table Header
|
| 39 |
+
data = [['S.No', 'Label', 'Loc', 'Reason']]
|
| 40 |
+
|
| 41 |
+
# Table Data
|
| 42 |
+
for idx, r in enumerate(results):
|
| 43 |
+
# Text wrapping for table cells needs explicit Paragraph usage usually,
|
| 44 |
+
# but for simplicity we truncate or just list them.
|
| 45 |
+
# To make it robust, we'll list details below the table or keep table simple.
|
| 46 |
+
row = [
|
| 47 |
+
str(idx + 1),
|
| 48 |
+
r.get('Label', 'N/A'),
|
| 49 |
+
r.get('Location 1', '').replace('Pg ', 'P').replace('Ln ', 'L'),
|
| 50 |
+
r.get('Reason', 'N/A')
|
| 51 |
+
]
|
| 52 |
+
data.append(row)
|
| 53 |
+
|
| 54 |
+
# Create Table
|
| 55 |
+
t = Table(data, colWidths=[30, 90, 60, 320])
|
| 56 |
+
t.setStyle(TableStyle([
|
| 57 |
+
('BACKGROUND', (0, 0), (-1, 0), colors.grey),
|
| 58 |
+
('TEXTCOLOR', (0, 0), (-1, 0), colors.whitesmoke),
|
| 59 |
+
('ALIGN', (0, 0), (-1, -1), 'LEFT'),
|
| 60 |
+
('FONTNAME', (0, 0), (-1, 0), 'Helvetica-Bold'),
|
| 61 |
+
('BOTTOMPADDING', (0, 0), (-1, 0), 12),
|
| 62 |
+
('BACKGROUND', (0, 1), (-1, -1), colors.beige),
|
| 63 |
+
('GRID', (0, 0), (-1, -1), 1, colors.black),
|
| 64 |
+
]))
|
| 65 |
+
elements.append(t)
|
| 66 |
+
|
| 67 |
+
elements.append(Spacer(1, 24))
|
| 68 |
+
|
| 69 |
+
# Detailed Findings
|
| 70 |
+
elements.append(Paragraph("Detailed Findings", heading_style))
|
| 71 |
+
for idx, r in enumerate(results):
|
| 72 |
+
elements.append(Paragraph(f"<b>Issue #{idx + 1}: {r.get('Label')}</b>", normal_style))
|
| 73 |
+
elements.append(Paragraph(f"<i>Reason:</i> {r.get('Reason')}", normal_style))
|
| 74 |
+
elements.append(Paragraph(f"<i>Clause 1:</i> {r.get('Clause 1')}", normal_style))
|
| 75 |
+
elements.append(Paragraph(f"<i>Clause 2:</i> {r.get('Clause 2')}", normal_style))
|
| 76 |
+
elements.append(Spacer(1, 12))
|
| 77 |
+
elements.append(Paragraph("-" * 60, normal_style))
|
| 78 |
+
elements.append(Spacer(1, 12))
|
| 79 |
+
|
| 80 |
+
doc.build(elements)
|
| 81 |
+
buffer.seek(0)
|
| 82 |
+
return buffer.getvalue()
|
output/report.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"type": "Duplication",
|
| 4 |
+
"clause_1": "The organization retains all user data for a period of five (5) years from the date of collection.",
|
| 5 |
+
"clause_2": "The organization retains all user data for a period of five (5) years from the date of collection.",
|
| 6 |
+
"confidence": 1.0,
|
| 7 |
+
"explanation": "High semantic similarity (>90%)"
|
| 8 |
+
},
|
| 9 |
+
{
|
| 10 |
+
"type": "Contradiction",
|
| 11 |
+
"clause_1": "All cloud storage providers must comply with ISO 27001 security standards.",
|
| 12 |
+
"clause_2": "Cloud vendors are encouraged, but not required, to follow ISO 27001 standards.",
|
| 13 |
+
"confidence": 0.71,
|
| 14 |
+
"explanation": "Logical opposition (Assertion vs Negation)"
|
| 15 |
+
},
|
| 16 |
+
{
|
| 17 |
+
"type": "Contradiction",
|
| 18 |
+
"clause_1": "Users shall have full access to modify or delete their personal data at any time.",
|
| 19 |
+
"clause_2": "Users are not permitted to modify or delete their personal data once it has been submitted.",
|
| 20 |
+
"confidence": 0.67,
|
| 21 |
+
"explanation": "Logical opposition (Assertion vs Negation)"
|
| 22 |
+
}
|
| 23 |
+
]
|
output/report_generator.py
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
|
| 3 |
+
def generate_report(results, path="output/report.json"):
|
| 4 |
+
with open(path, "w") as f:
|
| 5 |
+
json.dump(results, f, indent=4)
|