Spaces:
Runtime error
Runtime error
File size: 3,358 Bytes
6771851 cac9eab 6771851 cac9eab 6771851 81985aa 8c36813 cac9eab 6771851 9adda79 6771851 cac9eab 6771851 cac9eab 9adda79 6771851 9adda79 6771851 124e810 6771851 8b0495f 9adda79 d7efb38 53542d0 eee8f57 bacabac eee8f57 9adda79 53542d0 9adda79 eee8f57 9adda79 bacabac b4404b9 53542d0 9adda79 53542d0 9adda79 53542d0 eee8f57 |
1 2 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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
import openai
import streamlit as st
import os
from tenacity import retry, stop_after_attempt, wait_fixed
# Set the OpenAI API key
openai.api_key = os.environ["sk-proj-39WvclbTNo8aFwOukQXET3BlbkFJn4sNgi7G3tXMNb8OyS9t"]
initial_messages = [{
"role": "system",
"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!' """
}]
@retry(stop=stop_after_attempt(3), wait=wait_fixed(1))
def call_openai_api(messages):
return openai.ChatCompletion.create(
model="gpt-4",
messages=messages
)
def CustomChatGPT(activities, location_proximity, location_type, group_type, messages):
selected_activities = ', '.join(activities)
messages.append({
"role": "user",
"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}."
})
response = call_openai_api(messages)
ChatGPT_reply = response["choices"][0]["message"]["content"]
messages.append({"role": "assistant", "content": ChatGPT_reply})
return ChatGPT_reply, messages
# Streamlit Interface
st.set_page_config(layout="wide") # Set the layout to wide
st.title("Weekend Activity Matchmaker")
st.write("This tool suggests weekend activities in Chelmsford, Essex, and surrounding areas based on your preferences.")
# Using columns to organize the layout
col1, col2 = st.columns(2)
with col1:
st.subheader("Your Preferences")
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"]
# Splitting activities into two columns
half = len(activities_list) // 2
activities_col1, activities_col2 = st.columns(2)
with activities_col1:
activities1 = [activity for activity in activities_list[:half] if st.checkbox(activity)]
with activities_col2:
activities2 = [activity for activity in activities_list[half:] if st.checkbox(activity)]
activities = activities1 + activities2
location_proximity = st.selectbox("Proximity to Activities", ["Nearby", "A short drive away", "I don't mind travelling"])
location_type = st.selectbox("Location Type", ["City centre", "Out of town", "Any"])
group_type = st.selectbox("Group Type", ["Individual", "Small group", "Family", "Pet-friendly", "Accessible"])
submit_button = st.button('Find Activities')
with col2:
# Placeholder for the result
st.subheader("Recommended Activities")
result_placeholder = st.empty()
if submit_button:
messages = initial_messages.copy()
reply, _ = CustomChatGPT(activities, location_proximity, location_type, group_type, messages)
result_placeholder.write(reply + "\nEnjoy your weekend!")
else:
result_placeholder.write("**Results will appear here after you submit your preferences**")
|