Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -19,7 +19,8 @@ def softmax(vector):
|
|
19 |
e = exp(vector)
|
20 |
return e / e.sum()
|
21 |
|
22 |
-
def aiornot(image, model_index):
|
|
|
23 |
mod = models[model_index]
|
24 |
feature_extractor = AutoFeatureExtractor.from_pretrained(mod)
|
25 |
model = AutoModelForImageClassification.from_pretrained(mod)
|
@@ -66,6 +67,10 @@ def calculate_final_prob():
|
|
66 |
"AI": f"{1 - fin_out:.4f}"
|
67 |
}
|
68 |
|
|
|
|
|
|
|
|
|
69 |
with gr.Blocks() as app:
|
70 |
gr.Markdown("""<center><h1>AI Image Detector<br><h4>(Test Demo - accuracy varies by model)</h4></center>""")
|
71 |
with gr.Column():
|
@@ -85,9 +90,9 @@ with gr.Blocks() as app:
|
|
85 |
output_html = gr.HTML()
|
86 |
output_label = gr.Label(label="Output")
|
87 |
btn.click(aiornot, inputs=[inp, gr.Number(value=i, visible=False)], outputs=[output_html, output_label])
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
load_btn.click(load_url, in_url, [inp, mes])
|
92 |
|
93 |
app.launch(show_api=False, max_threads=24)
|
|
|
19 |
e = exp(vector)
|
20 |
return e / e.sum()
|
21 |
|
22 |
+
def aiornot(image, model_index):
|
23 |
+
model_index = int(model_index) # Convert to integer
|
24 |
mod = models[model_index]
|
25 |
feature_extractor = AutoFeatureExtractor.from_pretrained(mod)
|
26 |
model = AutoModelForImageClassification.from_pretrained(mod)
|
|
|
67 |
"AI": f"{1 - fin_out:.4f}"
|
68 |
}
|
69 |
|
70 |
+
def clear_results():
|
71 |
+
results_store.clear()
|
72 |
+
return gr.HTML.update(value=""), gr.Label.update(value=None)
|
73 |
+
|
74 |
with gr.Blocks() as app:
|
75 |
gr.Markdown("""<center><h1>AI Image Detector<br><h4>(Test Demo - accuracy varies by model)</h4></center>""")
|
76 |
with gr.Column():
|
|
|
90 |
output_html = gr.HTML()
|
91 |
output_label = gr.Label(label="Output")
|
92 |
btn.click(aiornot, inputs=[inp, gr.Number(value=i, visible=False)], outputs=[output_html, output_label])
|
93 |
+
|
94 |
+
btn.click(clear_results, outputs=[output_html, output_label], queue=False)
|
95 |
+
btn.click(calculate_final_prob, outputs=fin)
|
96 |
load_btn.click(load_url, in_url, [inp, mes])
|
97 |
|
98 |
app.launch(show_api=False, max_threads=24)
|