Spaces:
Sleeping
Sleeping
Kesheratmex
commited on
Commit
·
3433b9f
1
Parent(s):
b21e167
Add report, metrics, and configuration tabs to Gradio UI and refactor update helpers
Browse files
app.py
CHANGED
|
@@ -182,13 +182,6 @@ def infer_media(media_path, conf=0.25, iou=0.45, out_res="720p", preset="default
|
|
| 182 |
if cap:
|
| 183 |
cap.release()
|
| 184 |
|
| 185 |
-
def _extract_video_update(d):
|
| 186 |
-
v = (d.get("video") if isinstance(d, dict) else d)
|
| 187 |
-
return gr.update(value=v, visible=True)
|
| 188 |
-
|
| 189 |
-
def _extract_path_update(d):
|
| 190 |
-
v = (d.get("path") if isinstance(d, dict) else d)
|
| 191 |
-
return gr.update(value=v, visible=True)
|
| 192 |
|
| 193 |
# registrar métricas
|
| 194 |
_record_metrics("video", counts)
|
|
@@ -247,6 +240,14 @@ def _extract_video(d):
|
|
| 247 |
def _extract_path(d):
|
| 248 |
return (d.get("path") if isinstance(d, dict) else d)
|
| 249 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 250 |
def compute_visual_features(image_path, detections=None):
|
| 251 |
"""Compute simple visual features and return a short description plus numeric metrics.
|
| 252 |
|
|
@@ -787,11 +788,37 @@ with gr.Blocks(
|
|
| 787 |
|
| 788 |
with gr.Row():
|
| 789 |
media_tabs = gr.Tabs()
|
| 790 |
-
|
| 791 |
-
|
| 792 |
-
|
| 793 |
-
|
| 794 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 795 |
|
| 796 |
output_video = gr.Video(label="Vídeo anotado", visible=False)
|
| 797 |
output_image = gr.Image(label="Imagen anotada", visible=False)
|
|
|
|
| 182 |
if cap:
|
| 183 |
cap.release()
|
| 184 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
|
| 186 |
# registrar métricas
|
| 187 |
_record_metrics("video", counts)
|
|
|
|
| 240 |
def _extract_path(d):
|
| 241 |
return (d.get("path") if isinstance(d, dict) else d)
|
| 242 |
|
| 243 |
+
def _extract_video_update(d):
|
| 244 |
+
v = (d.get("video") if isinstance(d, dict) else d)
|
| 245 |
+
return gr.update(value=v, visible=True)
|
| 246 |
+
|
| 247 |
+
def _extract_path_update(d):
|
| 248 |
+
v = (d.get("path") if isinstance(d, dict) else d)
|
| 249 |
+
return gr.update(value=v, visible=True)
|
| 250 |
+
|
| 251 |
def compute_visual_features(image_path, detections=None):
|
| 252 |
"""Compute simple visual features and return a short description plus numeric metrics.
|
| 253 |
|
|
|
|
| 788 |
|
| 789 |
with gr.Row():
|
| 790 |
media_tabs = gr.Tabs()
|
| 791 |
+
with media_tabs:
|
| 792 |
+
with gr.TabItem("Vídeo"):
|
| 793 |
+
video_input = gr.Video(label="Sube tu vídeo de inspección")
|
| 794 |
+
with gr.TabItem("Imagen"):
|
| 795 |
+
image_input = gr.Image(type="filepath", label="Sube una imagen de inspección")
|
| 796 |
+
with gr.TabItem("Configuración"):
|
| 797 |
+
btn_classes = gr.Button("Mostrar clases del modelo")
|
| 798 |
+
txt_classes = gr.Textbox(label="Clases cargadas", interactive=False)
|
| 799 |
+
btn_classes.click(fn=show_classes, outputs=txt_classes)
|
| 800 |
+
with gr.TabItem("Reportes"):
|
| 801 |
+
btn_report = gr.Button("Generar analisis fuerte")
|
| 802 |
+
status = gr.Textbox(label="Estado", interactive=False)
|
| 803 |
+
pdf_out = gr.File(label="Reporte PDF")
|
| 804 |
+
md_out = gr.File(label="Reporte Markdown")
|
| 805 |
+
json_out = gr.File(label="Reporte JSON")
|
| 806 |
+
def _on_report(vid, img):
|
| 807 |
+
path = None
|
| 808 |
+
if vid:
|
| 809 |
+
path = vid
|
| 810 |
+
elif img:
|
| 811 |
+
path = img if isinstance(img, str) else getattr(img, "name", None)
|
| 812 |
+
if not path:
|
| 813 |
+
return "No media provided", None, None, None
|
| 814 |
+
res = generar_analisis_fuerte(path)
|
| 815 |
+
return res.get("status", "error"), (res.get("report_pdf") if res.get("report_pdf") else None), (res.get("report_md") if res.get("report_md") else None), (res.get("report_json") if res.get("report_json") else None)
|
| 816 |
+
btn_report.click(fn=_on_report, inputs=[video_input, image_input], outputs=[status, pdf_out, md_out, json_out])
|
| 817 |
+
with gr.TabItem("Métricas"):
|
| 818 |
+
btn_metrics = gr.Button("Ver métricas")
|
| 819 |
+
out_metrics = gr.JSON(label="Métricas", visible=True)
|
| 820 |
+
btn_metrics.click(fn=get_metrics, outputs=out_metrics, api_name="metrics")
|
| 821 |
+
|
| 822 |
|
| 823 |
output_video = gr.Video(label="Vídeo anotado", visible=False)
|
| 824 |
output_image = gr.Image(label="Imagen anotada", visible=False)
|