rufaidahaiman42 commited on
Commit
00b82e0
·
verified ·
1 Parent(s): 7dacb81

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -15
app.py CHANGED
@@ -1,33 +1,30 @@
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 = "BuzzFeedNews/Deepfake-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()
 
 
1
+ from transformers import AutoImageProcessor, SiglipForImageClassification
 
2
  from PIL import Image
3
+ import gradio as gr
4
  import torch
5
 
6
+ # New model details
7
+ model_name = "prithivMLmods/deepfake-detector-model-v1"
 
8
  processor = AutoImageProcessor.from_pretrained(model_name)
9
+ model = SiglipForImageClassification.from_pretrained(model_name)
10
 
11
  def detect_deepfake(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
+ id2label = { "0": "Fake", "1": "Real" }
18
+ return { id2label[str(i)]: float(probs[i]) for i in range(2) }
19
 
 
 
 
 
 
 
20
  demo = gr.Interface(
21
  fn=detect_deepfake,
22
+ inputs=gr.Image(type="numpy"),
23
  outputs=gr.Label(num_top_classes=2),
24
  title="Deepfake Detector",
25
+ description="Upload an image; this model predicts Real vs Fake."
26
  )
27
 
28
  if __name__ == "__main__":
29
  demo.launch()
30
+