rufaidahaiman42 commited on
Commit
17f4543
·
verified ·
1 Parent(s): 009200a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -27
app.py CHANGED
@@ -1,31 +1,30 @@
1
- from transformers import AutoImageProcessor, AutoModelForImageClassification
 
2
  from PIL import Image
3
  import torch
4
 
5
- # Use a valid Hugging Face model repo
6
- MODEL_NAME = "selimsef/dfdc_deepfake_challenge"
7
-
8
- # Load processor & model
9
- processor = AutoImageProcessor.from_pretrained(MODEL_NAME)
10
- model = AutoModelForImageClassification.from_pretrained(MODEL_NAME)
11
-
12
- # Load your image
13
- image_path = "your_image.jpg" # replace with your raw image path
14
- image = Image.open(image_path).convert("RGB")
15
-
16
- # Preprocess
17
- inputs = processor(images=image, return_tensors="pt")
18
-
19
- # Inference
20
- with torch.no_grad():
21
- outputs = model(**inputs)
22
- logits = outputs.logits
23
- probs = torch.nn.functional.softmax(logits, dim=-1)[0]
24
-
25
- # Get labels
26
- labels = model.config.id2label
27
- real_prob = probs[labels["0"]] if "0" in labels else probs[0]
28
- fake_prob = probs[labels["1"]] if "1" in labels else probs[1]
29
-
30
- print(f"Prediction: Real={real_prob:.4f}, Fake={fake_prob:.4f}")
31
 
 
1
+ import gradio as gr
2
+ from transformers import ViTForImageClassification, ViTImageProcessor
3
  from PIL import Image
4
  import torch
5
 
6
+ MODEL_NAME = "prithivMLmods/Deep-Fake-Detector-v2-Model"
7
+
8
+ processor = ViTImageProcessor.from_pretrained(MODEL_NAME)
9
+ model = ViTForImageClassification.from_pretrained(MODEL_NAME)
10
+
11
+ def classify_image(image):
12
+ image = Image.fromarray(image).convert("RGB")
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
+ labels = model.config.id2label
18
+ return { labels[i]: float(probs[i]) for i in range(len(probs)) }
19
+
20
+ demo = gr.Interface(
21
+ fn=classify_image,
22
+ inputs=gr.Image(type="numpy"),
23
+ outputs=gr.Label(num_top_classes=2, label="Prediction (Real vs Deepfake)"),
24
+ title="Deepfake Detector (ViT)",
25
+ description="Upload an image — model classifies it as Real or Deepfake."
26
+ )
27
+
28
+ if __name__ == "__main__":
29
+ demo.launch()
 
 
30