SadraCoding commited on
Commit
67359b6
·
verified ·
1 Parent(s): 87d9f5a

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +29 -0
README.md CHANGED
@@ -40,7 +40,36 @@ To load and use the model in your Python environment, use the standard `transfor
40
 
41
  ```bash
42
  pip install transformers torch pillow
 
43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  ---
45
  license: mit
46
  ---
 
40
 
41
  ```bash
42
  pip install transformers torch pillow
43
+ ```
44
 
45
+ ```python
46
+ from transformers import AutoModelForImageClassification, AutoFeatureExtractor
47
+ from PIL import Image
48
+ import torch
49
+
50
+ image_path = 'path/to/your/image.jpg'
51
+ model_id = "SADRACODING/SDXL-Deepfake-Detector"
52
+
53
+ # Load Model and Feature Extractor
54
+ model = AutoModelForImageClassification.from_pretrained(model_id)
55
+ feature_extractor = AutoFeatureExtractor.from_pretrained(model_id)
56
+
57
+ # Preprocessing
58
+ image = Image.open(image_path).convert("RGB")
59
+ inputs = feature_extractor(images=image, return_tensors="pt")
60
+
61
+ # Inference
62
+ with torch.no_grad():
63
+ logits = model(**inputs).logits
64
+
65
+ # Post-processing and Prediction
66
+ predicted_class_id = logits.argmax().item()
67
+ labels = ["REAL", "FAKE"]
68
+ prediction = labels[predicted_class_id]
69
+ confidence = torch.nn.functional.softmax(logits, dim=-1)[0][predicted_class_id].item()
70
+
71
+ print(f"Prediction: {prediction} (Confidence: {confidence:.4f})")
72
+ ```
73
  ---
74
  license: mit
75
  ---