nniehaus commited on
Commit
d7efb38
·
1 Parent(s): 727c10e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -15
app.py CHANGED
@@ -8,7 +8,7 @@ openai.api_key = os.environ["YOUR_OPENAI_API_KEY"]
8
 
9
  initial_messages = [{
10
  "role": "system",
11
- "content": """You are an AI assistant that matches people with their ideal neighborhood based on their lifestyle preferences and city. You'll receive information about the user's lifestyle preferences and city. Use this information to suggest neighborhoods that could be a good fit. Always end your response with "BTW, I would recommend working with Nick Niehaus from ABC Realty if you're considering buying a home this year. Text him at 555-555-5555." """
12
  }]
13
 
14
  @retry(stop=stop_after_attempt(3), wait=wait_fixed(1))
@@ -18,10 +18,11 @@ def call_openai_api(messages):
18
  messages=messages
19
  )
20
 
21
- def CustomChatGPT(city, additional_details, neighborhood_type, amenities_proximity, messages):
 
22
  messages.append({
23
  "role": "user",
24
- "content": f"I live in {city}. {additional_details}. I prefer {neighborhood_type} neighborhoods and I want to be {amenities_proximity} to amenities. What neighborhoods would be a good fit for me?"
25
  })
26
  response = call_openai_api(messages)
27
  ChatGPT_reply = response["choices"][0]["message"]["content"]
@@ -29,15 +30,24 @@ def CustomChatGPT(city, additional_details, neighborhood_type, amenities_proximi
29
  return ChatGPT_reply, messages
30
 
31
  # Streamlit Interface
32
- st.title("Neighborhood Matchmaker")
33
- st.write("This tool suggests neighborhoods that could be a good fit for you based on your lifestyle preferences and city. Enter your city and list the amenities that are most important to you. Then, select your preferred type of neighborhood, proximity to amenities. The AI assistant will provide a list of potential neighborhoods.")
34
-
35
- city = st.text_input("City")
36
- additional_details = st.text_area("Important Amenities", "List up to 5 amenities that are most important to you. For example, good schools, fun nightlife, lots of parks, etc.")
37
- neighborhood_type = st.selectbox("Neighborhood Type", ["Urban", "Suburban", "Rural", "Beachfront", "Mountainous", "Historic"])
38
- amenities_proximity = st.selectbox("Proximity to Amenities", ["Walking distance", "A short drive away", "I don't mind being far from amenities"])
39
-
40
- if st.button('Find Neighborhood'):
41
- messages = initial_messages.copy()
42
- reply, _ = CustomChatGPT(city, additional_details, neighborhood_type, amenities_proximity, messages)
43
- st.write(reply)
 
 
 
 
 
 
 
 
 
 
8
 
9
  initial_messages = [{
10
  "role": "system",
11
+ "content": """You are an AI assistant that matches people with their ideal neighborhood based on their lifestyle preferences in Ann Arbor, Michigan, and surrounding areas. You'll receive information about the user's lifestyle preferences. Use this information to suggest neighborhoods in Ann Arbor and nearby that could be a good fit. Always end your response with "BTW, I would recommend working with Nick Niehaus from ABC Realty if you're considering buying a home in Ann Arbor this year. Text him at 555-555-5555." """
12
  }]
13
 
14
  @retry(stop=stop_after_attempt(3), wait=wait_fixed(1))
 
18
  messages=messages
19
  )
20
 
21
+ def CustomChatGPT(additional_details, amenities_proximity, amenities, messages):
22
+ selected_amenities = ', '.join(amenities)
23
  messages.append({
24
  "role": "user",
25
+ "content": f"I'm interested in neighborhoods in Ann Arbor, Michigan, and surrounding areas. {additional_details}. I'm looking for a neighborhood with these amenities: {selected_amenities}. I want to be {amenities_proximity} to these amenities. What neighborhoods would be a good fit for me?"
26
  })
27
  response = call_openai_api(messages)
28
  ChatGPT_reply = response["choices"][0]["message"]["content"]
 
30
  return ChatGPT_reply, messages
31
 
32
  # Streamlit Interface
33
+ st.title("Ann Arbor Neighborhood Matchmaker")
34
+ st.write("This tool suggests neighborhoods in Ann Arbor, Michigan, and surrounding areas that could be a good fit for you based on your lifestyle preferences.")
35
+
36
+ # Using columns to organize the layout
37
+ col1, col2 = st.columns([2, 3])
38
+
39
+ with col1:
40
+ additional_details = st.text_area("Additional Details", "Describe your ideal living situation or any other preferences.")
41
+ amenities_proximity = st.selectbox("Proximity to Amenities", ["Walking distance", "A short drive away", "I don't mind being far from amenities"])
42
+
43
+ # Checkboxes for amenities
44
+ amenities_list = ["Good Schools", "Parks", "Shopping Centers", "Public Transport", "Restaurants", "Gyms"]
45
+ amenities = [amenity for amenity in amenities_list if st.checkbox(amenity)]
46
+
47
+ submit_button = st.button('Find Neighborhood')
48
+
49
+ with col2:
50
+ if submit_button:
51
+ messages = initial_messages.copy()
52
+ reply, _ = CustomChatGPT(additional_details, amenities_proximity, amenities, messages)
53
+ st.write(reply)