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()