nniehaus commited on
Commit
9e199d2
·
verified ·
1 Parent(s): c138cb1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -13
app.py CHANGED
@@ -9,7 +9,7 @@ openai.api_key = os.environ["OPENAI_API_KEY"]
9
  initial_messages = [{
10
  "role": "system",
11
  "content": """
12
- You are a neighborhood matchmaker. Given a person's preferences in terms of amenities, lifestyle, and priorities, suggest three neighborhoods that best match their needs in a specified city. Provide a short description of each neighborhood, highlighting its unique qualities.
13
  """
14
  }]
15
 
@@ -20,7 +20,7 @@ def call_openai_api(messages):
20
  )
21
 
22
  def CustomChatGPT(city, preferences, messages):
23
- query = f"User is looking for neighborhoods in {city} with these preferences: {preferences}. Suggest suitable neighborhoods and describe each briefly."
24
  messages.append({"role": "user", "content": query})
25
  response = call_openai_api(messages)
26
  ChatGPT_reply = response["choices"][0]["message"]["content"]
@@ -52,20 +52,16 @@ if generate_button and city and preferences:
52
  st.markdown("<h2 style='text-align: center; color: black;'>Recommended Neighborhoods ⬇️</h2>", unsafe_allow_html=True)
53
  st.write(reply)
54
 
55
- # Extract and clean neighborhood names
56
  neighborhoods = []
57
  for line in reply.splitlines():
58
  if ":" in line:
59
- neighborhood = line.split(":")[0].strip()
60
- neighborhoods.append(neighborhood)
61
-
62
- # Format city correctly for Zillow URLs
63
- city_formatted = urllib.parse.quote(city.strip().title())
64
 
65
  # Display Zillow links
66
  st.markdown("### Zillow Search Links")
67
- for neighborhood in neighborhoods:
68
- neighborhood_query = urllib.parse.quote(f"{neighborhood}, {city_formatted}")
69
- zillow_url = f"https://www.zillow.com/homes/{neighborhood_query}_rb/"
70
- st.markdown(f"- [Search for homes in {neighborhood}, {city} on Zillow]({zillow_url})")
71
-
 
9
  initial_messages = [{
10
  "role": "system",
11
  "content": """
12
+ You are a neighborhood matchmaker. Given a person's preferences in terms of amenities, lifestyle, and priorities, suggest three neighborhoods that best match their needs in a specified city. For each neighborhood, include the full location in the format: Neighborhood, City, State, and provide a short description highlighting its unique qualities.
13
  """
14
  }]
15
 
 
20
  )
21
 
22
  def CustomChatGPT(city, preferences, messages):
23
+ query = f"User is looking for neighborhoods in {city} with these preferences: {preferences}. Suggest suitable neighborhoods and describe each briefly, including the full location as Neighborhood, City, State."
24
  messages.append({"role": "user", "content": query})
25
  response = call_openai_api(messages)
26
  ChatGPT_reply = response["choices"][0]["message"]["content"]
 
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
+ neighborhoods.append(location)
 
 
 
61
 
62
  # Display Zillow links
63
  st.markdown("### Zillow Search Links")
64
+ for location in neighborhoods:
65
+ location_query = urllib.parse.quote(location)
66
+ zillow_url = f"https://www.zillow.com/homes/{location_query}_rb/"
67
+ st.markdown(f"- [Search for homes in {location} on Zillow]({zillow_url})")