rufaidahaiman42 commited on
Commit
e952c3e
·
verified ·
1 Parent(s): 0c6d3e3

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForImageClassification, AutoImageProcessor
3
+ from PIL import Image
4
+ import torch
5
+
6
+ # Load model and processor
7
+ model_name = "dima806/deepfake_vs_real_image_detection"
8
+ model = AutoModelForImageClassification.from_pretrained(model_name)
9
+ processor = AutoImageProcessor.from_pretrained(model_name)
10
+
11
+ def detect_deepfake(image):
12
+ # Preprocess image
13
+ inputs = processor(images=image, return_tensors="pt")
14
+ with torch.no_grad():
15
+ outputs = model(**inputs)
16
+ probs = torch.nn.functional.softmax(outputs.logits, dim=-1)[0]
17
+
18
+ # Convert to dict
19
+ labels = model.config.id2label
20
+ results = {labels[i]: float(probs[i]) for i in range(len(labels))}
21
+ return results
22
+
23
+ # Gradio UI
24
+ demo = gr.Interface(
25
+ fn=detect_deepfake,
26
+ inputs=gr.Image(type="pil"),
27
+ outputs=gr.Label(num_top_classes=2),
28
+ title="Deepfake Detector",
29
+ description="Upload an image to check if it's Real or Fake using an AI model."
30
+ )
31
+
32
+ if __name__ == "__main__":
33
+ demo.launch()