wangzerui commited on
Commit
c64b8ce
Β·
1 Parent(s): 69ca011
Files changed (2) hide show
  1. __pycache__/app.cpython-311.pyc +0 -0
  2. app.py +82 -86
__pycache__/app.cpython-311.pyc CHANGED
Binary files a/__pycache__/app.cpython-311.pyc and b/__pycache__/app.cpython-311.pyc differ
 
app.py CHANGED
@@ -1,73 +1,73 @@
1
  #!/usr/bin/env python3
2
  """
3
  Hugging Face Spaces deployment for Residential Architecture Assistant
4
- Simplified version to avoid schema issues
5
  """
6
 
7
- import os
8
  import gradio as gr
9
- import traceback
10
- from typing import List, Tuple
11
 
12
- # Create a minimal interface without complex imports to avoid schema issues
13
- def create_simple_interface():
14
- """Create a simple Gradio interface that works reliably in HF Spaces"""
15
 
16
- def handle_message(message: str, history: List[List[str]], api_key: str) -> Tuple[List[List[str]], str]:
17
- """Simple message handler"""
 
 
 
 
 
 
 
18
  try:
19
- if not api_key or not api_key.strip():
20
- error_msg = "❌ Please provide your OpenAI API key to start using the Architecture Assistant."
21
- history.append([message, error_msg])
22
- return history, ""
23
-
24
- if not message.strip():
25
- return history, ""
 
 
 
26
 
27
- # Try to import and use the actual system
28
- try:
29
- from graph import ArchitectureAssistant
30
-
31
- # Create assistant instance
32
- assistant = ArchitectureAssistant(
33
- openai_api_key=api_key.strip(),
34
- user_id=f"hf_user_{len(history)}"
35
- )
36
-
37
- # Get response
38
- response = assistant.chat(message)
39
- history.append([message, response])
40
-
41
- except Exception as e:
42
- # Fallback error handling
43
- error_msg = f"""❌ **System Error**: {str(e)}
44
 
45
- **Possible Solutions:**
46
- 1. **Check your OpenAI API key** - Make sure it's valid and has sufficient credits
47
- 2. **Try again** - Sometimes there are temporary connection issues
48
- 3. **Simpler questions** - Start with basic architecture questions
49
 
50
- **This is a multi-agent LangGraph system** that provides:
51
- - πŸ›οΈ **Architecture design guidance**
52
- - πŸ’° **Montreal market cost analysis**
53
- - πŸ“ **Professional floorplan generation**
54
- - πŸ“‹ **Building codes & permit requirements**
55
 
56
- Please try your question again, or contact support if the issue persists."""
57
-
58
- history.append([message, error_msg])
59
-
60
- return history, ""
61
 
62
  except Exception as e:
63
- # Final fallback
64
- error_msg = f"❌ Unexpected error: {str(e)}"
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  history.append([message, error_msg])
66
- return history, ""
67
-
68
- # Create interface with minimal components
69
- with gr.Blocks(title="🏠 Architecture Assistant") as demo:
70
 
 
 
 
71
  gr.HTML("""
72
  <div style="text-align: center; padding: 20px;">
73
  <h1>🏠 Residential Architecture Assistant</h1>
@@ -76,15 +76,13 @@ Please try your question again, or contact support if the issue persists."""
76
  </div>
77
  """)
78
 
79
- # API Key input
80
  api_key = gr.Textbox(
81
- label="πŸ”‘ OpenAI API Key",
82
- placeholder="Enter your OpenAI API key (sk-...)",
83
  type="password",
 
84
  info="Required for AI functionality. Not stored or logged."
85
  )
86
 
87
- # Chat interface
88
  chatbot = gr.Chatbot(
89
  label="πŸ’¬ Architecture Consultation",
90
  height=400
@@ -96,53 +94,51 @@ Please try your question again, or contact support if the issue persists."""
96
  lines=2
97
  )
98
 
99
- # Buttons
100
  with gr.Row():
101
  send_btn = gr.Button("πŸ“€ Send", variant="primary")
