Abraham E. Tavarez
PDF report generator
9c93e59
raw
history blame
3.79 kB
import gradio as gr
from detector.face import verify_faces, analyze_face
from detector.voice import verify_voices
from detector.video import verify_faces_in_video
from report.report import generate_pdf_report
# Holds latest results
last_face_result = None
last_voice_result = None
last_video_results = []
def start_scan(image, audio):
return "Scanning in progress...", None
def compare_faces(img1_path, img2_path):
result = verify_faces(img1_path, img2_path)
if "error" in result:
return f"❌ Error: {result['error']}"
if result["verified"]:
return f"βœ… Match! Distance: {result['distance']:.4f} (Threshold: {result['threshold']})"
else:
return f"❌ No Match. Distance: {result['distance']:.4f} (Threshold: {result['threshold']})"
def compare_voices(audio1, audio2):
result = verify_voices(audio1, audio2)
if "error" in result:
return f"❌ Error: {result['error']}"
if result["match"]:
return f"βœ… Same speaker detected. Similarity: {result['similarity']} (Threshold: {result['threshold']})"
else:
return f"❌ Different speakers. Similarity: {result['similarity']} (Threshold: {result['threshold']})"
def scan_video(video_path, ref_img):
results = verify_faces_in_video(video_path, ref_img)
report = ""
for r in results:
if "error" in r:
report += f"\n⚠️ Frame {r['frame']}: {r['error']}"
else:
status = "βœ… Match" if r["verified"] else "❌ Mismatch"
report += f"\nπŸ–Ό Frame {r['frame']}: {status} (Distance: {r['distance']})"
return report
def generate_report():
return generate_pdf_report(last_face_result, last_voice_result, last_video_results)
with gr.Blocks(title="Deepfake Watchdog") as demo:
gr.Markdown("# πŸ›‘οΈDeepfake Watchdog πŸ€—")
gr.Markdown("## Upload your image and/or voice to scan for deepfake misuse online.")
# Face Verification
gr.Markdown("### πŸ“· Face Verification")
with gr.Tab("Face Verification"):
image = gr.Image(label="Upload your face", type="filepath")
audio = gr.Audio(label="Upload your voice (optional)", type="filepath")
run_button = gr.Button("Start Scan")
output_text = gr.Textbox(label="Status")
output_gallery = gr.Gallery(label="Matched Results")
run_button.click(
start_scan, inputs=[image, audio], outputs=[output_text, output_gallery]
)
# Voice Verification
gr.Markdown("### 🎀 Voice Verification")
with gr.Tab("🎀 Voice Verification"):
gr.Markdown("Upload two audio files to check if the voices match.")
audio1 = gr.Audio(type="filepath", label="Voice Sample 1")
audio2 = gr.Audio(type="filepath", label="Voice Sample 2")
voice_btn = gr.Button("Compare Voices")
voice_output = gr.Textbox(label="Result")
voice_btn.click(compare_voices, inputs=[audio1, audio2], outputs=voice_output)
# Video DeepFake Scan
gr.Markdown("### πŸ“Ή Video Deepfake Scan")
with gr.Tab("πŸ“Ή Video Deepfake Scan"):
gr.Markdown("Upload a video and a reference image. We'll scan for deepfake face mismatches.")
ref_img = gr.Image(type="filepath", label="Reference Face")
video_input = gr.Video(label="Video File")
scan_btn = gr.Button("Scan Video")
scan_output = gr.Textbox(label="Scan Results", lines=10)
scan_btn.click(scan_video, inputs=[video_input, ref_img], outputs=scan_output)
gr.Markdown("### πŸ“„ Generate Report")
with gr.Tab("πŸ“„ Generate Report"):
report_btn = gr.Button("Generate PDF Report")
report_output = gr.File(label="Download Report")
report_btn.click(generate_report, outputs=report_output)
demo.launch(mcp_server=True)