Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -21,7 +21,7 @@ models=[
|
|
| 21 |
"arnolfokam/ai-generated-image-detector",
|
| 22 |
|
| 23 |
]
|
| 24 |
-
|
| 25 |
def aiornot0(image):
|
| 26 |
labels = ["Real", "AI"]
|
| 27 |
mod=models[0]
|
|
@@ -45,6 +45,7 @@ def aiornot0(image):
|
|
| 45 |
for idx,result in enumerate(px):
|
| 46 |
results[labels[idx]] = px[idx][0]
|
| 47 |
#results[labels['label']] = result['score']
|
|
|
|
| 48 |
return gr.HTML.update(html_out),results
|
| 49 |
def aiornot1(image):
|
| 50 |
labels = ["Real", "AI"]
|
|
@@ -69,6 +70,7 @@ def aiornot1(image):
|
|
| 69 |
for idx,result in enumerate(px):
|
| 70 |
results[labels[idx]] = px[idx][0]
|
| 71 |
#results[labels['label']] = result['score']
|
|
|
|
| 72 |
return gr.HTML.update(html_out),results
|
| 73 |
def aiornot2(image):
|
| 74 |
labels = ["AI", "Real"]
|
|
@@ -94,6 +96,8 @@ def aiornot2(image):
|
|
| 94 |
for idx,result in enumerate(px):
|
| 95 |
results[labels[idx]] = px[idx][0]
|
| 96 |
#results[labels['label']] = result['score']
|
|
|
|
|
|
|
| 97 |
return gr.HTML.update(html_out),results
|
| 98 |
|
| 99 |
def load_url(url):
|
|
@@ -107,6 +111,24 @@ def load_url(url):
|
|
| 107 |
image=None
|
| 108 |
mes=f"Image not Found<br>Error: {e}"
|
| 109 |
return image,mes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
with gr.Blocks() as app:
|
| 111 |
with gr.Column():
|
| 112 |
in_url=gr.Textbox(label="Image URL")
|
|
@@ -119,7 +141,9 @@ with gr.Blocks() as app:
|
|
| 119 |
with gr.Row():
|
| 120 |
with gr.Box():
|
| 121 |
lab0 = gr.HTML(f"""<b>Testing on Model: <a href='https://huggingface.co/{models[0]}'>{models[0]}</a></b>""")
|
|
|
|
| 122 |
lab1 = gr.HTML(f"""<b>Testing on Model: <a href='https://huggingface.co/{models[1]}'>{models[1]}</a></b>""")
|
|
|
|
| 123 |
lab2 = gr.HTML(f"""<b>Testing on Model: <a href='https://huggingface.co/{models[2]}'>{models[2]}</a></b>""")
|
| 124 |
|
| 125 |
with gr.Row():
|
|
@@ -133,9 +157,11 @@ with gr.Blocks() as app:
|
|
| 133 |
n_out2=gr.Label(label="Output")
|
| 134 |
outp2 = gr.HTML("""""")
|
| 135 |
|
|
|
|
|
|
|
| 136 |
load_btn.click(load_url,in_url,[inp,mes])
|
| 137 |
-
btn.click(aiornot0,[inp],[outp0,n_out0])
|
| 138 |
-
btn.click(aiornot1,[inp],[outp1,n_out1])
|
| 139 |
-
btn.click(aiornot2,[inp],[outp2,n_out2])
|
| 140 |
|
| 141 |
app.queue(concurrency_count=20).launch()
|
|
|
|
| 21 |
"arnolfokam/ai-generated-image-detector",
|
| 22 |
|
| 23 |
]
|
| 24 |
+
fin_sum=[]
|
| 25 |
def aiornot0(image):
|
| 26 |
labels = ["Real", "AI"]
|
| 27 |
mod=models[0]
|
|
|
|
| 45 |
for idx,result in enumerate(px):
|
| 46 |
results[labels[idx]] = px[idx][0]
|
| 47 |
#results[labels['label']] = result['score']
|
| 48 |
+
fin_sum.append(results)
|
| 49 |
return gr.HTML.update(html_out),results
|
| 50 |
def aiornot1(image):
|
| 51 |
labels = ["Real", "AI"]
|
|
|
|
| 70 |
for idx,result in enumerate(px):
|
| 71 |
results[labels[idx]] = px[idx][0]
|
| 72 |
#results[labels['label']] = result['score']
|
| 73 |
+
fin_sum.append(results)
|
| 74 |
return gr.HTML.update(html_out),results
|
| 75 |
def aiornot2(image):
|
| 76 |
labels = ["AI", "Real"]
|
|
|
|
| 96 |
for idx,result in enumerate(px):
|
| 97 |
results[labels[idx]] = px[idx][0]
|
| 98 |
#results[labels['label']] = result['score']
|
| 99 |
+
fin_sum.append(results)
|
| 100 |
+
|
| 101 |
return gr.HTML.update(html_out),results
|
| 102 |
|
| 103 |
def load_url(url):
|
|
|
|
| 111 |
image=None
|
| 112 |
mes=f"Image not Found<br>Error: {e}"
|
| 113 |
return image,mes
|
| 114 |
+
|
| 115 |
+
def tot_prob():
|
| 116 |
+
try:
|
| 117 |
+
fin_out = fin_sum[0]["Real"]+fin_sum[1]["Real"]+fin_sum[2]["Real"]
|
| 118 |
+
fin_out = fin_out/3
|
| 119 |
+
fin_sub = 1-fin_out
|
| 120 |
+
out={
|
| 121 |
+
"Real":f"{fin_out}",
|
| 122 |
+
"AI":f"{fin_sub}"
|
| 123 |
+
}
|
| 124 |
+
fin_sum.clear()
|
| 125 |
+
print (fin_out)
|
| 126 |
+
return out
|
| 127 |
+
except Exception as e:
|
| 128 |
+
pass
|
| 129 |
+
print (e)
|
| 130 |
+
|
| 131 |
+
|
| 132 |
with gr.Blocks() as app:
|
| 133 |
with gr.Column():
|
| 134 |
in_url=gr.Textbox(label="Image URL")
|
|
|
|
| 141 |
with gr.Row():
|
| 142 |
with gr.Box():
|
| 143 |
lab0 = gr.HTML(f"""<b>Testing on Model: <a href='https://huggingface.co/{models[0]}'>{models[0]}</a></b>""")
|
| 144 |
+
with gr.Box():
|
| 145 |
lab1 = gr.HTML(f"""<b>Testing on Model: <a href='https://huggingface.co/{models[1]}'>{models[1]}</a></b>""")
|
| 146 |
+
with gr.Box():
|
| 147 |
lab2 = gr.HTML(f"""<b>Testing on Model: <a href='https://huggingface.co/{models[2]}'>{models[2]}</a></b>""")
|
| 148 |
|
| 149 |
with gr.Row():
|
|
|
|
| 157 |
n_out2=gr.Label(label="Output")
|
| 158 |
outp2 = gr.HTML("""""")
|
| 159 |
|
| 160 |
+
with gr.Row():
|
| 161 |
+
fin=gr.Label(label="Final Probability")
|
| 162 |
load_btn.click(load_url,in_url,[inp,mes])
|
| 163 |
+
btn.click(aiornot0,[inp],[outp0,n_out0]).then(tot_prob,None,fin)
|
| 164 |
+
btn.click(aiornot1,[inp],[outp1,n_out1]).then(tot_prob,None,fin)
|
| 165 |
+
btn.click(aiornot2,[inp],[outp2,n_out2]).then(tot_prob,None,fin)
|
| 166 |
|
| 167 |
app.queue(concurrency_count=20).launch()
|