|
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 |
|
|
|
|
|
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.") |
|
|
|
|
|
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] |
|
) |
|
|
|
|
|
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) |
|
|
|
|
|
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) |
|
|