|
from fpdf import FPDF |
|
import os |
|
import datetime |
|
|
|
|
|
class ReportGenerator(FPDF): |
|
def header(self): |
|
self.set_font("Arial", "B", 16) |
|
self.cell(0, 10, "Deepfake Watchdog Report", ln=1, align="C") |
|
self.ln(5) |
|
|
|
def add_section_title(self, title): |
|
self.set_font("Arial", "B", 12) |
|
self.cell(0, 10, title, ln=1, align="L") |
|
self.ln(2) |
|
|
|
def add_text(self, text): |
|
self.set_font("Arial", "", 12) |
|
safe_text = str(text) if text is not None else "" |
|
self.multi_cell(0, 8, safe_text) |
|
self.ln(2) |
|
|
|
def add_image(self, image_path, w=60): |
|
if os.path.exists(image_path): |
|
self.image(image_path, w=w) |
|
self.ln(5) |
|
else: |
|
print(f"Image not found: {image_path}") |
|
|
|
|
|
|
|
def clean_text(text): |
|
return ( |
|
text.replace("β
", "[MATCH]") |
|
.replace("β", "[NO MATCH]") |
|
.replace("β οΈ", "[WARNING]") |
|
) |
|
|
|
|
|
|
|
def generate_pdf_report( |
|
face_result, |
|
voice_result, |
|
video_results, |
|
output_path=f"report{datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S')}.pdf", |
|
): |
|
pdf = ReportGenerator() |
|
pdf.add_page() |
|
|
|
print("Generating PDF report...") |
|
print(face_result) |
|
print(voice_result) |
|
print(video_results) |
|
|
|
|
|
if face_result: |
|
pdf.add_section_title("Face Verification Results") |
|
pdf.add_text(clean_text(face_result)) |
|
|
|
|
|
if voice_result: |
|
pdf.add_section_title("Voice Verification Results") |
|
pdf.add_text(clean_text(voice_result)) |
|
|
|
|
|
if video_results: |
|
pdf.add_section_title("Video Verification Results") |
|
|
|
for frame in video_results: |
|
if "error" in frame: |
|
pdf.add_text(clean_text(f"{frame['frame']}: ERROR - {frame['error']}")) |
|
else: |
|
status = "β
Match" if frame["verified"] else "β Mismatch" |
|
pdf.add_text( |
|
clean_text(f"{frame['frame']} - {status} (Distance: {frame['distance']})") |
|
) |
|
|
|
if not frame["verified"]: |
|
pdf.add_image(frame["frame"], w=80) |
|
|
|
pdf.output(output_path) |
|
print(f"PDF report generated at: {output_path}") |
|
return output_path |
|
|