102
  clear_btn = gr.Button("πŸ”„ Clear", variant="secondary")
103
 
104
- # Examples
105
  gr.HTML("""
106
- <div style="margin: 20px; padding: 15px; background: #f0f0f0; border-radius: 10px;">
107
- <h4>πŸ’‘ Try these example questions:</h4>
108
- <ul>
109
  <li>"I want to design a home but don't know where to start"</li>
110
  <li>"I have a $800,000 budget for Montreal - is that realistic?"</li>
 
111
  <li>"Can you generate a floorplan for a 2500 sq ft house?"</li>
112
- <li>"What permits do I need in Montreal?"</li>
 
 
 
 
 
 
 
 
 
 
 
113
  </ul>
114
  </div>
115
  """)
116
 
117
  # Event handlers
118
- msg.submit(
119
- handle_message,
120
- inputs=[msg, chatbot, api_key],
121
- outputs=[chatbot, msg]
122
- )
123
-
124
- send_btn.click(
125
- handle_message,
126
- inputs=[msg, chatbot, api_key],
127
- outputs=[chatbot, msg]
128
- )
129
-
130
- clear_btn.click(
131
- lambda: ([], ""),
132
- outputs=[chatbot, msg]
133
- )
134
 
135
- # Footer
136
  gr.HTML("""
137
- <div style="text-align: center; padding: 20px; margin-top: 30px; border-top: 1px solid #ddd;">
138
- <p><strong>🏠 Residential Architecture Assistant</strong></p>
139
- <p>Multi-Agent LangGraph System β€’ Built with Gradio</p>
 
 
 
140
  </div>
141
  """)
142
 
143
- return demo
144
 
145
- # Launch the interface
146
  if __name__ == "__main__":
147
- demo = create_simple_interface()
148
  demo.launch()
 
1
  #!/usr/bin/env python3
2
  """
3
  Hugging Face Spaces deployment for Residential Architecture Assistant
4
+ Standalone version that completely avoids LangGraph imports until needed
5
  """
6
 
 
7
  import gradio as gr
 
 
8
 
9
+ def create_interface():
10
+ """Create interface that works reliably in HF Spaces"""
 
11
 
12
+ def handle_chat(message, history, api_key):
13
+ if not api_key or not api_key.strip():
14
+ error_msg = "❌ Please provide your OpenAI API key to start using the Architecture Assistant."
15
+ history.append([message, error_msg])
16
+ return history, ""
17
+
18
+ if not message.strip():
19
+ return history, ""
20
+
21
  try:
22
+ # Only import when actually used
23
+ from graph import ArchitectureAssistant
24
+
25
+ assistant = ArchitectureAssistant(
26
+ openai_api_key=api_key.strip(),
27
+ user_id=f"hf_user_{len(history)}"
28
+ )
29
+
30
+ response = assistant.chat(message)
31
+ history.append([message, response])
32
 
33
+ except ImportError as e:
34
+ error_msg = f"""❌ **Import Error**: {str(e)}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
+ **The system modules couldn't be loaded.** This might be due to:
37
+ 1. Missing dependencies in the Hugging Face Space
38
+ 2. Package compatibility issues
 
39
 
40
+ **This should be the Residential Architecture Assistant** with:
41
+ - πŸ›οΈ Architecture design guidance
42
+ - πŸ’° Montreal market cost analysis
43
+ - πŸ“ Professional floorplan generation
44
+ - πŸ“‹ Building codes & permit requirements
45
 
46
+ Please contact the space administrator to resolve the import issues."""
47
+
48
+ history.append([message, error_msg])
 
 
49
 
50
  except Exception as e:
51
+ error_msg = f"""❌ **System Error**: {str(e)}
52
+
53
+ **Troubleshooting:**
54
+ 1. **Check your OpenAI API key** - Ensure it's valid and has credits
55
+ 2. **Try a simpler question** - Start with basic architecture questions
56
+ 3. **Wait and retry** - There might be temporary connectivity issues
57
+
58
+ **Expected functionality:**
59
+ - Multi-agent architecture consultation
60
+ - Montreal-specific building analysis
61
+ - Professional floorplan generation
62
+ - Building code guidance
63
+
64
+ Please try again or contact support if issues persist."""
65
+
66
  history.append([message, error_msg])
 
 
 
 
