Omnibus commited on
Commit
88cf8f1
·
1 Parent(s): 92cee30

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -26
app.py CHANGED
@@ -23,25 +23,19 @@ def aiornot0(image):
23
  input = feature_extractor0(image, return_tensors="pt")
24
  with torch.no_grad():
25
  outputs = model0(**input)
26
- print (outputs)
27
  logits = outputs.logits
28
- print (logits)
29
  probability = softmax(logits)
30
- print(f'PROBABILITY ::: {probability}')
31
- print(probability[0][0])
32
  px = pd.DataFrame(probability.numpy())
33
- print(px)
34
-
35
  prediction = logits.argmax(-1).item()
36
  label = labels[prediction]
37
-
38
  html_out = f"""
39
- <h3>Model used: <a href src='https://huggingface.co/{mod}'>{mod}</a><br>
40
- This image is likely: {label}<br>
41
- Probabilites<br>
42
- AI: {px[0][0]}<br>
43
- Real: {px[1][0]}"""
44
-
 
45
  return gr.HTML.update(html_out)
46
  def aiornot1(image):
47
  labels = ["Real", "AI"]
@@ -51,12 +45,20 @@ def aiornot1(image):
51
  input = feature_extractor1(image, return_tensors="pt")
52
  with torch.no_grad():
53
  outputs = model1(**input)
54
- print (outputs)
55
- logits = outputs.logits
56
- print (logits)
57
  prediction = logits.argmax(-1).item()
58
- label = labels[prediction]
59
- return label
 
 
 
 
 
 
 
 
60
  def aiornot2(image):
61
  labels = ["Real", "AI"]
62
  mod=models[2]
@@ -65,12 +67,20 @@ def aiornot2(image):
65
  input = feature_extractor2(image, return_tensors="pt")
66
  with torch.no_grad():
67
  outputs = model2(**input)
68
- print (outputs)
69
- logits = outputs.logits
70
- print (logits)
71
  prediction = logits.argmax(-1).item()
72
- label = labels[prediction]
73
- return label
 
 
 
 
 
 
 
 
74
  with gr.Blocks() as app:
75
  with gr.Row():
76
  with gr.Column():
@@ -80,10 +90,12 @@ with gr.Blocks() as app:
80
 
81
  with gr.Column():
82
  #outp0 = gr.Textbox(label=f'{models[0]}')
83
- lab0 = gr.HTML(f"""Testing on Model {models[0]}""")
84
  outp0 = gr.HTML("""""")
85
- outp1 = gr.Textbox(label=f'{models[1]}')
86
- outp2 = gr.Textbox(label=f'{models[2]}')
 
 
87
  btn.click(aiornot0,[inp],outp0)
88
  btn.click(aiornot1,[inp],outp1)
89
  btn.click(aiornot2,[inp],outp2)
 
23
  input = feature_extractor0(image, return_tensors="pt")
24
  with torch.no_grad():
25
  outputs = model0(**input)
 
26
  logits = outputs.logits
 
27
  probability = softmax(logits)
 
 
28
  px = pd.DataFrame(probability.numpy())
 
 
29
  prediction = logits.argmax(-1).item()
30
  label = labels[prediction]
 
31
  html_out = f"""
32
+ <h3>
33
+ <b>This image is likely: {label}</b><br>
34
+ Model used: <a href='https://huggingface.co/{mod}'>{mod}</a><br>
35
+ <br>
36
+ Probabilites:<br>
37
+ Real: {px[0][0]}<br>
38
+ AI: {px[1][0]}"""
39
  return gr.HTML.update(html_out)
40
  def aiornot1(image):
41
  labels = ["Real", "AI"]
 
45
  input = feature_extractor1(image, return_tensors="pt")
46
  with torch.no_grad():
47
  outputs = model1(**input)
48
+ logits = outputs.logits
49
+ probability = softmax(logits)
50
+ px = pd.DataFrame(probability.numpy())
51
  prediction = logits.argmax(-1).item()
52
+ label = labels[prediction]
53
+ html_out = f"""
54
+ <h3>
55
+ <b>This image is likely: {label}</b><br>
56
+ Model used: <a href='https://huggingface.co/{mod}'>{mod}</a><br>
57
+ <br>
58
+ Probabilites:<br>
59
+ Real: {px[0][0]}<br>
60
+ AI: {px[1][0]}"""
61
+ return gr.HTML.update(html_out)
62
  def aiornot2(image):
63
  labels = ["Real", "AI"]
64
  mod=models[2]
 
67
  input = feature_extractor2(image, return_tensors="pt")
68
  with torch.no_grad():
69
  outputs = model2(**input)
70
+ logits = outputs.logits
71
+ probability = softmax(logits)
72
+ px = pd.DataFrame(probability.numpy())
73
  prediction = logits.argmax(-1).item()
74
+ label = labels[prediction]
75
+ html_out = f"""
76
+ <h3>
77
+ <b>This image is likely: {label}</b><br>
78
+ Model used: <a href='https://huggingface.co/{mod}'>{mod}</a><br>
79
+ <br>
80
+ Probabilites:<br>
81
+ Real: {px[0][0]}<br>
82
+ AI: {px[1][0]}"""
83
+ return gr.HTML.update(html_out)
84
  with gr.Blocks() as app:
85
  with gr.Row():
86
  with gr.Column():
 
90
 
91
  with gr.Column():
92
  #outp0 = gr.Textbox(label=f'{models[0]}')
93
+ lab0 = gr.HTML(f"""Testing on Model: {models[0]}""")
94
  outp0 = gr.HTML("""""")
95
+ lab1 = gr.HTML(f"""Testing on Model: {models[1]}""")
96
+ outp1 = gr.HTML("""""")
97
+ lab2 = gr.HTML(f"""Testing on Model: {models[2]}""")
98
+ outp2 = gr.HTML("""""")
99
  btn.click(aiornot0,[inp],outp0)
100
  btn.click(aiornot1,[inp],outp1)
101
  btn.click(aiornot2,[inp],outp2)