Spaces:
Sleeping
Sleeping
File size: 3,280 Bytes
ae2920c |
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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
import streamlit as st
import datetime
from openai import OpenAI
import os
from prompts import PROMPT_FOR_MANDATE
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
client = OpenAI(api_key=OPENAI_API_KEY)
st.set_page_config(page_title="AI Trip Planner")
if 'clicked' not in st.session_state:
st.session_state.clicked = False
def click_button():
st.session_state.clicked = True
with st.sidebar:
st.title("Your AI Trip Planner!")
where_to = st.text_area("Where To?")
number_of_days = st.text_area("How many days?")
itinerary_type = st.multiselect(
"Itinerary Type(s):",
(
"Standard",
"Adventure",
"Bachelor Party",
"Bachelor Party",
"Bicycling",
"City Experiences",
"Cultural Immersion",
"Dog Friendly",
"Eco Friendly",
"Educational",
"Family Friendly",
"Foodie",
"Honeymoon",
"Luxury",
"Motorcycle Riding",
"Nature",
"Relaxation",
"Rail/Train Trip",
"Road Trip",
"Shoestring Budget",
"Volunteering",
)
)
when_your_trip_start = st.date_input("When your trip start?", datetime.date(2024, 7, 6))
when_your_trip_end = st.date_input("When your trip end?", datetime.date(2024, 7, 8))
travel_preference = st.text_area("Any travel preference?")
st.button("Generate Trip Plan", on_click=click_button)
if st.session_state.clicked:
if where_to and number_of_days and itinerary_type:
message_placeholder = st.empty()
full_response = ""
prompt = f"""PLACE:```{where_to}``` , NUMBER_OF_DAYS:```{number_of_days}```, TRIP_TYPE: ```{itinerary_type}```""" + \
PROMPT_FOR_MANDATE
for response in client.chat.completions.create(
model="gpt-4",
messages=[{'role': 'user', 'content': prompt}],
stream=True,
):
if response.choices[0].delta.content is not None:
full_response += response.choices[0].delta.content
message_placeholder.markdown(full_response + "▌")
message_placeholder.markdown(full_response)
elif where_to and number_of_days and itinerary_type or when_your_trip_start or when_your_trip_end or travel_preference:
message_placeholder = st.empty()
full_response = ""
prompt = f"""PLACE:```{where_to}``` , NUMBER_OF_DAYS:```{number_of_days}```, TRIP_TYPE: ```{itinerary_type}```,
TRIP_START: ```{when_your_trip_start}```, TRIP_END:```{when_your_trip_end}```, TRAVEL_PREFERENCE:```{travel_preference}```""" + \
PROMPT_FOR_MANDATE
for response in client.chat.completions.create(
model="gpt-4",
messages=[{'role': 'user', 'content': prompt}],
stream=True,
):
if response.choices[0].delta.content is not None:
full_response += response.choices[0].delta.content
message_placeholder.markdown(full_response + "▌")
message_placeholder.markdown(full_response)
|