agentify-demo / app.py
Daniel Alvarez Echenagucia
menu fix
ba0a7b0
Raw History Blame Contribute Delete
9.25 kB
import streamlit as st
import requests
from utils import display_agent_results
from config import API_URL, PROPERTY_TYPES, FL_CITIES
# Configure the page with a clean, focused layout
st.set_page_config(
page_title="FL Real Estate Agent Recommender",
page_icon="🏠",
layout="wide",
# Hide the default menu to create a cleaner interface
menu_items={"Get Help": None, "Report a bug": None, "About": None},
)
# Hide Streamlit's default elements using custom CSS
hide_streamlit_style = """
<style>
#MainMenu {visibility: hidden;}
footer {visibility: hidden;}
.stDeployButton {display:none;}
</style>
"""
st.markdown(hide_streamlit_style, unsafe_allow_html=True)
def selling_agents_form():
"""Form for finding selling agents"""
st.header("🏑 Find Selling Agents")
with st.form("selling_form"):
st.info("Complete the property address below to find matching agents.")
# Required Address Section
st.subheader("Property Address")
col1, col2, col3 = st.columns(3)
street_number = col1.text_input("Street Number *", placeholder="123")
street_name = col2.text_input("Street Name *", placeholder="Main St")
unit = col3.text_input("Unit Number (Optional)", placeholder="4B")
col1, col2 = st.columns(2)
city = col1.selectbox("City *", options=FL_CITIES)
postal_code = col2.text_input("ZIP Code *", placeholder="33101")
# Optional Property Details
with st.expander("Property Details (Optional)"):
with st.container():
# Features object structure
col1, col2 = st.columns(2)
bedrooms = col1.number_input("Bedrooms", min_value=0, max_value=10)
bathrooms = col2.number_input("Bathrooms", min_value=0, max_value=10)
col1, col2 = st.columns(2)
property_type = col1.selectbox("Property Type", options=PROPERTY_TYPES)
living_area = col2.number_input("Living Area (sq ft)", min_value=0)
col1, col2 = st.columns(2)
year_built = col1.number_input(
"Year Built", min_value=1900, max_value=2024
)
lot_size = col2.number_input(
"Lot Size (acres)", min_value=0.0, step=0.1
)
col1, col2, col3 = st.columns(3)
waterfront = col1.checkbox("Waterfront Property")
association = col2.checkbox("Has Association")
new_construction = col3.checkbox("New Construction")
if association:
association_fee = st.number_input(
"Association Fee ($)", min_value=0
)
submitted = st.form_submit_button("Find Selling Agents")
if submitted:
if not all([street_number, street_name, city, postal_code]):
st.error("Please fill in all required address fields.")
return
# Construct request payload
payload = {
"Address": {
"StreetNumber": street_number,
"StreetName": street_name,
"City": city,
"StateOrProvince": "FL",
"PostalCode": postal_code,
"UnitNumber": unit if unit else None,
},
"Features": {
"BedroomsTotal": bedrooms if bedrooms > 0 else None,
"BathroomsTotalInteger": bathrooms if bathrooms > 0 else None,
"PropertyType": property_type,
"LivingArea": living_area if living_area > 0 else None,
"YearBuilt": year_built if year_built > 1900 else None,
"LotSizeAcres": lot_size if lot_size > 0 else None,
"WaterfrontYN": waterfront,
"AssociationYN": association,
"NewConstructionYN": new_construction,
"AssociationFee": (
association_fee
if association and "association_fee" in locals()
else None
),
},
}
try:
with st.spinner("Finding the best agents..."):
response = requests.post(
f"{API_URL}/recommend-selling-agents", json=payload
)
if response.status_code == 200:
display_agent_results(response.json(), "selling")
else:
st.error(f"{API_URL}/recommend-selling-agents")
st.error(f"Error: {response.text}")
except Exception as e:
st.error(f"Failed to get recommendations: {str(e)}")
def buying_agents_form():
"""Form for finding buying agents"""
st.header("πŸ” Find Buying Agents")
with st.form("buying_form"):
st.info("Specify your minimum requirements to find matching agents.")
# Required Fields
st.subheader("Required Preferences")
col1, col2 = st.columns(2)
min_beds = col1.number_input(
"Minimum Bedrooms *", min_value=1, max_value=10, value=3
)
min_baths = col2.number_input(
"Minimum Bathrooms *", min_value=1, max_value=10, value=2
)
# Optional Fields
st.subheader("Additional Preferences")
# Location Preferences
preferred_cities = st.multiselect("Preferred Cities", options=FL_CITIES)
postal_codes = st.text_input(
"Preferred ZIP Codes (comma-separated)",
placeholder="33101, 33139",
help="Enter ZIP codes separated by commas",
)
# Price Range
col1, col2 = st.columns(2)
min_price = col1.number_input("Minimum Price ($)", min_value=0, step=50000)
max_price = col2.number_input("Maximum Price ($)", min_value=0, step=50000)
# Property Details
with st.expander("More Preferences (Optional)"):
col1, col2 = st.columns(2)
property_type = col1.selectbox("Property Type", options=PROPERTY_TYPES)
min_area = col2.number_input("Minimum Living Area (sq ft)", min_value=0)
col1, col2, col3 = st.columns(3)
waterfront = col1.checkbox("Waterfront Preferred")
accept_hoa = col2.checkbox("Accept HOA")
new_only = col3.checkbox("New Construction Only")
if accept_hoa:
max_hoa = st.number_input("Maximum HOA Fee ($)", min_value=0)
submitted = st.form_submit_button("Find Buying Agents")
if submitted:
# Validate required fields
if min_beds < 1 or min_baths < 1:
st.error("Please specify minimum bedrooms and bathrooms.")
return
# Construct request payload
payload = {
"MinBedroomsTotal": min_beds,
"MinBathroomsTotalInteger": min_baths,
"StateOrProvince": "FL",
}
# Add optional fields
if min_price > 0:
payload["MinPrice"] = min_price
if max_price > 0 and max_price > min_price:
payload["MaxPrice"] = max_price
if preferred_cities:
payload["PreferredCities"] = preferred_cities
if postal_codes:
payload["PreferredPostalCodes"] = [
code.strip() for code in postal_codes.split(",")
]
if property_type:
payload["PropertyType"] = property_type
if min_area > 0:
payload["MinLivingArea"] = min_area
if waterfront:
payload["WaterfrontPreferred"] = True
if accept_hoa:
payload["AcceptHOA"] = True
if "max_hoa" in locals() and max_hoa > 0:
payload["MaxHOAFee"] = max_hoa
if new_only:
payload["NewConstructionOnly"] = True
try:
with st.spinner("Finding the best agents..."):
response = requests.post(
f"{API_URL}/recommend-buying-agents", json=payload
)
if response.status_code == 200:
display_agent_results(response.json(), "buying")
else:
st.error(f"Error: {response.text}")
except Exception as e:
st.error(f"Failed to get recommendations: {str(e)}")
def main():
st.title("🏠 Florida Real Estate Agent Recommender")
st.write(
"""
Find the perfect real estate agent for your needs using our AI-powered recommendation system.
Whether you're buying or selling, we'll match you with top-performing agents in your area.
"""
)
# Create tabs for buying and selling
tab1, tab2 = st.tabs(["Find Selling Agents", "Find Buying Agents"])
with tab1:
selling_agents_form()
with tab2:
buying_agents_form()
if __name__ == "__main__":
main()