Spaces:
Runtime error
Runtime error
Commit
·
77d1721
1
Parent(s):
dc23258
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,19 @@
|
|
|
|
|
|
|
|
1 |
|
2 |
-
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
for result in results:
|
7 |
-
print(result['sequence'])
|
|
|
1 |
+
from transformers import AutoImageProcessor, AutoModelForImageClassification
|
2 |
+
import torch
|
3 |
+
from datasets import load_dataset
|
4 |
|
5 |
+
dataset = load_dataset("competitions/aiornot")
|
6 |
+
image = dataset["test"][0]["image"]
|
7 |
+
|
8 |
+
processor = AutoImageProcessor.from_pretrained("microsoft/resnet-50")
|
9 |
+
model = AutoModelForImageClassification.from_pretrained("arnolfokam/ai-generated-image-detector", trust_remote_code=True)
|
10 |
+
|
11 |
+
inputs = processor(image, return_tensors="pt")
|
12 |
+
|
13 |
+
with torch.no_grad():
|
14 |
+
logits = model(**inputs).logits
|
15 |
+
|
16 |
+
# model predicts one of the 2 classes
|
17 |
+
predicted_label = logits.argmax(-1).item()
|
18 |
+
print(model.config.id2label[predicted_label])
|
19 |
|
|
|
|