File size: 2,378 Bytes
a340f3e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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}")


# Replace emojis with text equivalents
def clean_text(text):
    return (
        text.replace("✅", "[MATCH]")
        .replace("❌", "[NO MATCH]")
        .replace("⚠️", "[WARNING]")
    )


# Generate PDF Report
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)
    
    # Section 1: Face Verification
    if face_result:
        pdf.add_section_title("Face Verification Results")
        pdf.add_text(clean_text(face_result))

    # Section 2: Voice Verification
    if voice_result:
        pdf.add_section_title("Voice Verification Results")
        pdf.add_text(clean_text(voice_result))

    # Section 3: Video Verification
    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