mrpopsalot commited on
Commit
50237fb
·
verified ·
1 Parent(s): 2d44d99

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoImageProcessor
3
+ from transformers import SiglipForImageClassification
4
+ from transformers.image_utils import load_image
5
+ from PIL import Image
6
+ import torch
7
+
8
+ # Load model and processor
9
+ model_name = "prithivMLmods/AI-vs-Deepfake-vs-Real-Siglip2"
10
+ model = SiglipForImageClassification.from_pretrained(model_name)
11
+ processor = AutoImageProcessor.from_pretrained(model_name)
12
+
13
+ def image_classification(image):
14
+ """Classifies an image as AI-generated, deepfake, or real."""
15
+ image = Image.fromarray(image).convert("RGB")
16
+ inputs = processor(images=image, return_tensors="pt")
17
+
18
+ with torch.no_grad():
19
+ outputs = model(**inputs)
20
+ logits = outputs.logits
21
+ probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
22
+
23
+ labels = model.config.id2label
24
+ predictions = {labels[i]: round(probs[i], 3) for i in range(len(probs))}
25
+
26
+ return predictions
27
+
28
+ # Create Gradio interface
29
+ iface = gr.Interface(
30
+ fn=image_classification,
31
+ inputs=gr.Image(type="numpy"),
32
+ outputs=gr.Label(label="Classification Result"),
33
+ title="AI vs Deepfake vs Real Image Classification",
34
+ description="Upload an image to determine whether it is AI-generated, a deepfake, or a real image."
35
+ )
36
+
37
+ # Launch the app
38
+ if __name__ == "__main__":
39
+ iface.launch()