Kesheratmex commited on
Commit
fbb1bc8
·
1 Parent(s): 0937e36

Reorganize UI: move tabs into app_group and add placeholder pass.

Browse files
Files changed (1) hide show
  1. app.py +58 -57
app.py CHANGED
@@ -802,64 +802,58 @@ with gr.Blocks(
802
  btn_enter = gr.Button("Entrar")
803
 
804
  with gr.Group(visible=False) as app_group:
805
- pass # placeholder; actual app components below
806
-
807
-
808
- with gr.Row():
809
- with gr.Tabs() as media_tabs:
810
- # Video tab: only video input
811
- with gr.TabItem("Vídeo"):
812
- video_input = gr.Video(label="Sube tu vídeo de inspección")
813
- # Imagen tab: only image input
814
- with gr.TabItem("Imagen"):
815
- image_input = gr.Image(type="filepath", label="Sube una imagen de inspección")
816
- # Configuración tab: only classes tools
817
- with gr.TabItem("Configuración"):
818
- btn_classes = gr.Button("Mostrar clases del modelo")
819
- txt_classes = gr.Textbox(label="Clases cargadas", interactive=False)
820
- btn_classes.click(fn=show_classes, outputs=txt_classes)
821
- # Reportes tab: only report tools
822
- with gr.TabItem("Reportes"):
823
- btn_report = gr.Button("Generar analisis fuerte")
824
- status = gr.Textbox(label="Estado", interactive=False)
825
- pdf_out = gr.File(label="Reporte PDF")
826
- md_out = gr.File(label="Reporte Markdown")
827
- json_out = gr.File(label="Reporte JSON")
828
- def _on_report(vid, img):
829
- path = None
830
- if vid:
831
- path = vid
832
- elif img:
833
- path = img if isinstance(img, str) else getattr(img, "name", None)
834
- if not path:
835
- return "No media provided", None, None, None
836
- res = generar_analisis_fuerte(path)
837
- 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)
838
- btn_report.click(fn=_on_report, inputs=[video_input, image_input], outputs=[status, pdf_out, md_out, json_out])
839
- # Métricas tab: only metrics tools
840
- with gr.TabItem("Métricas"):
841
- btn_metrics = gr.Button("Ver métricas")
842
- out_metrics = gr.JSON(label="Métricas", visible=True)
843
- btn_metrics.click(fn=get_metrics, outputs=out_metrics, api_name="metrics")
844
-
845
- output_video = gr.Video(label="Vídeo anotado", visible=False)
846
- output_image = gr.Image(label="Imagen anotada", visible=False)
847
-
848
- # Componentes JSON ocultos para soportar API devolviendo dict y encadenar a la UI
849
- json_video = gr.JSON(visible=False)
850
- json_image = gr.JSON(visible=False)
851
-
 
 
 
852
  btn_enter.click(fn=_check_token, inputs=[gate_token], outputs=[gate_group, app_group, gate_status])
853
 
854
- btn_detect = gr.Button("Detectar defectos")
855
-
856
- # Endpoint API para vídeo: devuelve dict {video, classes}. UI: muestra resultado solo tras análisis
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
-
860
- # Endpoint API para imagen: devuelve dict {path, classes}. UI: muestra resultado solo tras análisis
861
- ev_image = btn_detect.click(fn=infer_media, inputs=image_input, outputs=json_image, api_name="infer_media_1")
862
- ev_image.then(_extract_path_update, inputs=json_image, outputs=output_image)
863
 
864
 
865
 
@@ -867,5 +861,12 @@ with gr.Blocks(
867
  demo.queue()
868
 
869
  if __name__ == "__main__":
 
 
 
 
 
 
 
870
  # Permitir acceso de descarga a directorio temporal para evitar 403
871
- demo.launch(allowed_paths=[tempfile.gettempdir()])
 
802
  btn_enter = gr.Button("Entrar")
803
 
804
  with gr.Group(visible=False) as app_group:
805
+ with gr.Row():
806
+ with gr.Tabs() as media_tabs:
807
+ pass
808
+ # Video tab: only video input
809
+ with gr.TabItem("Vídeo"):
810
+ video_input = gr.Video(label="Sube tu vídeo de inspección")
811
+ # Imagen tab: only image input
812
+ with gr.TabItem("Imagen"):
813
+ image_input = gr.Image(type="filepath", label="Sube una imagen de inspección")
814
+ # Configuración tab: only classes tools
815
+ with gr.TabItem("Configuración"):
816
+ btn_classes = gr.Button("Mostrar clases del modelo")
817
+ txt_classes = gr.Textbox(label="Clases cargadas", interactive=False)
818
+ btn_classes.click(fn=show_classes, outputs=txt_classes)
819
+ # Reportes tab: only report tools
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])
856
 
 
 
 
 
 
 
 
 
 
857
 
858
 
859
 
 
861
  demo.queue()
862
 
863
  if __name__ == "__main__":
864
+ # Basic token auth at server level (prevents UI from loading without token)
865
+ expected = os.getenv("APP_ACCESS_TOKEN") or os.getenv("KESHERAT_TOKEN") or "KESHERAT"
866
+ def _basic_auth(user, password):
867
+ try:
868
+ return str(password or "").strip() == str(expected).strip()
869
+ except Exception:
870
+ return False
871
  # Permitir acceso de descarga a directorio temporal para evitar 403
872
+ demo.launch(allowed_paths=[tempfile.gettempdir()], auth=_basic_auth)