Spaces:
Runtime error
Runtime error
update
Browse files- __pycache__/app.cpython-311.pyc +0 -0
- 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 |
-
|
5 |
"""
|
6 |
|
7 |
-
import os
|
8 |
import gradio as gr
|
9 |
-
import traceback
|
10 |
-
from typing import List, Tuple
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
"""Create a simple Gradio interface that works reliably in HF Spaces"""
|
15 |
|
16 |
-
def
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
try:
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
26 |
|
27 |
-
|
28 |
-
|
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 |
-
**
|
46 |
-
1.
|
47 |
-
2.
|
48 |
-
3. **Simpler questions** - Start with basic architecture questions
|
49 |
|
50 |
-
**This
|
51 |
-
- ποΈ
|
52 |
-
- π°
|
53 |
-
- π
|
54 |
-
- π
|
55 |
|
56 |
-
Please
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
return history, ""
|
61 |
|
62 |
except Exception as e:
|
63 |
-
|
64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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="
|
107 |
-
<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 |
-
|
120 |
-
|
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;
|
138 |
-
<p><strong>π Residential Architecture Assistant</strong></p>
|
139 |
-
<p>
|
|
|
|
|
|
|
140 |
</div>
|
141 |
""")
|
142 |
|
143 |
-
return
|
144 |
|
145 |
-
# Launch the interface
|
146 |
if __name__ == "__main__":
|
147 |
-
demo =
|
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()
|