dlennon's picture
Update app.py
095c341 verified
import streamlit as st
import openai
import os
# Set up OpenAI API key
openai.api_key = os.getenv("OPENAI_API_KEY")
# Define the archetypes and interests/options based on the prompts
archetypes = [
"Architecture Admirers", "Art Aficionados", "Literature Enthusiasts", "History Buffs", "Luxury Traveler"
"Biophilia and Nature Lovers", "Outdoor Recreation Enthusiasts", "Foodies and Culinary Explorers",
"Craft Beer Enthusiasts", "Music Lovers", "Wellness and Mindfulness Seekers", "Urban Enthusiast",
"Antique and Vintage Collectors", "Farm-to-Table Enthusiasts", "Spiritual and Holistic Healing",
"Photography and Scenic Views", "Thrift and Vintage Fashion", "Environmental Sustainability Advocates",
"LGBTQ+"
]
all_interests = [
"Modern Architecture",
"Contemporary Art",
"Local Art Scenes",
"Literary Landmarks",
"Historical Sites",
"Natural Attractions",
"Scenic Hikes",
"Water Sports",
"Best Restaurants",
"Food Markets",
"Breweries",
"Live Music Venues",
"Meditation Centers",
"Antique Shops",
"Farmers' Markets",
"Sacred Sites",
"Holistic Therapies",
"Best Photo Spots",
"Iconic Landmarks",
"Thrift Stores",
"Specific Fashion Eras",
"Eco-Conscious Attractions",
"Green Spaces",
"LGBTQ+ Bars",
"Clubs",
"LGBTQ+-Owned Businesses"
]
# Remove duplicates from all_interests
all_interests = list(set(all_interests))
def generate_itinerary(destination, duration, archetype, interests):
# Construct the system's prompt as a string
system_prompt = (
f"Create a detailed itinerary for a trip to {destination} spanning {duration} "
f"tailored for {archetype}. Do not number the recommendations, just list the day in bold, and then the suggested times for the activities. \n"
"Please include specific recommendations (please be sure to include hidden gems and off-the-beaten-path destinations) for the following interests:\n"
)
# Construct the user input as a string
user_input = ""
for interest in interests:
user_input += f"- {interest}\n"
messages = [
{"role": "system", "content": system_prompt},
{"role": "user", "content": user_input}
]
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=messages,
temperature=0.5,
max_tokens=1000
)
# Correctly access the response content
generated_itinerary = response.choices[0].message['content'].strip()
return generated_itinerary
# Streamlit UI for collecting inputs
st.set_page_config(layout="wide")
st.markdown("<h1 style='text-align: center; color: black;'>Hyperlocal Itinerary Generator</h1>", unsafe_allow_html=True)
st.write(":blue[A streamlined tool to craft personalized hyperlocal itineraries for clients. Tailored for potential and current clients, the app enables agents to curate detailed travel plans based on individual interests. Users input destination, trip duration, archetype (e.g., family, adventure seeker), and specific interests such as architecture or dining. Leveraging AI, the app generates bespoke itineraries, highlighting local attractions, dining options, and activities. With seamless integration of user preferences, agents can deliver immersive experiences that showcase the unique charm and appeal of each neighborhood, fostering deeper client engagement and satisfaction.]")
# User input sections
st.markdown("<h2 style='text-align: center; color: black;'>Trip Details</h2>", unsafe_allow_html=True)
destination = st.text_input("Destination (City, State)", placeholder="Enter destination city and state")
duration = st.selectbox("Duration", ["24 hours", "48 hours", "72 hours"])
archetype = st.selectbox("Archetype", ["Unknown"] + archetypes) # Include "Unknown" option
st.markdown("<h2 style='text-align: center; color: black;'>Interests</h2>", unsafe_allow_html=True)
# Calculate number of columns
num_columns = 7
# Calculate approximate number of checkboxes per column
approx_checkboxes_per_column = len(all_interests) // num_columns
# Create a list to store checkboxes
checkboxes = []
# Create columns for organizing checkboxes
cols = st.columns(num_columns)
# Loop over the number of columns
for i in range(num_columns):
# Calculate start and end indices for current column
start_index = i * approx_checkboxes_per_column
end_index = min((i + 1) * approx_checkboxes_per_column, len(all_interests))
# Get interests for current column
column_interests = all_interests[start_index:end_index]
# Add checkboxes to the current column container
with cols[i]:
for interest in column_interests:
unique_key = f"{interest}-{all_interests.index(interest)}" # Append index to ensure uniqueness
checkbox = st.checkbox(interest, key=unique_key, value=False) # Ensure each checkbox has a unique key
checkboxes.append(checkbox)
# If the button is pressed, generate content and display in the second column (right)
generate_button = st.button('Generate Itinerary')
if generate_button:
interests = [checkbox.label for checkbox in checkboxes if checkbox.value]
generated_itinerary = generate_itinerary(destination, duration, archetype, interests)
# Display the generated itinerary
st.markdown("<h2 style='text-align: center; color: black;'>Generated Itinerary ⬇️</h2>", unsafe_allow_html=True)
st.markdown(generated_itinerary)
download_button_str = f"Download Itinerary as Text Document"
with st.expander("Download Itinerary"):
st.download_button(
label=download_button_str,
data=generated_itinerary,
file_name="generated_itinerary.txt",
mime="text/plain"
)