"""Binary search: does the full app crash because of CSS, plots, or something else?""" import os, sys os.environ["SOUNDBROKEN_MOCK"] = "1" sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) import gradio as gr from audio_analyzer import extract_features from fault_rules import rank_candidates, RULES from json_guard import validate from feature_prompt import build_diagnosis_prompt, SYSTEM_PROMPT APPLIANCES = list(RULES.keys()) # Load CSS from file css_path = os.path.join(os.path.dirname(__file__), "assets", "custom.css") with open(css_path, "r", encoding="utf-8") as f: custom_css = f.read() print("[test] CSS loaded", flush=True) # Simple mock generate def _mock_generate(prompt, candidates, features): import json top = candidates[0] return json.dumps({ "fault": top.name, "urgency": top.urgency, "checks": ["Check component.", "Listen again.", "Call tech."], "safety": "Disconnect power.", "confidence": int(top.weight * 100), }) print("[test] Building Blocks...", flush=True) with gr.Blocks(css=custom_css, title="Does It Sound Broken?") as demo: state = gr.State({}) gr.Markdown("# Does It Sound Broken?") with gr.Tabs(): with gr.Tab("Diagnose"): with gr.Row(): with gr.Column(): audio_in = gr.Audio(sources=["microphone","upload"], type="filepath", label="Record audio") appliance = gr.Dropdown(choices=APPLIANCES, value="Washing machine", label="Appliance") diagnose_btn = gr.Button("Diagnose", variant="primary") gr.Examples( examples=[ ["assets/sample_washer_bearing.wav", "Washing machine"], ["assets/sample_fan_imbalanced.wav", "Electric fan"], ], inputs=[audio_in, appliance], ) with gr.Column(): verdict_out = gr.HTML() features_out = gr.Markdown() candidates_out = gr.Markdown() def diagnose(audio_path, appl, state_dict): if not audio_path: return "