Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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
|
| 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(
|
|
|
|
| 22 |
messages.append({
|
| 23 |
"role": "user",
|
| 24 |
-
"content": f"I
|
| 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
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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)
|