-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
243 lines (204 loc) · 8.72 KB
/
app.py
File metadata and controls
243 lines (204 loc) · 8.72 KB
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
import streamlit as st
import os
import time
from dotenv import load_dotenv
from agent import run_sequential_analysis, display_properties_professionally
load_dotenv()
DEFAULT_FIRECRAWL_API_KEY = os.getenv("FIRECRAWL_API_KEY")
DEFAULT_OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
def main():
st.set_page_config(
page_title="AI Real Estate Agent Team",
page_icon="🏠",
layout="wide",
initial_sidebar_state="expanded"
)
# Clean header
st.title("🏠 AI Real Estate Agent Team")
st.caption("Find Your Dream Home with Specialized AI Agents")
# Sidebar configuration
with st.sidebar:
st.header("⚙️ Configuration")
# Website selection
with st.expander("🌐 Search Sources", expanded=True):
st.markdown("**Select real estate websites to search:**")
available_websites = ["Zillow", "Realtor.com", "Trulia", "Homes.com"]
selected_websites = [site for site in available_websites if st.checkbox(site, value=site in ["Zillow", "Realtor.com"])]
if selected_websites:
st.markdown(f'✅ {len(selected_websites)} sources selected</div>', unsafe_allow_html=True)
else:
st.markdown('<div class="status-error">⚠️ Please select at least one website</div>', unsafe_allow_html=True)
# How it works
with st.expander("🤖 How It Works", expanded=False):
st.markdown("**🔍 Property Search Agent**")
st.markdown("Uses direct Firecrawl integration to find properties")
st.markdown("**📊 Market Analysis Agent**")
st.markdown("Analyzes market trends and neighborhood insights")
st.markdown("**💰 Property Valuation Agent**")
st.markdown("Evaluates properties and provides investment analysis")
# Main form
st.header("Your Property Requirements")
st.info("Please provide the location, budget, and property details to help us find your ideal home.")
with st.form("property_preferences"):
# Location and Budget Section
st.markdown("### 📍 Location & Budget")
col1, col2 = st.columns(2)
with col1:
city = st.text_input(
"🏙️ City",
placeholder="e.g., San Francisco",
help="Enter the city where you want to buy property"
)
state = st.text_input(
"🗺️ State/Province (optional)",
placeholder="e.g., CA",
help="Enter the state or province (optional)"
)
with col2:
min_price = st.number_input(
"💰 Minimum Price ($)",
min_value=0,
value=500000,
step=50000,
help="Your minimum budget for the property"
)
max_price = st.number_input(
"💰 Maximum Price ($)",
min_value=0,
value=1500000,
step=50000,
help="Your maximum budget for the property"
)
# Property Details Section
st.markdown("### 🏡 Property Details")
col1, col2, col3 = st.columns(3)
with col1:
property_type = st.selectbox(
"🏠 Property Type",
["Any", "House", "Condo", "Townhouse", "Apartment"],
help="Type of property you're looking for"
)
bedrooms = st.selectbox(
"🛏️ Bedrooms",
["Any", "1", "2", "3", "4", "5+"],
help="Number of bedrooms required"
)
with col2:
bathrooms = st.selectbox(
"🚿 Bathrooms",
["Any", "1", "1.5", "2", "2.5", "3", "3.5", "4+"],
help="Number of bathrooms required"
)
min_sqft = st.number_input(
"📏 Minimum Square Feet",
min_value=0,
value=1000,
step=100,
help="Minimum square footage required"
)
with col3:
timeline = st.selectbox(
"⏰ Timeline",
["Flexible", "1-3 months", "3-6 months", "6+ months"],
help="When do you plan to buy?"
)
urgency = st.selectbox(
"🚨 Urgency",
["Not urgent", "Somewhat urgent", "Very urgent"],
help="How urgent is your purchase?"
)
# Special Features
st.markdown("### ✨ Special Features")
special_features = st.text_area(
"🎯 Special Features & Requirements",
placeholder="e.g., Parking, Yard, View, Near public transport, Good schools, Walkable neighborhood, etc.",
help="Any specific features or requirements you're looking for"
)
# Submit button with custom styling
col1, col2, col3 = st.columns([1, 2, 1])
with col2:
submitted = st.form_submit_button(
"🚀 Start Property Analysis",
type="primary",
use_container_width=True
)
# Process form submission
if submitted:
# Validate all required inputs
missing_items = []
if not city:
missing_items.append("City")
if not selected_websites:
missing_items.append("At least one website selection")
if missing_items:
st.markdown(f"""
<div class="status-error" style="text-align: center; margin: 2rem 0;">
⚠️ Please provide: {', '.join(missing_items)}
</div>
""", unsafe_allow_html=True)
return
try:
user_criteria = {
'budget_range': f"${min_price:,} - ${max_price:,}",
'property_type': property_type,
'bedrooms': bedrooms,
'bathrooms': bathrooms,
'min_sqft': min_sqft,
'special_features': special_features if special_features else 'None specified'
}
except Exception as e:
st.markdown(f"""
<div class="status-error" style="text-align: center; margin: 2rem 0;">
❌ Error initializing: {str(e)}
</div>
""", unsafe_allow_html=True)
return
# Display progress
st.markdown("#### Property Analysis in Progress")
st.info("AI Agents are searching for your perfect home...")
status_container = st.container()
with status_container:
st.markdown("### 📊 Current Activity")
progress_bar = st.progress(0)
current_activity = st.empty()
def update_progress(progress, status, activity=None):
if activity:
progress_bar.progress(progress)
current_activity.text(activity)
try:
start_time = time.time()
update_progress(0.1, "Initializing...", "Starting sequential property analysis")
# Run sequential analysis with manual coordination
final_result = run_sequential_analysis(
city=city,
state=state,
user_criteria=user_criteria,
selected_websites=selected_websites,
firecrawl_api_key=DEFAULT_FIRECRAWL_API_KEY,
openai_api_key=DEFAULT_OPENAI_API_KEY,
update_callback=update_progress
)
total_time = time.time() - start_time
# Display results
if isinstance(final_result, dict):
# Use the new professional display
display_properties_professionally(
final_result['properties'],
final_result['market_analysis'],
final_result['property_valuations'],
final_result['total_properties']
)
else:
# Fallback to markdown display
st.markdown("### 🏠 Comprehensive Real Estate Analysis")
st.markdown(final_result)
# Timing info in a subtle way
st.caption(f"Analysis completed in {total_time:.1f}s")
except Exception as e:
st.markdown(f"""
<div class="status-error" style="text-align: center; margin: 2rem 0;">
❌ An error occurred: {str(e)}
</div>
""", unsafe_allow_html=True)
if __name__ == "__main__":
main()