Spaces:
Sleeping
Sleeping
Kesheratmex
commited on
Commit
·
fbb1bc8
1
Parent(s):
0937e36
Reorganize UI: move tabs into app_group and add placeholder pass.
Browse files
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 |
-
|
| 806 |
-
|
| 807 |
-
|
| 808 |
-
|
| 809 |
-
|
| 810 |
-
|
| 811 |
-
|
| 812 |
-
|
| 813 |
-
|
| 814 |
-
|
| 815 |
-
|
| 816 |
-
|
| 817 |
-
|
| 818 |
-
|
| 819 |
-
|
| 820 |
-
|
| 821 |
-
|
| 822 |
-
|
| 823 |
-
|
| 824 |
-
|
| 825 |
-
|
| 826 |
-
|
| 827 |
-
|
| 828 |
-
|
| 829 |
-
|
| 830 |
-
|
| 831 |
-
|
| 832 |
-
|
| 833 |
-
|
| 834 |
-
|
| 835 |
-
return "
|
| 836 |
-
|
| 837 |
-
|
| 838 |
-
|
| 839 |
-
|
| 840 |
-
|
| 841 |
-
|
| 842 |
-
|
| 843 |
-
|
| 844 |
-
|
| 845 |
-
|
| 846 |
-
|
| 847 |
-
|
| 848 |
-
|
| 849 |
-
|
| 850 |
-
|
| 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)
|