"""Gradio interface for Build 3: Explainable Decision Support Tool.""" import gradio as gr try: import spaces except ImportError: # Local/Colab fallback. Hugging Face ZeroGPU supplies the real package. class _SpacesFallback: @staticmethod def GPU(*args, **kwargs): def decorator(function): return function return decorator spaces = _SpacesFallback() from inference_engine import infer, render_report from knowledge_base import NO, UNKNOWN, YES CHOICES = [UNKNOWN, YES, NO] @spaces.GPU(duration=1) def zerogpu_startup_probe() -> str: """Register one bounded GPU function so the free ZeroGPU runtime can start. The application itself is a CPU-only rule engine and never calls this function. Keeping the probe separate prevents ordinary analyses from entering a GPU queue or consuming the user's ZeroGPU interaction quota. """ return "ZeroGPU runtime registered" def analyze( backend_running: str, health_check_passed: str, request_reached_server: str, cors_error_visible: str, api_key_present: str, status_code: str, ) -> tuple[str, dict]: facts = { "backend_running": backend_running, "health_check_passed": health_check_passed, "request_reached_server": request_reached_server, "cors_error_visible": cors_error_visible, "api_key_present": api_key_present, "status_code": status_code, } result = infer(facts) visible_facts = { **result.input_facts, **{f"derived:{key}": value for key, value in result.derived_facts.items()}, } return render_report(result), visible_facts def clear_form(): return (UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, "", "", {}) with gr.Blocks(title="Developer Connection Troubleshooter") as demo: gr.Markdown( """ # Developer Connection Troubleshooter A small knowledge-based decision-support system. It represents observations as facts, applies explicit rules, and shows an inference trace. Do not enter an actual API key; report only whether a required credential is present. """ ) with gr.Row(): with gr.Column(): backend_running = gr.Dropdown( CHOICES, value=UNKNOWN, label="Is the backend running?" ) health_check_passed = gr.Dropdown( CHOICES, value=UNKNOWN, label="Does the health endpoint respond?" ) request_reached_server = gr.Dropdown( CHOICES, value=UNKNOWN, label="Did the request reach the server?" ) with gr.Column(): cors_error_visible = gr.Dropdown( CHOICES, value=UNKNOWN, label="Is a CORS error visible?" ) api_key_present = gr.Dropdown( CHOICES, value=UNKNOWN, label="Is the required credential present?" ) status_code = gr.Textbox( label="HTTP status code", placeholder="For example: 200, 401, 404, or 500", max_lines=1, ) with gr.Row(): analyze_button = gr.Button("Analyze evidence", variant="primary") clear_button = gr.Button("Clear") with gr.Row(): report = gr.Markdown(label="Reasoning report") represented_facts = gr.JSON(label="Represented facts") gr.Examples( examples=[ [YES, YES, YES, NO, NO, "401"], [YES, YES, NO, YES, UNKNOWN, ""], [NO, YES, UNKNOWN, UNKNOWN, UNKNOWN, ""], [YES, YES, YES, NO, YES, "200"], ], inputs=[ backend_running, health_check_passed, request_reached_server, cors_error_visible, api_key_present, status_code, ], label="Test cases", ) inputs = [ backend_running, health_check_passed, request_reached_server, cors_error_visible, api_key_present, status_code, ] analyze_button.click(analyze, inputs=inputs, outputs=[report, represented_facts]) clear_button.click( clear_form, outputs=[*inputs, report, represented_facts], queue=False, ) if __name__ == "__main__": demo.launch()