Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,30 +1,26 @@
|
|
|
|
1 |
from transformers import ViTForImageClassification, ViTImageProcessor
|
2 |
-
import torch
|
3 |
from PIL import Image
|
4 |
-
import gradio as gr
|
5 |
-
import os
|
6 |
|
7 |
-
# Load model
|
8 |
model_name = "google/vit-base-patch16-224"
|
9 |
processor = ViTImageProcessor.from_pretrained(model_name)
|
10 |
model = ViTForImageClassification.from_pretrained(model_name)
|
11 |
|
12 |
def detect_deepfake(image):
|
13 |
-
if image
|
14 |
-
image = image.convert('RGB')
|
15 |
inputs = processor(images=image, return_tensors="pt")
|
16 |
-
|
17 |
-
|
18 |
-
return "Real" if outputs.logits.argmax() == 0 else "Fake"
|
19 |
|
20 |
-
# Create
|
21 |
-
|
22 |
fn=detect_deepfake,
|
23 |
-
inputs=gr.Image(type="pil"),
|
24 |
-
outputs="
|
25 |
-
title="Deepfake
|
26 |
-
description="Upload
|
27 |
)
|
28 |
|
29 |
-
|
30 |
-
|
|
|
1 |
+
import gradio as gr
|
2 |
from transformers import ViTForImageClassification, ViTImageProcessor
|
|
|
3 |
from PIL import Image
|
|
|
|
|
4 |
|
5 |
+
# Load a simple AI model
|
6 |
model_name = "google/vit-base-patch16-224"
|
7 |
processor = ViTImageProcessor.from_pretrained(model_name)
|
8 |
model = ViTForImageClassification.from_pretrained(model_name)
|
9 |
|
10 |
def detect_deepfake(image):
|
11 |
+
# Check if image is fake
|
|
|
12 |
inputs = processor(images=image, return_tensors="pt")
|
13 |
+
outputs = model(**inputs)
|
14 |
+
return "REAL" if outputs.logits.argmax() == 0 else "FAKE (Deepfake!)"
|
|
|
15 |
|
16 |
+
# Create a simple web interface
|
17 |
+
app = gr.Interface(
|
18 |
fn=detect_deepfake,
|
19 |
+
inputs=gr.Image(type="pil", label="Upload Image"),
|
20 |
+
outputs=gr.Label(label="Result"),
|
21 |
+
title="🔍 Deepfake Detector",
|
22 |
+
description="Upload a face photo to check if it's real or AI-generated!"
|
23 |
)
|
24 |
|
25 |
+
# Launch the app with a public URL
|
26 |
+
app.launch(share=True) # << This gives you a temporary public link!
|