"""NEXUS Visual Weaver v2.0 โ€” Diagnostic Build""" import gradio as gr import os import sys # Add src to path ROOT = os.path.dirname(os.path.abspath(__file__)) SRC = os.path.join(ROOT, "src") if SRC not in sys.path: sys.path.insert(0, SRC) DIAGNOSTIC = [] def check_imports(): results = [] # Basic imports try: import spaces results.append(("spaces", "OK", "")) except Exception as e: results.append(("spaces", "FAIL", str(e)[:100])) # Package imports for mod_name, mod_path in [ ("catalog", "nexus_visual_weaver.catalog"), ("exporter", "nexus_visual_weaver.exporter"), ("hf_runtime", "nexus_visual_weaver.hf_runtime"), ("model_relay", "nexus_visual_weaver.model_relay"), ("planner", "nexus_visual_weaver.planner"), ("provider_runtime", "nexus_visual_weaver.provider_runtime"), ("render", "nexus_visual_weaver.render"), ("security", "nexus_visual_weaver.security"), ("styles", "nexus_visual_weaver.styles"), ]: try: __import__(mod_path) results.append((mod_name, "OK", "")) except Exception as e: results.append((mod_name, "FAIL", str(e)[:100])) return results def run_diagnostics(): results = check_imports() text = "## Import Diagnostics\n" all_ok = True for name, status, error in results: icon = "โœ…" if status == "OK" else "โŒ" text += f"- {icon} **{name}**: {status}" if error: text += f" โ€” `{error}`" all_ok = False text += "\n" if all_ok: text += "\n๐ŸŽ‰ All imports OK! The Space should work." else: text += "\nโš ๏ธ Some imports failed. Check the errors above." return text with gr.Blocks(title="NEXUS Visual Weaver v2.0 โ€” Diagnostic") as demo: gr.Markdown("# ๐Ÿงต NEXUS Visual Weaver v2.0 โ€” Diagnostic Mode") gr.Markdown("Checking all module imports to find the runtime error...") diag_btn = gr.Button("Run Diagnostics", variant="primary") diag_output = gr.Markdown("Click Run Diagnostics to check...") diag_btn.click(fn=run_diagnostics, inputs=[], outputs=diag_output) # Auto-run on load demo.load(fn=run_diagnostics, inputs=[], outputs=diag_output) if __name__ == "__main__": demo.launch(server_name="0.0.0.0", server_port=int(os.environ.get("PORT", "7860")))