Spaces:
Sleeping
Sleeping
File size: 3,410 Bytes
6771851 cac9eab 6771851 cac9eab 6771851 fdeb1a4 cac9eab 6771851 96e5cf4 6771851 cac9eab 6771851 cac9eab e04d0e2 d7efb38 6771851 96e5cf4 6771851 124e810 6771851 8b0495f 96e5cf4 d7efb38 53542d0 eee8f57 bacabac eee8f57 96e5cf4 eee8f57 53542d0 96e5cf4 74e6cfb eee8f57 96e5cf4 bacabac b4404b9 53542d0 96e5cf4 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["YOUR_OPENAI_API_KEY"]
initial_messages = [{
"role": "system",
"content": """You are an AI assistant that matches people with their ideal thing to do this weekend based on their entertainment preferences in
Joliet, Illinois, and surrounding areas up to 15 miles outside Joliet, Illinois city limits. You'll receive information about the user's entertainment and lifestyle preferences. Use this information
to suggest things to do in Joliet, Illinois 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 subscribe to our newsletter to get exclusive Joliet weekend deals and offers. Just use the form at the top of the page!' """
}]
@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(additional_details, amenities_proximity, amenities, messages):
selected_amenities = ', '.join(amenities)
messages.append({
"role": "user",
"content": f"I'm interested in going out this weekend in Joliet, Illinois. {additional_details}. I'm looking for: {selected_amenities}. I want to be {amenities_proximity} to the city centre."
})
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("What On In Joliet Matchmaker")
st.write("This tool helps you help you find out what to do this weekend in Joliet, and surrounding areas based on your entertainment preferences.")
# Using columns to organize the layout
col1, col2 = st.columns(2)
with col1:
st.subheader("Your Preferences")
amenities_list = ["Restaurant", "Food Trucks", "Sports Bar", "Wine Bar", "Cafes", "Live music", "Clubs", "Sports", "Cultural Attractions", "Outdoor events"]
# Splitting amenities into two columns
half = len(amenities_list) // 2
amenities_col1, amenities_col2 = st.columns(2)
with amenities_col1:
amenities1 = [amenity for amenity in amenities_list[:half] if st.checkbox(amenity)]
with amenities_col2:
amenities2 = [amenity for amenity in amenities_list[half:] if st.checkbox(amenity)]
amenities = amenities1 + amenities2
amenities_proximity = st.selectbox("Proximity to the centre of Joliet", ["Walking distance", "A short drive away", "I don't mind being far from the city centre"])
additional_details = st.text_area("Additional Details", placeholder="Describe any other preferences such as style of music or type of food.")
submit_button = st.button('Plan My Weekend')
with col2:
# Placeholder for the result
st.subheader("What to do this weekend")
result_placeholder = st.empty()
if submit_button:
messages = initial_messages.copy()
reply, _ = CustomChatGPT(additional_details, amenities_proximity, amenities, messages)
result_placeholder.write(reply)
else:
result_placeholder.write("**Results will appear here after you submit your preferences**")
|