File size: 6,257 Bytes
10b617b
 
3e4f0ef
 
10b617b
 
eb8d8ce
10b617b
 
3e4f0ef
 
eb8d8ce
3e4f0ef
 
 
fa5cc48
3e4f0ef
eb8d8ce
3e4f0ef
 
eb8d8ce
 
3e4f0ef
 
10b617b
3e4f0ef
 
 
 
 
eb8d8ce
3e4f0ef
 
 
c64b8ce
3e4f0ef
 
 
 
 
 
 
 
 
 
eb8d8ce
c64b8ce
10b617b
 
3e4f0ef
c64b8ce
3e4f0ef
 
 
 
c64b8ce
3e4f0ef
 
 
 
 
 
 
 
 
eb8d8ce
3e4f0ef
 
 
10b617b
3e4f0ef
10b617b
3e4f0ef
 
10b617b
 
 
3e4f0ef
 
 
fa5cc48
3e4f0ef
fa5cc48
 
 
3e4f0ef
 
 
 
 
69ca011
 
3e4f0ef
 
 
 
 
10b617b
3e4f0ef
 
 
 
 
eb8d8ce
 
3e4f0ef
 
eb8d8ce
3e4f0ef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10b617b
 
3e4f0ef
 
 
eb8d8ce
3e4f0ef
 
 
 
 
 
 
 
 
10b617b
c64b8ce
10b617b
 
3e4f0ef
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/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("""
        <div style="text-align: center; padding: 20px;">
            <h1>🏠 Residential Architecture Assistant</h1>
            <p><strong>Multi-Agent LangGraph System for Professional Architecture Consultation</strong></p>
            <p>✨ 7 AI Specialists | πŸ“ Professional Floorplans | πŸ’° Montreal Market Analysis | πŸ“‹ Building Codes</p>
        </div>
        """)
        
        # 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("""
        <div style="background: #f8f9fa; padding: 15px; margin: 20px 0; border-radius: 8px;">
            <h4>πŸ’‘ Example Questions:</h4>
            <ul style="margin: 10px 0;">
                <li>"I want to design a home but don't know where to start"</li>
                <li>"I have a $800,000 budget for Montreal - is that realistic?"</li>
                <li>"We're a family of 4, what size house do we need?"</li>
                <li>"Can you generate a floorplan for a 2500 sq ft house?"</li>
                <li>"What building permits do I need in Montreal?"</li>
            </ul>
            
            <h4>πŸ€– Our AI Specialists:</h4>
            <ul style="margin: 10px 0;">
                <li><strong>RouterAgent:</strong> Intelligent conversation routing</li>
                <li><strong>GeneralDesignAgent:</strong> Architecture principles & design guidance</li>
                <li><strong>BudgetAnalysisAgent:</strong> Montreal market cost analysis</li>
                <li><strong>FloorplanAgent:</strong> Spatial planning & requirements</li>
                <li><strong>FloorplanGeneratorAgent:</strong> Detailed architectural specifications</li>
                <li><strong>DetailedBudgetAgent:</strong> Comprehensive cost breakdowns</li>
                <li><strong>RegulationAgent:</strong> Montreal building codes & permits</li>
            </ul>
        </div>
        """)
        
        # 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("""
        <div style="text-align: center; padding: 20px; border-top: 1px solid #ddd; margin-top: 20px;">
            <p><strong>🏠 Residential Architecture Assistant v3.0</strong></p>
            <p>Built with <a href="https://langchain.ai/langgraph">LangGraph</a> β€’ 
               Powered by <a href="https://openai.com">OpenAI</a> β€’ 
               Interface by <a href="https://gradio.app">Gradio</a></p>
            <p><em>Professional architecture consultation from concept to construction</em></p>
        </div>
        """)
    
    return interface

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