File size: 1,263 Bytes
91f05e0
096ed03
91f05e0
 
 
096ed03
 
 
 
91f05e0
c20eec4
 
91f05e0
 
 
 
 
 
096ed03
91f05e0
096ed03
 
 
91f05e0
 
 
c20eec4
91f05e0
096ed03
c20eec4
 
91f05e0
 
 
 
 
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
import gradio as gr
from transformers import ViTForImageClassification, ViTImageProcessor
from PIL import Image
import torch

# Load the model and processor
model_name = "prithivMLmods/Deep-Fake-Detector-v2-Model"
model = ViTForImageClassification.from_pretrained(model_name)
processor = ViTImageProcessor.from_pretrained(model_name)

def deepfake_classification(image):
    """Predicts whether an image is a Deepfake or Real."""
    image = Image.fromarray(image).convert("RGB")
    inputs = processor(images=image, return_tensors="pt")
    
    with torch.no_grad():
        outputs = model(**inputs)
        logits = outputs.logits
        predicted_class = torch.argmax(logits, dim=1).item()
    
    # Get label mapping
    label = model.config.id2label[predicted_class] if hasattr(model.config, "id2label") else str(predicted_class)
    return {label: 1.0}  # Gradio Label output expects a dictionary

# Create Gradio interface
iface = gr.Interface(
    fn=deepfake_classification,
    inputs=gr.Image(type="numpy"),
    outputs=gr.Label(label="Prediction"),
    title="Deepfake vs. Real Image Classification",
    description="Upload an image to determine if it's a Deepfake or a Real one."
)

# Launch the app
if __name__ == "__main__":
    iface.launch()