Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,13 @@
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
from transformers import AutoFeatureExtractor, AutoModelForImageClassification, pipeline
|
|
|
|
|
|
|
|
|
|
|
4 |
|
|
|
5 |
models=[
|
6 |
"Nahrawy/AIorNot",
|
7 |
"arnolfokam/ai-generated-image-detector",
|
@@ -15,10 +21,13 @@ def aiornot0(image):
|
|
15 |
model = AutoModelForImageClassification.from_pretrained(mod)
|
16 |
input = feature_extractor(image, return_tensors="pt")
|
17 |
with torch.no_grad():
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
22 |
prediction = logits.argmax(-1).item()
|
23 |
label = labels[prediction]
|
24 |
return label
|
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
from transformers import AutoFeatureExtractor, AutoModelForImageClassification, pipeline
|
4 |
+
from numpy import exp
|
5 |
+
|
6 |
+
def softmax(vector):
|
7 |
+
e = exp(vector)
|
8 |
+
return e / e.sum()
|
9 |
|
10 |
+
|
11 |
models=[
|
12 |
"Nahrawy/AIorNot",
|
13 |
"arnolfokam/ai-generated-image-detector",
|
|
|
21 |
model = AutoModelForImageClassification.from_pretrained(mod)
|
22 |
input = feature_extractor(image, return_tensors="pt")
|
23 |
with torch.no_grad():
|
24 |
+
outputs = model(**input)
|
25 |
+
print (outputs)
|
26 |
+
logits = outputs.logits
|
27 |
+
print (logits)
|
28 |
+
probability = softmax(logits, axis=-1)
|
29 |
+
print(probability)
|
30 |
+
|
31 |
prediction = logits.argmax(-1).item()
|
32 |
label = labels[prediction]
|
33 |
return label
|