67
 
68
+ return history, ""
69
+
70
+ with gr.Blocks(title="🏠 Architecture Assistant") as interface:
71
  gr.HTML("""
72
  <div style="text-align: center; padding: 20px;">
73
  <h1>🏠 Residential Architecture Assistant</h1>
 
76
  </div>
77
  """)
78
 
 
79
  api_key = gr.Textbox(
80
+ label="πŸ”‘ OpenAI API Key",
 
81
  type="password",
82
+ placeholder="Enter your OpenAI API key (sk-...)",
83
  info="Required for AI functionality. Not stored or logged."
84
  )
85
 
 
86
  chatbot = gr.Chatbot(
87
  label="πŸ’¬ Architecture Consultation",
88
  height=400
 
94
  lines=2
95
  )
96
 
 
97
  with gr.Row():
98
  send_btn = gr.Button("πŸ“€ Send", variant="primary")
99
  clear_btn = gr.Button("πŸ”„ Clear", variant="secondary")
100
 
 
101
  gr.HTML("""
102
+ <div style="background: #f8f9fa; padding: 15px; margin: 20px 0; border-radius: 8px;">
103
+ <h4>πŸ’‘ Example Questions:</h4>
104
+ <ul style="margin: 10px 0;">
105
  <li>"I want to design a home but don't know where to start"</li>
106
  <li>"I have a $800,000 budget for Montreal - is that realistic?"</li>
107
+ <li>"We're a family of 4, what size house do we need?"</li>
108
  <li>"Can you generate a floorplan for a 2500 sq ft house?"</li>
109
+ <li>"What building permits do I need in Montreal?"</li>
110
+ </ul>
111
+
112
+ <h4>πŸ€– Our AI Specialists:</h4>
113
+ <ul style="margin: 10px 0;">
114
+ <li><strong>RouterAgent:</strong> Intelligent conversation routing</li>
115
+ <li><strong>GeneralDesignAgent:</strong> Architecture principles & design guidance</li>
116
+ <li><strong>BudgetAnalysisAgent:</strong> Montreal market cost analysis</li>
117
+ <li><strong>FloorplanAgent:</strong> Spatial planning & requirements</li>
118
+ <li><strong>FloorplanGeneratorAgent:</strong> Detailed architectural specifications</li>
119
+ <li><strong>DetailedBudgetAgent:</strong> Comprehensive cost breakdowns</li>
120
+ <li><strong>RegulationAgent:</strong> Montreal building codes & permits</li>
121
  </ul>
122
  </div>
123
  """)
124
 
125
  # Event handlers
126
+ msg.submit(handle_chat, [msg, chatbot, api_key], [chatbot, msg])
127
+ send_btn.click(handle_chat, [msg, chatbot, api_key], [chatbot, msg])
128
+ clear_btn.click(lambda: ([], ""), outputs=[chatbot, msg])
 
 
 
 
 
 
 
 
 
 
 
 
 
129
 
 
130
  gr.HTML("""
131
+ <div style="text-align: center; padding: 20px; border-top: 1px solid #ddd; margin-top: 20px;">
132
+ <p><strong>🏠 Residential Architecture Assistant v3.0</strong></p>
133
+ <p>Built with <a href="https://langchain.ai/langgraph">LangGraph</a> β€’
134
+ Powered by <a href="https://openai.com">OpenAI</a> β€’
135
+ Interface by <a href="https://gradio.app">Gradio</a></p>
136
+ <p><em>Professional architecture consultation from concept to construction</em></p>
137
  </div>
138
  """)
139
 
140
+ return interface
141
 
 
142
  if __name__ == "__main__":
143
+ demo = create_interface()
144
  demo.launch()