LPX
commited on
Commit
·
88d2155
1
Parent(s):
ac9c2b2
feat: enhance image prediction output and UI components
Browse files- Modified `predict_image_with_json` to return a structured table of model results, excluding model path.
- Updated Gradio interface to include a debug JSON output for raw model results.
- Adjusted Dataframe headers to reflect the new output structure, removing the model path for clarity.
- Improved UI descriptions and ensured consistent formatting for better readability.
- app_mcp.py +18 -8
app_mcp.py
CHANGED
@@ -260,17 +260,23 @@ def predict_image_with_json(img, confidence_threshold, augment_methods, rotate_d
|
|
260 |
|
261 |
forensics_images = [img_pil, ela1, ela2, ela3, gradient_image, minmax_image]
|
262 |
|
263 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
264 |
|
265 |
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 iface:
|
266 |
with ms.Application() as app:
|
267 |
with antd.ConfigProvider():
|
268 |
antdx.Welcome(
|
269 |
-
icon=
|
270 |
-
"https://cdn-avatars.huggingface.co/v1/production/uploads/639daf827270667011153fbc/WpeSFhuB81DY-1TjNUmV_.png",
|
271 |
title="Welcome to Project OpenSight",
|
272 |
-
description=
|
273 |
-
"The OpenSight aims to be an open-source SOTA generated image detection model. This HF Space is not only an introduction but a educational playground for the public to evaluate and challenge current open source models. **Space will be upgraded shortly; inference on all 6 models should take about 1.2~ seconds.** "
|
274 |
)
|
275 |
with gr.Tab("👀 Detection Models Eval / Playground"):
|
276 |
gr.Markdown("# Open Source Detection Models Found on the Hub\n\n - **Space will be upgraded shortly;** inference on all 6 models should take about 1.2~ seconds once we're back on CUDA.\n - The **Community Forensics** mother of all detection models is now available for inference, head to the middle tab above this.\n - Lots of exciting things coming up, stay tuned!")
|
@@ -294,12 +300,16 @@ with gr.Blocks(css="#post-gallery { overflow: hidden !important;} .grid-wrap{ ov
|
|
294 |
# Use Gradio-native Dataframe to display results with headers
|
295 |
results_table = gr.Dataframe(
|
296 |
label="Model Predictions",
|
297 |
-
headers=["Model", "Contributor", "
|
298 |
-
datatype=["str", "str", "
|
299 |
)
|
300 |
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")
|
|
|
|
|
|
|
|
|
301 |
|
302 |
-
outputs = [image_output, forensics_gallery, results_table]
|
303 |
|
304 |
# Show/hide rotate slider based on selected augmentation method
|
305 |
augment_checkboxgroup.change(lambda methods: gr.update(visible="rotate" in methods), inputs=[augment_checkboxgroup], outputs=[rotate_slider])
|
|
|
260 |
|
261 |
forensics_images = [img_pil, ela1, ela2, ela3, gradient_image, minmax_image]
|
262 |
|
263 |
+
# Prepare table rows for Dataframe (exclude model path)
|
264 |
+
table_rows = [[
|
265 |
+
r.get("Model", ""),
|
266 |
+
r.get("Contributor", ""),
|
267 |
+
r.get("AI Score", ""),
|
268 |
+
r.get("Real Score", ""),
|
269 |
+
r.get("Label", "")
|
270 |
+
] for r in results]
|
271 |
+
return img_pil, forensics_images, table_rows, results
|
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 iface:
|
274 |
with ms.Application() as app:
|
275 |
with antd.ConfigProvider():
|
276 |
antdx.Welcome(
|
277 |
+
icon="https://cdn-avatars.huggingface.co/v1/production/uploads/639daf827270667011153fbc/WpeSFhuB81DY-1TjNUmV_.png",
|
|
|
278 |
title="Welcome to Project OpenSight",
|
279 |
+
description="The OpenSight aims to be an open-source SOTA generated image detection model. This HF Space is not only an introduction but a educational playground for the public to evaluate and challenge current open source models. **Space will be upgraded shortly; inference on all 6 models should take about 1.2~ seconds.** "
|
|
|
280 |
)
|
281 |
with gr.Tab("👀 Detection Models Eval / Playground"):
|
282 |
gr.Markdown("# Open Source Detection Models Found on the Hub\n\n - **Space will be upgraded shortly;** inference on all 6 models should take about 1.2~ seconds once we're back on CUDA.\n - The **Community Forensics** mother of all detection models is now available for inference, head to the middle tab above this.\n - Lots of exciting things coming up, stay tuned!")
|
|
|
300 |
# Use Gradio-native Dataframe to display results with headers
|
301 |
results_table = gr.Dataframe(
|
302 |
label="Model Predictions",
|
303 |
+
headers=["Model", "Contributor", "AI Score", "Real Score", "Label"],
|
304 |
+
datatype=["str", "str", "number", "number", "str"]
|
305 |
)
|
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 |
+
debug_json = gr.JSON(label="Raw Model Results")
|
308 |
+
debug_accordion = gr.Accordion("Debug Output (Raw JSON)", open=False)
|
309 |
+
with debug_accordion:
|
310 |
+
debug_json.render()
|
311 |
|
312 |
+
outputs = [image_output, forensics_gallery, results_table, debug_json]
|
313 |
|
314 |
# Show/hide rotate slider based on selected augmentation method
|
315 |
augment_checkboxgroup.change(lambda methods: gr.update(visible="rotate" in methods), inputs=[augment_checkboxgroup], outputs=[rotate_slider])
|