Spaces:
Sleeping
Sleeping
File size: 1,333 Bytes
e89e5f9 0cb9695 e89e5f9 9e0f3c3 e89e5f9 c0beb72 e89e5f9 0cb9695 9e0f3c3 e89e5f9 04bb1f8 |
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 |
import gradio as gr
import numpy as np
import cv2
from prediction import Prediction
# Initialize the Prediction class
predictor = Prediction()
def inference(video):
"""
Gradio-compatible inference function.
Args:
video (str): Path to the uploaded video file
Returns:
tuple: (Prediction string, Grad-CAM image, Classification details)
"""
prediction, gradcam_image, classification_details = predictor.predict(video)
# Convert Grad-CAM image to RGB for display in Gradio
if gradcam_image is not None:
gradcam_image = cv2.cvtColor(gradcam_image, cv2.COLOR_BGR2RGB)
else:
gradcam_image = np.zeros((256, 256, 3), dtype=np.uint8) # fallback image
return prediction, gradcam_image, classification_details
# Define Gradio interface
demo = gr.Interface(
fn=inference,
inputs=gr.Video(label="Upload a video"),
outputs=[
gr.Textbox(label="Prediction"),
gr.Image(label="Grad-CAM Visualization"),
gr.Label(label="Classification Confidence Scores"), # Updated label
],
title="Deepfake Detection with Grad-CAM",
description="Upload a video and detect whether it is real or a deepfake. Grad-CAM will highlight the most influential region.",
theme="default",
)
if __name__ == "__main__":
demo.launch(debug=True)
|