|
import streamlit as st |
|
import openai |
|
import urllib.parse |
|
|
|
|
|
openai.api_key = os.environ["OPENAI_API_KEY"] |
|
|
|
|
|
def suggest_neighborhoods(user_preferences, city=""): |
|
prompt = (f"Based on the following preferences, suggest neighborhoods in {city}: {user_preferences}. " |
|
"For each neighborhood, provide a brief description including its main attractions and why it would suit these preferences.") |
|
response = openai.Completion.create( |
|
model="gpt-3.5-turbo", |
|
prompt=prompt, |
|
max_tokens=150 |
|
) |
|
return response.choices[0].text.strip() |
|
|
|
|
|
def generate_zillow_link(neighborhood): |
|
neighborhood_query = urllib.parse.quote(neighborhood) |
|
return f"https://www.zillow.com/homes/{neighborhood_query}_rb/" |
|
|
|
|
|
st.title("Ideal Neighborhood Finder") |
|
st.write("Describe what you're looking for in an ideal neighborhood, and we'll suggest neighborhoods with Zillow links for homes in those areas.") |
|
|
|
|
|
city = st.text_input("City", placeholder="Enter the city you want to search in") |
|
user_preferences = st.text_area("Describe Your Ideal Neighborhood", placeholder="E.g., close to schools, parks, public transit, vibrant nightlife, etc.") |
|
|
|
if st.button("Find Neighborhoods"): |
|
if city and user_preferences: |
|
|
|
neighborhoods = suggest_neighborhoods(user_preferences, city) |
|
|
|
|
|
st.subheader("Neighborhood Suggestions") |
|
for neighborhood in neighborhoods.splitlines(): |
|
if neighborhood: |
|
zillow_link = generate_zillow_link(neighborhood) |
|
st.markdown(f"- **{neighborhood}**: [View homes on Zillow]({zillow_link})") |
|
else: |
|
st.error("Please provide both a city and a description of your ideal neighborhood.") |
|
|