from transformers import pipeline from PIL import Image import requests from io import BytesIO class DeepfakeDetector: def __init__(self, model_name="dima806/deepfake_vs_real_image_detection"): self.classifier = pipeline("image-classification", model=model_name) def detect_from_file(self, file_path): image = Image.open(file_path) return self.classifier(image) def detect_from_url(self, image_url): response = requests.get(image_url) image = Image.open(BytesIO(response.content)) return self.classifier(image) # Example usage if __name__ == "__main__": detector = DeepfakeDetector() result = detector.detect_from_url("https://example.com/sample.jpg") print(result)