#!/usr/bin/env python3 """ Hugging Face Spaces deployment for Residential Architecture Assistant Standalone version that avoids all LangGraph imports at startup """ import os import gradio as gr def create_interface(): """Create interface that works reliably in HF Spaces""" def handle_chat(message, history, api_key, user_id=""): if not api_key or not api_key.strip(): error_msg = "❌ Please provide your OpenAI API key to start using the Architecture Assistant." history.append([message, error_msg]) return history, "" if not message.strip(): return history, "" try: # Only import when actually needed to avoid schema issues from graph import ArchitectureAssistant # Create assistant instance assistant = ArchitectureAssistant( openai_api_key=api_key.strip(), user_id=user_id.strip() if user_id.strip() else f"hf_user_{len(history)}" ) # Get response response = assistant.chat(message) history.append([message, response]) except ImportError as e: error_msg = f"""❌ **System modules not available**: {str(e)} **This should be the Residential Architecture Assistant** with: - 🏛️ Architecture design guidance - 💰 Montreal market cost analysis - 📐 Professional floorplan generation - 📋 Building codes & permit requirements The system modules couldn't be loaded in this environment. Please try again or contact support.""" history.append([message, error_msg]) except Exception as e: error_msg = f"""❌ **Error**: {str(e)} **Troubleshooting:** 1. **Check your OpenAI API key** - Ensure it's valid and has credits 2. **Try a simpler question** - Start with basic architecture questions 3. **Wait and retry** - There might be temporary connectivity issues **Expected functionality:** - Multi-agent architecture consultation - Montreal-specific building analysis - Professional floorplan generation - Building code guidance Please try again or contact support if issues persist.""" history.append([message, error_msg]) return history, "" with gr.Blocks(title="🏠 Architecture Assistant") as interface: gr.HTML("""

🏠 Residential Architecture Assistant

Multi-Agent LangGraph System for Professional Architecture Consultation

✨ 7 AI Specialists | 📐 Professional Floorplans | 💰 Montreal Market Analysis | 📋 Building Codes

""") # API Key input api_key = gr.Textbox( label="🔑 OpenAI API Key", type="password", placeholder="Enter your OpenAI API key (sk-...)", info="Required for AI functionality. Not stored or logged." ) # Optional User ID user_id = gr.Textbox( label="👤 User ID (Optional)", placeholder="Enter a unique ID to save your conversation (e.g., 'john_house_project')", info="Leave blank for anonymous session" ) # Chat interface chatbot = gr.Chatbot( label="💬 Architecture Consultation", height=400 ) msg = gr.Textbox( label="Your Message", placeholder="Ask about home design, budgets, floorplans, Montreal building codes...", lines=2 ) with gr.Row(): send_btn = gr.Button("📤 Send", variant="primary") clear_btn = gr.Button("🔄 Clear", variant="secondary") gr.HTML("""

💡 Example Questions:

🤖 Our AI Specialists:

""") # Event handlers msg.submit(handle_chat, [msg, chatbot, api_key, user_id], [chatbot, msg]) send_btn.click(handle_chat, [msg, chatbot, api_key, user_id], [chatbot, msg]) clear_btn.click(lambda: ([], ""), outputs=[chatbot, msg]) gr.HTML("""

🏠 Residential Architecture Assistant v3.0

Built with LangGraph • Powered by OpenAI • Interface by Gradio

Professional architecture consultation from concept to construction

""") return interface if __name__ == "__main__": demo = create_interface() demo.launch()