File size: 749 Bytes
dec8025
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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)