Omnibus commited on
Commit
436d80d
1 Parent(s): 387ecb3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -4
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
- outputs = model(**input)
19
- print (outputs)
20
- logits = outputs.logits
21
- print (logits)
 
 
 
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