Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -11,33 +11,10 @@ def softmax(vector):
|
|
11 |
|
12 |
models=[
|
13 |
"Nahrawy/AIorNot",
|
14 |
-
"arnolfokam/ai-generated-image-detector",
|
15 |
"umm-maybe/AI-image-detector",
|
16 |
-
|
17 |
-
'''
|
18 |
-
pipe0 = pipeline("image-classification", f"{models[0]}")
|
19 |
-
pipe1 = pipeline("image-classification", f"{models[1]}")
|
20 |
-
pipe2 = pipeline("image-classification", f"{models[2]}")
|
21 |
|
22 |
-
|
23 |
-
outputs = pipe0(image)
|
24 |
-
results = {}
|
25 |
-
for result in outputs:
|
26 |
-
results[result['label']] = result['score']
|
27 |
-
return results
|
28 |
-
def image_classifier1(image):
|
29 |
-
outputs = pipe1(image)
|
30 |
-
results = {}
|
31 |
-
for result in outputs:
|
32 |
-
results[result['label']] = result['score']
|
33 |
-
return results
|
34 |
-
def image_classifier2(image):
|
35 |
-
outputs = pipe2(image)
|
36 |
-
results = {}
|
37 |
-
for result in outputs:
|
38 |
-
results[result['label']] = result['score']
|
39 |
-
return results
|
40 |
-
'''
|
41 |
|
42 |
def aiornot0(image):
|
43 |
labels = ["Real", "AI"]
|
@@ -54,8 +31,7 @@ def aiornot0(image):
|
|
54 |
label = labels[prediction]
|
55 |
html_out = f"""
|
56 |
<h1>This image is likely: {label}</h1><br><h3>
|
57 |
-
|
58 |
-
<br>
|
59 |
Probabilites:<br>
|
60 |
Real: {px[0][0]}<br>
|
61 |
AI: {px[1][0]}"""
|
@@ -79,8 +55,7 @@ def aiornot1(image):
|
|
79 |
label = labels[prediction]
|
80 |
html_out = f"""
|
81 |
<h1>This image is likely: {label}</h1><br><h3>
|
82 |
-
|
83 |
-
<br>
|
84 |
Probabilites:<br>
|
85 |
Real: {px[0][0]}<br>
|
86 |
AI: {px[1][0]}"""
|
@@ -104,8 +79,7 @@ def aiornot2(image):
|
|
104 |
label = labels[prediction]
|
105 |
html_out = f"""
|
106 |
<h1>This image is likely: {label}</h1><br><h3>
|
107 |
-
|
108 |
-
<br>
|
109 |
Probabilites:<br>
|
110 |
Real: {px[1][0]}<br>
|
111 |
AI: {px[0][0]}"""
|
@@ -115,29 +89,38 @@ def aiornot2(image):
|
|
115 |
results[labels[idx]] = px[idx][0]
|
116 |
#results[labels['label']] = result['score']
|
117 |
return gr.HTML.update(html_out),results
|
118 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
with gr.Blocks() as app:
|
120 |
-
with gr.
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
inp = gr.Pil()
|
122 |
-
btn = gr.Button()
|
123 |
with gr.Group():
|
124 |
with gr.Row():
|
125 |
with gr.Box():
|
126 |
-
lab0 = gr.HTML(f"""<b>Testing on Model: {models[0]}</b>""")
|
127 |
outp0 = gr.HTML("""""")
|
128 |
n_out0=gr.Label(label="Output")
|
129 |
with gr.Box():
|
130 |
-
lab1 = gr.HTML(f"""<b>Testing on Model: {models[1]}</b>""")
|
131 |
outp1 = gr.HTML("""""")
|
132 |
n_out1=gr.Label(label="Output")
|
133 |
with gr.Box():
|
134 |
-
lab2 = gr.HTML(f"""<b>Testing on Model: {models[2]}</b>""")
|
135 |
outp2 = gr.HTML("""""")
|
136 |
n_out2=gr.Label(label="Output")
|
|
|
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 |
-
#btn.click(image_classifier1,[inp],n_out1)
|
142 |
-
#btn.click(image_classifier2,[inp],n_out2)
|
143 |
-
app.launch()
|
|
|
11 |
|
12 |
models=[
|
13 |
"Nahrawy/AIorNot",
|
|
|
14 |
"umm-maybe/AI-image-detector",
|
15 |
+
"arnolfokam/ai-generated-image-detector",
|
|
|
|
|
|
|
|
|
16 |
|
17 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
def aiornot0(image):
|
20 |
labels = ["Real", "AI"]
|
|
|
31 |
label = labels[prediction]
|
32 |
html_out = f"""
|
33 |
<h1>This image is likely: {label}</h1><br><h3>
|
34 |
+
|
|
|
35 |
Probabilites:<br>
|
36 |
Real: {px[0][0]}<br>
|
37 |
AI: {px[1][0]}"""
|
|
|
55 |
label = labels[prediction]
|
56 |
html_out = f"""
|
57 |
<h1>This image is likely: {label}</h1><br><h3>
|
58 |
+
|
|
|
59 |
Probabilites:<br>
|
60 |
Real: {px[0][0]}<br>
|
61 |
AI: {px[1][0]}"""
|
|
|
79 |
label = labels[prediction]
|
80 |
html_out = f"""
|
81 |
<h1>This image is likely: {label}</h1><br><h3>
|
82 |
+
|
|
|
83 |
Probabilites:<br>
|
84 |
Real: {px[1][0]}<br>
|
85 |
AI: {px[0][0]}"""
|
|
|
89 |
results[labels[idx]] = px[idx][0]
|
90 |
#results[labels['label']] = result['score']
|
91 |
return gr.HTML.update(html_out),results
|
92 |
+
def load_url(url):
|
93 |
+
try:
|
94 |
+
image = Image.open(url)
|
95 |
+
mes = "Image Loaded"
|
96 |
+
except Exception:
|
97 |
+
mes="Image not Found"
|
98 |
+
return image,mes
|
99 |
with gr.Blocks() as app:
|
100 |
+
with gr.Row():
|
101 |
+
with gr.Column():
|
102 |
+
in_url=gr.Textbox(label="Image URL")
|
103 |
+
with gr.Row():
|
104 |
+
load_btn=gr.Button("Load URL")
|
105 |
+
btn = gr.Button("Detect AI")
|
106 |
+
mes = gr.HTML("""""")
|
107 |
inp = gr.Pil()
|
|
|
108 |
with gr.Group():
|
109 |
with gr.Row():
|
110 |
with gr.Box():
|
111 |
+
lab0 = gr.HTML(f"""<b>Testing on Model: <a href='https://huggingface.co/{models[0]}'>{models[0]}</a></b>""")
|
112 |
outp0 = gr.HTML("""""")
|
113 |
n_out0=gr.Label(label="Output")
|
114 |
with gr.Box():
|
115 |
+
lab1 = gr.HTML(f"""<b>Testing on Model: <a href='https://huggingface.co/{models[1]}'>{models[1]}</a></b>""")
|
116 |
outp1 = gr.HTML("""""")
|
117 |
n_out1=gr.Label(label="Output")
|
118 |
with gr.Box():
|
119 |
+
lab2 = gr.HTML(f"""<b>Testing on Model: <a href='https://huggingface.co/{models[2]}'>{models[2]}</a></b>""")
|
120 |
outp2 = gr.HTML("""""")
|
121 |
n_out2=gr.Label(label="Output")
|
122 |
+
load_btn.click(load_url,in_url,[inp,mes])
|
123 |
btn.click(aiornot0,[inp],[outp0,n_out0])
|
124 |
btn.click(aiornot1,[inp],[outp1,n_out1])
|
125 |
btn.click(aiornot2,[inp],[outp2,n_out2])
|
126 |
+
app.launch(enable_queue=False)
|
|
|
|
|
|