LPX
commited on
Commit
·
82e63cc
1
Parent(s):
e2101d4
good morning: small ui change
Browse files- .gitignore +1 -0
- app_mcp.py +13 -3
- requirements.txt +2 -2
.gitignore
CHANGED
@@ -5,3 +5,4 @@
|
|
5 |
./models/*
|
6 |
forensics/__pycache__/*
|
7 |
*.cpython-311.pyc
|
|
|
|
5 |
./models/*
|
6 |
forensics/__pycache__/*
|
7 |
*.cpython-311.pyc
|
8 |
+
test.ipynb
|
app_mcp.py
CHANGED
@@ -237,7 +237,15 @@ def predict_image(img, confidence_threshold):
|
|
237 |
results = [infer(img, model_id, confidence_threshold) for model_id in model_ids]
|
238 |
return img, results
|
239 |
|
240 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
241 |
|
242 |
def predict_image_with_json(img, confidence_threshold, augment_methods, rotate_degrees, noise_level, sharpen_strength):
|
243 |
if augment_methods:
|
@@ -268,7 +276,8 @@ def predict_image_with_json(img, confidence_threshold, augment_methods, rotate_d
|
|
268 |
r.get("Real Score", ""),
|
269 |
r.get("Label", "")
|
270 |
] for r in results]
|
271 |
-
|
|
|
272 |
|
273 |
with gr.Blocks(css="#post-gallery { overflow: hidden !important;} .grid-wrap{ overflow-y: hidden !important;} .ms-gr-ant-welcome-icon{ height:unset !important;} .tabs{margin-top:10px;}") as demo:
|
274 |
with ms.Application() as app:
|
@@ -306,8 +315,9 @@ with gr.Blocks(css="#post-gallery { overflow: hidden !important;} .grid-wrap{ ov
|
|
306 |
forensics_gallery = gr.Gallery(label="Post Processed Images", visible=True, columns=[4], rows=[2], container=False, height="auto", object_fit="contain", elem_id="post-gallery")
|
307 |
with gr.Accordion("Debug Output (Raw JSON)", open=False):
|
308 |
debug_json = gr.JSON(label="Raw Model Results")
|
|
|
309 |
|
310 |
-
outputs = [image_output, forensics_gallery, results_table, debug_json]
|
311 |
|
312 |
# Show/hide rotate slider based on selected augmentation method
|
313 |
augment_checkboxgroup.change(lambda methods: gr.update(visible="rotate" in methods), inputs=[augment_checkboxgroup], outputs=[rotate_slider])
|
|
|
237 |
results = [infer(img, model_id, confidence_threshold) for model_id in model_ids]
|
238 |
return img, results
|
239 |
|
240 |
+
def get_consensus_label(results):
|
241 |
+
labels = [r[4] for r in results if len(r) > 4]
|
242 |
+
if not labels:
|
243 |
+
return "No results"
|
244 |
+
consensus = max(set(labels), key=labels.count)
|
245 |
+
color = {"AI": "red", "REAL": "green", "UNCERTAIN": "orange"}.get(consensus, "gray")
|
246 |
+
return f"<b><span style='color:{color}'>{consensus}</span></b>"
|
247 |
+
|
248 |
+
# Update predict_image_with_json to return consensus label
|
249 |
|
250 |
def predict_image_with_json(img, confidence_threshold, augment_methods, rotate_degrees, noise_level, sharpen_strength):
|
251 |
if augment_methods:
|
|
|
276 |
r.get("Real Score", ""),
|
277 |
r.get("Label", "")
|
278 |
] for r in results]
|
279 |
+
consensus = get_consensus_label(table_rows)
|
280 |
+
return img_pil, forensics_images, table_rows, results, consensus
|
281 |
|
282 |
with gr.Blocks(css="#post-gallery { overflow: hidden !important;} .grid-wrap{ overflow-y: hidden !important;} .ms-gr-ant-welcome-icon{ height:unset !important;} .tabs{margin-top:10px;}") as demo:
|
283 |
with ms.Application() as app:
|
|
|
315 |
forensics_gallery = gr.Gallery(label="Post Processed Images", visible=True, columns=[4], rows=[2], container=False, height="auto", object_fit="contain", elem_id="post-gallery")
|
316 |
with gr.Accordion("Debug Output (Raw JSON)", open=False):
|
317 |
debug_json = gr.JSON(label="Raw Model Results")
|
318 |
+
consensus_md = gr.Markdown(label="Consensus", value="")
|
319 |
|
320 |
+
outputs = [image_output, forensics_gallery, results_table, debug_json, consensus_md]
|
321 |
|
322 |
# Show/hide rotate slider based on selected augmentation method
|
323 |
augment_checkboxgroup.change(lambda methods: gr.update(visible="rotate" in methods), inputs=[augment_checkboxgroup], outputs=[rotate_slider])
|
requirements.txt
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
-
gradio
|
2 |
gradio_leaderboard
|
3 |
transformers
|
4 |
-
huggingface_hub
|
5 |
torchvision
|
6 |
torch
|
7 |
spaces
|
|
|
1 |
+
gradio[mcp]
|
2 |
gradio_leaderboard
|
3 |
transformers
|
4 |
+
huggingface_hub[xet]
|
5 |
torchvision
|
6 |
torch
|
7 |
spaces
|