Spaces:
Sleeping
Sleeping
Kesheratmex
commited on
Commit
Β·
0937e36
1
Parent(s):
8a4abef
**Add token gate to public Gradio app and update UI title**
Browse filesImplemented a simple tokenβbased access gate for the public app.
- Added `_check_token` helper that validates a token from environment variables (`APP_ACCESS_TOKEN` or `KESHERAT_TOKEN`) and returns visibility updates.
- Introduced a gate UI group with a password textbox, status message, and βEntrarβ button.
- Updated the app title and header text to βKESHERAT AIβ.
- Connected the gate button to the `_check_token` function, hiding the main app until a valid token is entered.
- Adjusted imports and placeholders for the gated app components.
app.py
CHANGED
|
@@ -248,6 +248,17 @@ 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 |
|
|
@@ -774,17 +785,25 @@ def generar_analisis_fuerte(media_path):
|
|
| 774 |
except Exception as e:
|
| 775 |
return {"status": f"error: {e}", "report_pdf": None, "report_md": None, "report_json": None}
|
| 776 |
|
| 777 |
-
# ββββββββββββββββββββββββββββ
|
| 778 |
-
# Interfaz Gradio (extendida)
|
| 779 |
# ββββββββββββββββββββββββββββ
|
| 780 |
with gr.Blocks(
|
| 781 |
-
title="
|
| 782 |
theme=gr.themes.Soft(),
|
| 783 |
) as demo:
|
| 784 |
gr.HTML("""
|
| 785 |
<link rel=\"stylesheet\" href=\"/file=assets/kesheret.css\" />
|
| 786 |
-
<div class=\"kesheret-header\"><h1
|
| 787 |
""")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 788 |
|
| 789 |
with gr.Row():
|
| 790 |
with gr.Tabs() as media_tabs:
|
|
@@ -830,6 +849,8 @@ with gr.Blocks(
|
|
| 830 |
json_video = gr.JSON(visible=False)
|
| 831 |
json_image = gr.JSON(visible=False)
|
| 832 |
|
|
|
|
|
|
|
| 833 |
btn_detect = gr.Button("Detectar defectos")
|
| 834 |
|
| 835 |
# Endpoint API para vΓdeo: devuelve dict {video, classes}. UI: muestra resultado solo tras anΓ‘lisis
|
|
|
|
| 248 |
v = (d.get("path") if isinstance(d, dict) else d)
|
| 249 |
return gr.update(value=v, visible=True)
|
| 250 |
|
| 251 |
+
def _check_token(token: str):
|
| 252 |
+
"""Token gate for public app. Expected token via env APP_ACCESS_TOKEN or KESHERAT_TOKEN.
|
| 253 |
+
Defaults to 'KESHERAT' if none provided.
|
| 254 |
+
Returns visibility updates for [gate_group, app_group, gate_status]."""
|
| 255 |
+
expected = os.getenv("APP_ACCESS_TOKEN") or os.getenv("KESHERAT_TOKEN") or "KESHERAT"
|
| 256 |
+
ok = str(token or "").strip() == str(expected).strip()
|
| 257 |
+
if ok:
|
| 258 |
+
return gr.update(visible=False), gr.update(visible=True), gr.update(visible=False, value="")
|
| 259 |
+
else:
|
| 260 |
+
return gr.update(visible=True), gr.update(visible=False), gr.update(visible=True, value="Token invΓ‘lido. Intenta nuevamente.")
|
| 261 |
+
|
| 262 |
def compute_visual_features(image_path, detections=None):
|
| 263 |
"""Compute simple visual features and return a short description plus numeric metrics.
|
| 264 |
|
|
|
|
| 785 |
except Exception as e:
|
| 786 |
return {"status": f"error: {e}", "report_pdf": None, "report_md": None, "report_json": None}
|
| 787 |
|
|
|
|
|
|
|
| 788 |
# ββββββββββββββββββββββββββββ
|
| 789 |
with gr.Blocks(
|
| 790 |
+
title="KESHERAT AI",
|
| 791 |
theme=gr.themes.Soft(),
|
| 792 |
) as demo:
|
| 793 |
gr.HTML("""
|
| 794 |
<link rel=\"stylesheet\" href=\"/file=assets/kesheret.css\" />
|
| 795 |
+
<div class=\"kesheret-header\"><h1>KESHERAT AI</h1><p>KESHERAT AI</p></div>
|
| 796 |
""")
|
| 797 |
+
# Access gate (token) β app is public but gated by token
|
| 798 |
+
with gr.Group(visible=True) as gate_group:
|
| 799 |
+
gr.Markdown("### Acceso β Introduce tu token de seguridad")
|
| 800 |
+
gate_token = gr.Textbox(label="Token", type="password", placeholder="Introduce tu token")
|
| 801 |
+
gate_status = gr.Markdown(visible=False)
|
| 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:
|
|
|
|
| 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
|