Spaces:
Runtime error
Runtime error
Download src/ui/admin_ui.py from MetiMiester/Venus: direct link, hf CLI and curl.
- Browser
- Download file 1.24 kB
-
https://huggingface.co/spaces/MetiMiester/Venus/resolve/main/src/ui/admin_ui.py
- Command line
-
hf download hf://spaces/MetiMiester/Venus/src/ui/admin_ui.py
-
curl -L -o admin_ui.py https://huggingface.co/spaces/MetiMiester/Venus/resolve/main/src/ui/admin_ui.py
1.24 kB
| import gradio as gr | |
| from src.services.auth_service import is_admin | |
| from src.db.connection import get_conn | |
| from src.db.audit import recent as recent_audit | |
| def render_admin_tab(db_path: str, auth_state: gr.State): | |
| with gr.Column() as panel: | |
| gr.Markdown("## Admin") | |
| info = gr.Markdown("Login as **Dr** to access admin features.") | |
| refresh = gr.Button("Refresh Audit (Admin)") | |
| table = gr.Dataframe( | |
| headers=["entity","entity_id","action","note","changed_by","changed_at_utc"], | |
| interactive=False, | |
| row_count=15, | |
| col_count=6, | |
| ) | |
| def _refresh(auth): | |
| if not auth: | |
| return "Please login.", [] | |
| if not is_admin(auth): | |
| return "β Admin only.", [] | |
| conn = get_conn(db_path) | |
| try: | |
| rows = recent_audit(conn, limit=30) | |
| finally: | |
| conn.close() | |
| data = [[r["entity"], r["entity_id"], r["action"], r["note"], r["changed_by"], r["changed_at_utc"]] for r in rows] | |
| return "β Audit loaded.", data | |
| refresh.click(_refresh, inputs=[auth_state], outputs=[info, table]) | |
| panel.load(_refresh, inputs=[auth_state], outputs=[info, table]) | |
| return panel, {} | |