Abraham E. Tavarez
commited on
Commit
·
9c93e59
1
Parent(s):
342ea4d
PDF report generator
Browse files- app.py +15 -1
- report/report.py +57 -0
app.py
CHANGED
@@ -2,12 +2,17 @@ import gradio as gr
|
|
2 |
from detector.face import verify_faces, analyze_face
|
3 |
from detector.voice import verify_voices
|
4 |
from detector.video import verify_faces_in_video
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
|
7 |
def start_scan(image, audio):
|
8 |
return "Scanning in progress...", None
|
9 |
|
10 |
-
|
11 |
def compare_faces(img1_path, img2_path):
|
12 |
result = verify_faces(img1_path, img2_path)
|
13 |
|
@@ -45,6 +50,8 @@ def scan_video(video_path, ref_img):
|
|
45 |
|
46 |
return report
|
47 |
|
|
|
|
|
48 |
|
49 |
|
50 |
with gr.Blocks(title="Deepfake Watchdog") as demo:
|
@@ -91,5 +98,12 @@ with gr.Blocks(title="Deepfake Watchdog") as demo:
|
|
91 |
scan_btn.click(scan_video, inputs=[video_input, ref_img], outputs=scan_output)
|
92 |
|
93 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
|
95 |
demo.launch(mcp_server=True)
|
|
|
2 |
from detector.face import verify_faces, analyze_face
|
3 |
from detector.voice import verify_voices
|
4 |
from detector.video import verify_faces_in_video
|
5 |
+
from report.report import generate_pdf_report
|
6 |
+
|
7 |
+
# Holds latest results
|
8 |
+
last_face_result = None
|
9 |
+
last_voice_result = None
|
10 |
+
last_video_results = []
|
11 |
|
12 |
|
13 |
def start_scan(image, audio):
|
14 |
return "Scanning in progress...", None
|
15 |
|
|
|
16 |
def compare_faces(img1_path, img2_path):
|
17 |
result = verify_faces(img1_path, img2_path)
|
18 |
|
|
|
50 |
|
51 |
return report
|
52 |
|
53 |
+
def generate_report():
|
54 |
+
return generate_pdf_report(last_face_result, last_voice_result, last_video_results)
|
55 |
|
56 |
|
57 |
with gr.Blocks(title="Deepfake Watchdog") as demo:
|
|
|
98 |
scan_btn.click(scan_video, inputs=[video_input, ref_img], outputs=scan_output)
|
99 |
|
100 |
|
101 |
+
gr.Markdown("### 📄 Generate Report")
|
102 |
+
with gr.Tab("📄 Generate Report"):
|
103 |
+
report_btn = gr.Button("Generate PDF Report")
|
104 |
+
report_output = gr.File(label="Download Report")
|
105 |
+
|
106 |
+
report_btn.click(generate_report, outputs=report_output)
|
107 |
+
|
108 |
|
109 |
demo.launch(mcp_server=True)
|
report/report.py
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fpdf import FPDF
|
2 |
+
import os
|
3 |
+
import datetime
|
4 |
+
|
5 |
+
class ReportGenerator(FPDF):
|
6 |
+
def header(self):
|
7 |
+
self.set_font("Arial", "B", 16)
|
8 |
+
self.cell(0, 10, "Deepfake Watchdog Report", ln=1, align="C")
|
9 |
+
self.ln(5)
|
10 |
+
|
11 |
+
def add_section_title(self, title):
|
12 |
+
self.set_font("Arial", "B", 12)
|
13 |
+
self.cell(0, 10, title, ln=1, align="L")
|
14 |
+
self.ln(2)
|
15 |
+
|
16 |
+
def add_text(self, text):
|
17 |
+
self.set_font("Arial", "", 12)
|
18 |
+
self.multi_cell(0, 8, text)
|
19 |
+
self.ln(2)
|
20 |
+
|
21 |
+
def add_image(self, image_path, w=60):
|
22 |
+
if os.path.exists(image_path):
|
23 |
+
self.image(image_path, w=w)
|
24 |
+
self.ln(5)
|
25 |
+
else:
|
26 |
+
print(f"Image not found: {image_path}")
|
27 |
+
|
28 |
+
# Generate PDF Report
|
29 |
+
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"):
|
30 |
+
pdf = ReportGenerator()
|
31 |
+
pdf.add_page()
|
32 |
+
|
33 |
+
# Section 1: Face Verification
|
34 |
+
pdf.add_section_title("Face Verification Results")
|
35 |
+
pdf.add_text(face_result)
|
36 |
+
|
37 |
+
# Section 2: Voice Verification
|
38 |
+
pdf.add_section_title("Voice Verification Results")
|
39 |
+
pdf.add_text(voice_result)
|
40 |
+
|
41 |
+
# Section 3: Video Verification
|
42 |
+
pdf.add_section_title("Video Verification Results")
|
43 |
+
|
44 |
+
for frame in video_results:
|
45 |
+
if "error" in frame:
|
46 |
+
pdf.add_text(f"{frame['frame']}: ERROR - {frame['error']}")
|
47 |
+
else:
|
48 |
+
status = "✅ Match" if frame["verified"] else "❌ Mismatch"
|
49 |
+
pdf.add_text(f"{frame['frame']} - {status} (Distance: {frame['distance']})")
|
50 |
+
|
51 |
+
if not frame["verified"]:
|
52 |
+
pdf.add_image(frame["frame"], w=80)
|
53 |
+
|
54 |
+
pdf.output(output_path)
|
55 |
+
print(f"PDF report generated at: {output_path}")
|
56 |
+
return output_path
|
57 |
+
|