Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,41 +1,82 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import openai
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import openai
|
| 3 |
+
import os
|
| 4 |
+
import folium
|
| 5 |
+
from streamlit_folium import st_folium
|
| 6 |
|
| 7 |
+
# Ensure your OpenAI API key is set in your environment variables
|
| 8 |
+
openai.api_key = os.environ["OPENAI_API_KEY"]
|
| 9 |
+
|
| 10 |
+
initial_messages = [{
|
| 11 |
+
"role": "system",
|
| 12 |
+
"content": """
|
| 13 |
+
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. Provide a short description for each neighborhood, including key features such as nearby amenities, atmosphere, and suitability for the user's preferences.
|
| 14 |
+
"""
|
| 15 |
+
}]
|
| 16 |
+
|
| 17 |
+
def call_openai_api(messages):
|
| 18 |
+
return openai.ChatCompletion.create(
|
| 19 |
+
model="gpt-3.5-turbo",
|
| 20 |
+
messages=messages
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
def CustomChatGPT(preferences, messages):
|
| 24 |
+
query = f"User preferences: {preferences}. Suggest suitable neighborhoods."
|
| 25 |
+
messages.append({"role": "user", "content": query})
|
| 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 |
+
# Set layout to wide
|
| 32 |
+
st.set_page_config(layout="wide")
|
| 33 |
+
|
| 34 |
+
# Centered title
|
| 35 |
+
st.markdown("<h1 style='text-align: center; color: black;'>Neighborhood Matchmaker</h1>", unsafe_allow_html=True)
|
| 36 |
+
|
| 37 |
+
# Create columns for input and output
|
| 38 |
+
col1, col2 = st.columns(2)
|
| 39 |
+
|
| 40 |
+
with col1:
|
| 41 |
+
st.markdown("<h2 style='text-align: center; color: black;'>Your Preferences</h2>", unsafe_allow_html=True)
|
| 42 |
+
preferences = st.text_area("Describe your ideal neighborhood", placeholder="E.g., family-friendly, good schools, near parks, vibrant nightlife, public transportation, etc.")
|
| 43 |
+
generate_button = st.button('Find Neighborhoods')
|
| 44 |
+
|
| 45 |
+
with col2:
|
| 46 |
+
st.markdown("<h2 style='text-align: center; color: black;'>Recommended Neighborhoods ⬇️</h2>", unsafe_allow_html=True)
|
| 47 |
+
if generate_button:
|
| 48 |
+
messages = initial_messages.copy()
|
| 49 |
+
reply, _ = CustomChatGPT(preferences, messages)
|
| 50 |
+
st.write(reply)
|
| 51 |
+
|
| 52 |
+
# Add map integration
|
| 53 |
+
st.markdown("<h2 style='text-align: center; color: black;'>Map of Suggested Neighborhoods ⬇️</h2>", unsafe_allow_html=True)
|
| 54 |
+
map_center = [37.7749, -122.4194] # Default to San Francisco coordinates
|
| 55 |
+
m = folium.Map(location=map_center, zoom_start=12)
|
| 56 |
+
|
| 57 |
+
# Placeholder coordinates for neighborhoods (these should be updated with actual data)
|
| 58 |
+
neighborhoods = [
|
| 59 |
+
{"name": "Neighborhood 1", "coordinates": [37.7749, -122.4194]},
|
| 60 |
+
{"name": "Neighborhood 2", "coordinates": [37.7849, -122.4094]},
|
| 61 |
+
{"name": "Neighborhood 3", "coordinates": [37.7649, -122.4294]}
|
| 62 |
+
]
|
| 63 |
+
|
| 64 |
+
for neighborhood in neighborhoods:
|
| 65 |
+
folium.Marker(
|
| 66 |
+
location=neighborhood["coordinates"],
|
| 67 |
+
popup=neighborhood["name"],
|
| 68 |
+
icon=folium.Icon(color='blue')
|
| 69 |
+
).add_to(m)
|
| 70 |
+
|
| 71 |
+
st_folium(m, width=700, height=500)
|
| 72 |
+
|
| 73 |
+
# Contact capture form
|
| 74 |
+
st.markdown("<h2 style='text-align: center; color: black;'>Get in Touch for More Details ⬇️</h2>", unsafe_allow_html=True)
|
| 75 |
+
with st.form(key='contact_form'):
|
| 76 |
+
name = st.text_input("Your Name", placeholder="Enter your name")
|
| 77 |
+
email = st.text_input("Your Email", placeholder="Enter your email address")
|
| 78 |
+
message = st.text_area("Your Message", placeholder="Let us know how we can assist you further")
|
| 79 |
+
submit_button = st.form_submit_button(label='Submit')
|
| 80 |
+
|
| 81 |
+
if submit_button:
|
| 82 |
+
st.success("Thank you for getting in touch! We'll get back to you shortly.")
|