Shiwanni commited on
Commit
4a0902b
·
verified ·
1 Parent(s): 42acc6c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -17
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.mode != 'RGB':
14
- image = image.convert('RGB')
15
  inputs = processor(images=image, return_tensors="pt")
16
- with torch.no_grad():
17
- outputs = model(**inputs)
18
- return "Real" if outputs.logits.argmax() == 0 else "Fake"
19
 
20
- # Create interface WITHOUT examples
21
- iface = gr.Interface(
22
  fn=detect_deepfake,
23
- inputs=gr.Image(type="pil"),
24
- outputs="text",
25
- title="Deepfake Detection",
26
- description="Upload an image to check if it's real or AI-generated"
27
  )
28
 
29
- if __name__ == "__main__":
30
- iface.launch(server_name="0.0.0.0", server_port=7860)
 
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!