reagvis commited on
Commit
0ced88f
·
verified ·
1 Parent(s): 33d365f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from PIL import Image
4
+ from transformers import AutoImageProcessor, AutoModelForImageClassification
5
+
6
+ # Load the Hugging Face model and processor for deepfake detection.
7
+ processor = AutoImageProcessor.from_pretrained("Smogy/SMOGY-Ai-images-detector")
8
+ model = AutoModelForImageClassification.from_pretrained("Smogy/SMOGY-Ai-images-detector")
9
+
10
+ def detect_deepfake(image: Image.Image) -> str:
11
+ inputs = processor(images=image, return_tensors="pt")
12
+ with torch.no_grad():
13
+ outputs = model(**inputs)
14
+ probs = torch.softmax(outputs.logits, dim=1)
15
+ idx = probs.argmax(dim=1).item()
16
+ label = model.config.id2label[idx]
17
+ conf = probs[0, idx].item()
18
+ return f"The image is {label} with confidence {conf:.2f}"
19
+
20
+ # Build Gradio interface
21
+ with gr.Blocks() as demo:
22
+ gr.Markdown("# Deepfake Detection App")
23
+ gr.Markdown("### Upload an image to detect deepfake content.")
24
+ img_in = gr.Image(type="pil", label="Upload Image")
25
+ txt_out = gr.Textbox(label="Result")
26
+ gr.Button("Detect").click(fn=detect_deepfake, inputs=img_in, outputs=txt_out)
27
+
28
+ if __name__ == "__main__":
29
+ demo.launch()