Omnibus commited on
Commit
65ffebf
·
1 Parent(s): f62c5a9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -10
app.py CHANGED
@@ -8,27 +8,41 @@ import urllib.request
8
  import uuid
9
  uid=uuid.uuid4()
10
 
11
- pipe = pipeline("image-classification", "umm-maybe/AI-image-detector")
 
 
 
 
 
 
 
 
12
 
13
- def image_classifier(image):
14
- outputs = pipe(image)
 
 
 
 
 
 
 
 
 
 
 
 
15
  results = {}
16
  for result in outputs:
17
  results[result['label']] = result['score']
18
  return results
19
-
20
 
21
  def softmax(vector):
22
  e = exp(vector)
23
  return e / e.sum()
24
 
25
 
26
- models=[
27
- "Nahrawy/AIorNot",
28
- "umm-maybe/AI-image-detector",
29
- "arnolfokam/ai-generated-image-detector",
30
 
31
- ]
32
  fin_sum=[]
33
  def aiornot0(image):
34
  labels = ["Real", "AI"]
@@ -172,11 +186,25 @@ with gr.Blocks() as app:
172
  with gr.Box():
173
  n_out2=gr.Label(label="Output")
174
  outp2 = gr.HTML("""""")
175
-
 
 
 
 
 
 
 
 
 
 
176
  btn.click(fin_clear,None,fin)
177
  load_btn.click(load_url,in_url,[inp,mes])
178
  btn.click(aiornot0,[inp],[outp0,n_out0]).then(tot_prob,None,fin)
179
  btn.click(aiornot1,[inp],[outp1,n_out1]).then(tot_prob,None,fin)
180
  btn.click(aiornot2,[inp],[outp2,n_out2]).then(tot_prob,None,fin)
181
 
 
 
 
 
182
  app.queue(concurrency_count=20).launch()
 
8
  import uuid
9
  uid=uuid.uuid4()
10
 
11
+ models=[
12
+ "Nahrawy/AIorNot",
13
+ "umm-maybe/AI-image-detector",
14
+ "arnolfokam/ai-generated-image-detector",
15
+ ]
16
+
17
+ pipe0 = pipeline("image-classification", f"{models[0]}")
18
+ pipe1 = pipeline("image-classification", f"{models[1]}")
19
+ pipe2 = pipeline("image-classification", f"{models[2]}")
20
 
21
+ def image_classifier0(image):
22
+ outputs = pipe0(image)
23
+ results = {}
24
+ for result in outputs:
25
+ results[result['label']] = result['score']
26
+ return results
27
+ def image_classifier1(image):
28
+ outputs = pipe1(image)
29
+ results = {}
30
+ for result in outputs:
31
+ results[result['label']] = result['score']
32
+ return results
33
+ def image_classifier2(image):
34
+ outputs = pipe2(image)
35
  results = {}
36
  for result in outputs:
37
  results[result['label']] = result['score']
38
  return results
 
39
 
40
  def softmax(vector):
41
  e = exp(vector)
42
  return e / e.sum()
43
 
44
 
 
 
 
 
45
 
 
46
  fin_sum=[]
47
  def aiornot0(image):
48
  labels = ["Real", "AI"]
 
186
  with gr.Box():
187
  n_out2=gr.Label(label="Output")
188
  outp2 = gr.HTML("""""")
189
+ with gr.Row():
190
+ with gr.Box():
191
+ n_out3=gr.Label(label="Output")
192
+ outp3 = gr.HTML("""""")
193
+ with gr.Box():
194
+ n_out4=gr.Label(label="Output")
195
+ outp4 = gr.HTML("""""")
196
+ with gr.Box():
197
+ n_out5=gr.Label(label="Output")
198
+ outp5 = gr.HTML("""""")
199
+
200
  btn.click(fin_clear,None,fin)
201
  load_btn.click(load_url,in_url,[inp,mes])
202
  btn.click(aiornot0,[inp],[outp0,n_out0]).then(tot_prob,None,fin)
203
  btn.click(aiornot1,[inp],[outp1,n_out1]).then(tot_prob,None,fin)
204
  btn.click(aiornot2,[inp],[outp2,n_out2]).then(tot_prob,None,fin)
205
 
206
+ btn.click(image_classifier0,[inp],[n_out3])
207
+ btn.click(image_classifier1,[inp],[n_out4])
208
+ btn.click(image_classifier2,[inp],[n_out5])
209
+
210
  app.queue(concurrency_count=20).launch()