Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,27 +4,28 @@ import openai
|
|
| 4 |
# Access the OpenAI API key from environment variables or secrets
|
| 5 |
openai.api_key = st.secrets["OPENAI_API_KEY"]
|
| 6 |
|
| 7 |
-
st.title("
|
| 8 |
|
| 9 |
# User inputs
|
| 10 |
st.subheader("About You")
|
| 11 |
-
age = st.number_input("Your Age", min_value=
|
| 12 |
-
|
| 13 |
|
| 14 |
-
st.subheader("
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
|
| 19 |
-
st.subheader("Your
|
| 20 |
-
|
| 21 |
-
|
| 22 |
|
| 23 |
-
if st.button('
|
| 24 |
# Construct the prompt for the AI
|
| 25 |
prompt_text = (
|
| 26 |
-
f"
|
| 27 |
-
f"
|
|
|
|
| 28 |
)
|
| 29 |
|
| 30 |
# Call the OpenAI API for text generation
|
|
@@ -32,17 +33,17 @@ if st.button('Generate My Fitness Plan'):
|
|
| 32 |
response_text = openai.ChatCompletion.create(
|
| 33 |
model="gpt-4",
|
| 34 |
messages=[
|
| 35 |
-
{"role": "system", "content": "You are an AI
|
| 36 |
{"role": "user", "content": prompt_text}
|
| 37 |
]
|
| 38 |
)
|
| 39 |
-
|
| 40 |
except Exception as e:
|
| 41 |
-
|
| 42 |
|
| 43 |
-
# Display the
|
| 44 |
-
st.markdown("### Your
|
| 45 |
-
st.write(
|
| 46 |
|
| 47 |
# Disclaimer
|
| 48 |
-
st.write("Disclaimer: This tool provides suggestions based on AI-generated content. Please
|
|
|
|
| 4 |
# Access the OpenAI API key from environment variables or secrets
|
| 5 |
openai.api_key = st.secrets["OPENAI_API_KEY"]
|
| 6 |
|
| 7 |
+
st.title("Find Your Ideal Neighborhood")
|
| 8 |
|
| 9 |
# User inputs
|
| 10 |
st.subheader("About You")
|
| 11 |
+
age = st.number_input("Your Age", min_value=18, max_value=100, step=1)
|
| 12 |
+
occupation = st.text_input("Your Occupation", placeholder="e.g., Software Developer, Teacher")
|
| 13 |
|
| 14 |
+
st.subheader("Lifestyle and Preferences")
|
| 15 |
+
preferred_climate = st.selectbox("Preferred Climate", ["Warm", "Temperate", "Cold"])
|
| 16 |
+
interests = st.text_area("Interests", placeholder="e.g., Outdoor activities, Arts and culture, Nightlife")
|
| 17 |
+
housing_budget = st.number_input("Housing Budget", min_value=500, max_value=10000, step=100, format="$%i")
|
| 18 |
|
| 19 |
+
st.subheader("Your Ideal Neighborhood")
|
| 20 |
+
neighborhood_preferences = st.multiselect("Select Your Neighborhood Preferences", ["Safe", "Family-friendly", "Vibrant nightlife", "Quiet", "Pet-friendly", "Close to nature", "Urban"])
|
| 21 |
+
commute_preference = st.selectbox("Preferred Commute Time", ["Less than 15 minutes", "15-30 minutes", "30-60 minutes", "More than an hour"])
|
| 22 |
|
| 23 |
+
if st.button('Find My Ideal Neighborhood'):
|
| 24 |
# Construct the prompt for the AI
|
| 25 |
prompt_text = (
|
| 26 |
+
f"Find an ideal neighborhood for the user, a {age}-year-old working as {occupation}. "
|
| 27 |
+
f"Preferred climate: {preferred_climate}. Interests: {interests}. Housing budget: {housing_budget}. "
|
| 28 |
+
f"Neighborhood preferences: {', '.join(neighborhood_preferences)} with a preferred commute time of {commute_preference}."
|
| 29 |
)
|
| 30 |
|
| 31 |
# Call the OpenAI API for text generation
|
|
|
|
| 33 |
response_text = openai.ChatCompletion.create(
|
| 34 |
model="gpt-4",
|
| 35 |
messages=[
|
| 36 |
+
{"role": "system", "content": "You are an AI specializing in neighborhood recommendations."},
|
| 37 |
{"role": "user", "content": prompt_text}
|
| 38 |
]
|
| 39 |
)
|
| 40 |
+
neighborhood_recommendation = response_text.choices[0].message['content']
|
| 41 |
except Exception as e:
|
| 42 |
+
neighborhood_recommendation = f"Error in finding ideal neighborhood: {e}"
|
| 43 |
|
| 44 |
+
# Display the neighborhood recommendation
|
| 45 |
+
st.markdown("### Your Ideal Neighborhood Recommendation")
|
| 46 |
+
st.write(neighborhood_recommendation)
|
| 47 |
|
| 48 |
# Disclaimer
|
| 49 |
+
st.write("Disclaimer: This tool provides suggestions based on AI-generated content. Please ensure to conduct your own research or consult with a real estate professional before making any decisions.")
|