Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,10 +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
|
| 12 |
-
Saint Louis, Missouri, and surrounding areas up to 30 miles outside Saint Louis city limits. You'll receive information about the user's lifestyle preferences. Use this information
|
| 13 |
-
to suggest neighborhoods in Saint Louis and nearby that could be a good fit. Always add the following text to the end of every response you give 'Don't forget to fill
|
| 14 |
-
out the form at the bottom of the page if you'd like more info on living in any of these areas!' """
|
| 15 |
}]
|
| 16 |
|
| 17 |
@retry(stop=stop_after_attempt(3), wait=wait_fixed(1))
|
|
@@ -21,11 +18,11 @@ def call_openai_api(messages):
|
|
| 21 |
messages=messages
|
| 22 |
)
|
| 23 |
|
| 24 |
-
def CustomChatGPT(
|
| 25 |
-
|
| 26 |
messages.append({
|
| 27 |
"role": "user",
|
| 28 |
-
"content": f"I'm
|
| 29 |
})
|
| 30 |
response = call_openai_api(messages)
|
| 31 |
ChatGPT_reply = response["choices"][0]["message"]["content"]
|
|
@@ -34,36 +31,37 @@ def CustomChatGPT(additional_details, amenities_proximity, amenities, messages):
|
|
| 34 |
|
| 35 |
# Streamlit Interface
|
| 36 |
st.set_page_config(layout="wide") # Set the layout to wide
|
| 37 |
-
st.title("
|
| 38 |
-
st.write("This tool
|
| 39 |
|
| 40 |
# Using columns to organize the layout
|
| 41 |
col1, col2 = st.columns(2)
|
| 42 |
|
| 43 |
with col1:
|
| 44 |
st.subheader("Your Preferences")
|
| 45 |
-
|
| 46 |
-
# Splitting
|
| 47 |
-
half = len(
|
| 48 |
-
|
| 49 |
-
with
|
| 50 |
-
|
| 51 |
-
with
|
| 52 |
-
|
| 53 |
-
|
| 54 |
|
| 55 |
-
|
| 56 |
-
|
|
|
|
| 57 |
|
| 58 |
-
submit_button = st.button('Find
|
| 59 |
|
| 60 |
with col2:
|
| 61 |
# Placeholder for the result
|
| 62 |
-
st.subheader("Recommended
|
| 63 |
result_placeholder = st.empty()
|
| 64 |
if submit_button:
|
| 65 |
messages = initial_messages.copy()
|
| 66 |
-
reply, _ = CustomChatGPT(
|
| 67 |
-
result_placeholder.write(reply)
|
| 68 |
else:
|
| 69 |
result_placeholder.write("**Results will appear here after you submit your preferences**")
|
|
|
|
| 8 |
|
| 9 |
initial_messages = [{
|
| 10 |
"role": "system",
|
| 11 |
+
"content": """You are an AI assistant that suggests weekend activities in Chelmsford, Essex, and surrounding areas up to 10 miles away. You'll receive information about the user's preferences for the weekend. Use this information to suggest activities in the area. Always add the following text to the end of every response you give: 'Enjoy your weekend!' """
|
|
|
|
|
|
|
|
|
|
| 12 |
}]
|
| 13 |
|
| 14 |
@retry(stop=stop_after_attempt(3), wait=wait_fixed(1))
|
|
|
|
| 18 |
messages=messages
|
| 19 |
)
|
| 20 |
|
| 21 |
+
def CustomChatGPT(activities, location_proximity, location_type, group_type, messages):
|
| 22 |
+
selected_activities = ', '.join(activities)
|
| 23 |
messages.append({
|
| 24 |
"role": "user",
|
| 25 |
+
"content": f"I'm looking for weekend activities in Chelmsford, Essex, and surrounding areas up to 10 miles away. I'm interested in {selected_activities}. I prefer to do activities {location_proximity} and in {location_type}. My group type is {group_type}."
|
| 26 |
})
|
| 27 |
response = call_openai_api(messages)
|
| 28 |
ChatGPT_reply = response["choices"][0]["message"]["content"]
|
|
|
|
| 31 |
|
| 32 |
# Streamlit Interface
|
| 33 |
st.set_page_config(layout="wide") # Set the layout to wide
|
| 34 |
+
st.title("Weekend Activity Matchmaker")
|
| 35 |
+
st.write("This tool suggests weekend activities in Chelmsford, Essex, and surrounding areas based on your preferences.")
|
| 36 |
|
| 37 |
# Using columns to organize the layout
|
| 38 |
col1, col2 = st.columns(2)
|
| 39 |
|
| 40 |
with col1:
|
| 41 |
st.subheader("Your Preferences")
|
| 42 |
+
activities_list = ["Outdoor activities", "Indoor activities", "Free activities", "On a budget", "Restaurants", "Live music", "Museums", "Sports", "Games", "Animals", "Shopping", "Parks", "Cultural attractions", "Spas", "Swimming pools"]
|
| 43 |
+
# Splitting activities into two columns
|
| 44 |
+
half = len(activities_list) // 2
|
| 45 |
+
activities_col1, activities_col2 = st.columns(2)
|
| 46 |
+
with activities_col1:
|
| 47 |
+
activities1 = [activity for activity in activities_list[:half] if st.checkbox(activity)]
|
| 48 |
+
with activities_col2:
|
| 49 |
+
activities2 = [activity for activity in activities_list[half:] if st.checkbox(activity)]
|
| 50 |
+
activities = activities1 + activities2
|
| 51 |
|
| 52 |
+
location_proximity = st.selectbox("Proximity to Activities", ["Nearby", "A short drive away", "I don't mind travelling"])
|
| 53 |
+
location_type = st.selectbox("Location Type", ["City centre", "Out of town", "Any"])
|
| 54 |
+
group_type = st.selectbox("Group Type", ["Individual", "Small group", "Family", "Pet-friendly", "Accessible"])
|
| 55 |
|
| 56 |
+
submit_button = st.button('Find Activities')
|
| 57 |
|
| 58 |
with col2:
|
| 59 |
# Placeholder for the result
|
| 60 |
+
st.subheader("Recommended Activities")
|
| 61 |
result_placeholder = st.empty()
|
| 62 |
if submit_button:
|
| 63 |
messages = initial_messages.copy()
|
| 64 |
+
reply, _ = CustomChatGPT(activities, location_proximity, location_type, group_type, messages)
|
| 65 |
+
result_placeholder.write(reply + "\nEnjoy your weekend!")
|
| 66 |
else:
|
| 67 |
result_placeholder.write("**Results will appear here after you submit your preferences**")
|