Spaces:
Sleeping
Sleeping
Kesheratmex
commited on
Commit
·
ac470f2
1
Parent(s):
9f9bffe
**Add media tabs, detection button, and report/metrics tools to app UI**
Browse files
app.py
CHANGED
|
@@ -802,54 +802,62 @@ with gr.Blocks(
|
|
| 802 |
btn_enter = gr.Button("Entrar")
|
| 803 |
|
| 804 |
with gr.Group(visible=False) as app_group:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 805 |
with gr.Row():
|
| 806 |
-
with gr.
|
| 807 |
-
|
| 808 |
-
|
| 809 |
-
|
| 810 |
-
|
| 811 |
-
|
| 812 |
-
|
| 813 |
-
|
| 814 |
-
|
| 815 |
-
|
| 816 |
-
|
| 817 |
-
|
| 818 |
-
|
| 819 |
-
|
| 820 |
-
with gr.TabItem("Reportes"):
|
| 821 |
-
btn_report = gr.Button("Generar analisis fuerte")
|
| 822 |
-
status = gr.Textbox(label="Estado", interactive=False)
|
| 823 |
-
pdf_out = gr.File(label="Reporte PDF")
|
| 824 |
-
md_out = gr.File(label="Reporte Markdown")
|
| 825 |
-
json_out = gr.File(label="Reporte JSON")
|
| 826 |
-
def _on_report(vid, img):
|
| 827 |
-
path = None
|
| 828 |
-
if vid:
|
| 829 |
-
path = vid
|
| 830 |
-
elif img:
|
| 831 |
-
path = img if isinstance(img, str) else getattr(img, "name", None)
|
| 832 |
-
if not path:
|
| 833 |
-
return "No media provided", None, None, None
|
| 834 |
-
res = generar_analisis_fuerte(path)
|
| 835 |
-
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)
|
| 836 |
-
btn_report.click(fn=_on_report, inputs=[video_input, image_input], outputs=[status, pdf_out, md_out, json_out])
|
| 837 |
-
# Métricas tab: only metrics tools
|
| 838 |
-
with gr.TabItem("Métricas"):
|
| 839 |
-
btn_metrics = gr.Button("Ver métricas")
|
| 840 |
-
out_metrics = gr.JSON(label="Métricas", visible=True)
|
| 841 |
-
btn_metrics.click(fn=get_metrics, outputs=out_metrics, api_name="metrics")
|
| 842 |
-
|
| 843 |
-
# Shared components (must be inside app_group so they are hidden before token)
|
| 844 |
-
output_video = gr.Video(label="Vídeo anotado", visible=False)
|
| 845 |
-
output_image = gr.Image(label="Imagen anotada", visible=False)
|
| 846 |
-
json_video = gr.JSON(visible=False)
|
| 847 |
-
json_image = gr.JSON(visible=False)
|
| 848 |
-
btn_detect = gr.Button("Detectar defectos")
|
| 849 |
-
ev_video = btn_detect.click(fn=infer_media, inputs=video_input, outputs=json_video, api_name="infer_media")
|
| 850 |
-
ev_video.then(_extract_video_update, inputs=json_video, outputs=output_video)
|
| 851 |
-
ev_image = btn_detect.click(fn=infer_media, inputs=image_input, outputs=json_image, api_name="infer_media_1")
|
| 852 |
-
ev_image.then(_extract_path_update, inputs=json_image, outputs=output_image)
|
| 853 |
|
| 854 |
# Wire the gate
|
| 855 |
btn_enter.click(fn=_check_token, inputs=[gate_token], outputs=[gate_group, app_group, gate_status])
|
|
|
|
| 802 |
btn_enter = gr.Button("Entrar")
|
| 803 |
|
| 804 |
with gr.Group(visible=False) as app_group:
|
| 805 |
+
# Input section: tabs for different media types
|
| 806 |
+
with gr.Tabs() as media_tabs:
|
| 807 |
+
# Video tab: only video input
|
| 808 |
+
with gr.TabItem("Vídeo"):
|
| 809 |
+
video_input = gr.Video(label="Sube tu vídeo de inspección")
|
| 810 |
+
# Imagen tab: only image input
|
| 811 |
+
with gr.TabItem("Imagen"):
|
| 812 |
+
image_input = gr.Image(type="filepath", label="Sube una imagen de inspección")
|
| 813 |
+
# Configuración tab: only classes tools
|
| 814 |
+
with gr.TabItem("Configuración"):
|
| 815 |
+
btn_classes = gr.Button("Mostrar clases del modelo")
|
| 816 |
+
txt_classes = gr.Textbox(label="Clases cargadas", interactive=False)
|
| 817 |
+
btn_classes.click(fn=show_classes, outputs=txt_classes)
|
| 818 |
+
# Reportes tab: only report tools
|
| 819 |
+
with gr.TabItem("Reportes"):
|
| 820 |
+
btn_report = gr.Button("Generar analisis fuerte")
|
| 821 |
+
status = gr.Textbox(label="Estado", interactive=False)
|
| 822 |
+
pdf_out = gr.File(label="Reporte PDF")
|
| 823 |
+
md_out = gr.File(label="Reporte Markdown")
|
| 824 |
+
json_out = gr.File(label="Reporte JSON")
|
| 825 |
+
def _on_report(vid, img):
|
| 826 |
+
path = None
|
| 827 |
+
if vid:
|
| 828 |
+
path = vid
|
| 829 |
+
elif img:
|
| 830 |
+
path = img if isinstance(img, str) else getattr(img, "name", None)
|
| 831 |
+
if not path:
|
| 832 |
+
return "No media provided", None, None, None
|
| 833 |
+
res = generar_analisis_fuerte(path)
|
| 834 |
+
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)
|
| 835 |
+
btn_report.click(fn=_on_report, inputs=[video_input, image_input], outputs=[status, pdf_out, md_out, json_out])
|
| 836 |
+
# Métricas tab: only metrics tools
|
| 837 |
+
with gr.TabItem("Métricas"):
|
| 838 |
+
btn_metrics = gr.Button("Ver métricas")
|
| 839 |
+
out_metrics = gr.JSON(label="Métricas", visible=True)
|
| 840 |
+
btn_metrics.click(fn=get_metrics, outputs=out_metrics, api_name="metrics")
|
| 841 |
+
|
| 842 |
+
# Detection button (always visible after token)
|
| 843 |
+
btn_detect = gr.Button("Detectar defectos", variant="primary")
|
| 844 |
+
|
| 845 |
+
# Output section: results appear here after detection
|
| 846 |
with gr.Row():
|
| 847 |
+
with gr.Column():
|
| 848 |
+
output_video = gr.Video(label="Vídeo anotado", visible=False)
|
| 849 |
+
with gr.Column():
|
| 850 |
+
output_image = gr.Image(label="Imagen anotada", visible=False)
|
| 851 |
+
|
| 852 |
+
# Hidden JSON components for API chaining
|
| 853 |
+
json_video = gr.JSON(visible=False)
|
| 854 |
+
json_image = gr.JSON(visible=False)
|
| 855 |
+
|
| 856 |
+
# Wire up the detection events
|
| 857 |
+
ev_video = btn_detect.click(fn=infer_media, inputs=video_input, outputs=json_video, api_name="infer_media")
|
| 858 |
+
ev_video.then(_extract_video_update, inputs=json_video, outputs=output_video)
|
| 859 |
+
ev_image = btn_detect.click(fn=infer_media, inputs=image_input, outputs=json_image, api_name="infer_media_1")
|
| 860 |
+
ev_image.then(_extract_path_update, inputs=json_image, outputs=output_image)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 861 |
|
| 862 |
# Wire the gate
|
| 863 |
btn_enter.click(fn=_check_token, inputs=[gate_token], outputs=[gate_group, app_group, gate_status])
|