nniehaus commited on
Commit
6771851
1 Parent(s): 136ee63

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -26
app.py CHANGED
@@ -1,33 +1,43 @@
 
1
  import streamlit as st
 
 
2
 
3
- # Sample database of neighborhoods (replace with real data)
4
- neighborhood_data = {
5
- 'Neighborhood A': {'price_range': (300000, 500000), 'amenities': {'school': 2, 'park': 5}, 'distance': 10},
6
- 'Neighborhood B': {'price_range': (200000, 400000), 'amenities': {'school': 5, 'supermarket': 3}, 'distance': 5},
7
- # Add more neighborhoods...
8
- }
9
 
10
- def match_neighborhoods(price_range, amenities, max_distance):
11
- matches = []
12
- for name, data in neighborhood_data.items():
13
- if data['price_range'][0] <= price_range[1] and data['price_range'][1] >= price_range[0]:
14
- if all(amenity in data['amenities'] and data['amenities'][amenity] <= max_distance for amenity in amenities):
15
- matches.append(name)
16
- return matches
17
 
18
- st.title('Neighborhood Matchmaker')
 
 
 
 
 
19
 
20
- min_price, max_price = st.slider("Select your price range", 100000, 1000000, (200000, 500000))
21
- selected_amenities = st.multiselect("Select desired amenities", ['school', 'park', 'supermarket', 'public transport'])
22
- max_distance = st.selectbox("Maximum distance to amenities (in miles)", [1, 2, 5, 10, 20])
 
 
 
 
 
 
23
 
24
- if st.button('Find Match'):
25
- matches = match_neighborhoods((min_price, max_price), selected_amenities, max_distance)
26
- if matches:
27
- st.write('Matching Neighborhoods:')
28
- for match in matches:
29
- st.write(match)
30
- else:
31
- st.write('No matches found. Try adjusting your criteria.')
32
 
33
- # Remember to handle user data responsibly.
 
 
 
 
 
 
 
 
 
1
+ import openai
2
  import streamlit as st
3
+ import os
4
+ from tenacity import retry, stop_after_attempt, wait_fixed
5
 
6
+ # Set the OpenAI API key
7
+ openai.api_key = os.environ["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))
15
+ def call_openai_api(messages):
16
+ return openai.ChatCompletion.create(
17
+ model="gpt-4",
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"]
28
+ messages.append({"role": "assistant", "content": ChatGPT_reply})
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)