Spaces:
Runtime error
Runtime error
Create detect.py
Browse files
detect.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
from PIL import Image
|
3 |
+
import requests
|
4 |
+
from io import BytesIO
|
5 |
+
|
6 |
+
class DeepfakeDetector:
|
7 |
+
def __init__(self, model_name="dima806/deepfake_vs_real_image_detection"):
|
8 |
+
self.classifier = pipeline("image-classification", model=model_name)
|
9 |
+
|
10 |
+
def detect_from_file(self, file_path):
|
11 |
+
image = Image.open(file_path)
|
12 |
+
return self.classifier(image)
|
13 |
+
|
14 |
+
def detect_from_url(self, image_url):
|
15 |
+
response = requests.get(image_url)
|
16 |
+
image = Image.open(BytesIO(response.content))
|
17 |
+
return self.classifier(image)
|
18 |
+
|
19 |
+
# Example usage
|
20 |
+
if __name__ == "__main__":
|
21 |
+
detector = DeepfakeDetector()
|
22 |
+
result = detector.detect_from_url("https://example.com/sample.jpg")
|
23 |
+
print(result)
|