nniehaus commited on
Commit
830f5f1
·
verified ·
1 Parent(s): 8d8822e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -14
app.py CHANGED
@@ -30,6 +30,10 @@ def CustomChatGPT(city, preferences, messages):
30
  # Streamlit setup
31
  st.set_page_config(layout="wide")
32
 
 
 
 
 
33
  # Centered title
34
  st.markdown("<h1 style='text-align: center; color: black;'>Ideal Neighborhood Finder</h1>", unsafe_allow_html=True)
35
 
@@ -45,16 +49,17 @@ with col1:
45
  # Process results on button click
46
  if generate_button and city and preferences:
47
  messages = initial_messages.copy()
48
- reply, _ = CustomChatGPT(city, preferences, messages)
49
-
50
- # Display the results
 
51
  with col2:
52
  st.markdown("<h2 style='text-align: center; color: black;'>Recommended Neighborhoods ⬇️</h2>", unsafe_allow_html=True)
53
- st.write(reply)
54
 
55
  # Extract neighborhood, city, and state information
56
  neighborhoods = []
57
- for line in reply.splitlines():
58
  if ":" in line:
59
  location = line.split(":")[0].strip() # Full location "Neighborhood, City, State"
60
  # Remove any leading numbering
@@ -62,16 +67,11 @@ if generate_button and city and preferences:
62
  location = location.split(" ", 1)[1].strip()
63
  neighborhoods.append(location)
64
 
65
- # Display Zillow links, focusing on city and state first, then adding neighborhood if needed
66
  st.markdown("### Zillow Search Links")
67
  for location in neighborhoods:
68
- # Simplify the search query to prevent Zillow from returning specific listings
69
- city_state_query = urllib.parse.quote(f"{city}, {location.split(',')[-1].strip()}")
70
- zillow_url = f"https://www.zillow.com/homes/{city_state_query}_rb/"
71
-
72
- # Add neighborhood to query if broader city/state search isn't suitable
73
- if city.lower() not in location.lower():
74
- location_query = urllib.parse.quote(location)
75
- zillow_url = f"https://www.zillow.com/homes/{location_query}_rb/"
76
 
77
  st.markdown(f"- [Search for homes in {location} on Zillow]({zillow_url})")
 
30
  # Streamlit setup
31
  st.set_page_config(layout="wide")
32
 
33
+ # Initialize session state for storing the API reply
34
+ if "reply" not in st.session_state:
35
+ st.session_state["reply"] = None
36
+
37
  # Centered title
38
  st.markdown("<h1 style='text-align: center; color: black;'>Ideal Neighborhood Finder</h1>", unsafe_allow_html=True)
39
 
 
49
  # Process results on button click
50
  if generate_button and city and preferences:
51
  messages = initial_messages.copy()
52
+ st.session_state["reply"], _ = CustomChatGPT(city, preferences, messages) # Store response in session state
53
+
54
+ # Display results if there is a reply in session state
55
+ if st.session_state["reply"]:
56
  with col2:
57
  st.markdown("<h2 style='text-align: center; color: black;'>Recommended Neighborhoods ⬇️</h2>", unsafe_allow_html=True)
58
+ st.write(st.session_state["reply"])
59
 
60
  # Extract neighborhood, city, and state information
61
  neighborhoods = []
62
+ for line in st.session_state["reply"].splitlines():
63
  if ":" in line:
64
  location = line.split(":")[0].strip() # Full location "Neighborhood, City, State"
65
  # Remove any leading numbering
 
67
  location = location.split(" ", 1)[1].strip()
68
  neighborhoods.append(location)
69
 
70
+ # Display Zillow links, ensuring neighborhood and city are included in each URL
71
  st.markdown("### Zillow Search Links")
72
  for location in neighborhoods:
73
+ # Ensure format "Neighborhood, City, State" for the search query
74
+ full_location_query = urllib.parse.quote(location)
75
+ zillow_url = f"https://www.zillow.com/homes/{full_location_query}_rb/"
 
 
 
 
 
76
 
77
  st.markdown(f"- [Search for homes in {location} on Zillow]({zillow_url})")