Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- app.py +83 -0
- prompts.py +40 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import datetime
|
| 3 |
+
from openai import OpenAI
|
| 4 |
+
import os
|
| 5 |
+
from prompts import PROMPT_FOR_MANDATE
|
| 6 |
+
|
| 7 |
+
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
| 8 |
+
client = OpenAI(api_key=OPENAI_API_KEY)
|
| 9 |
+
st.set_page_config(page_title="AI Trip Planner")
|
| 10 |
+
|
| 11 |
+
if 'clicked' not in st.session_state:
|
| 12 |
+
st.session_state.clicked = False
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def click_button():
|
| 16 |
+
st.session_state.clicked = True
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
with st.sidebar:
|
| 20 |
+
st.title("Your AI Trip Planner!")
|
| 21 |
+
where_to = st.text_area("Where To?")
|
| 22 |
+
number_of_days = st.text_area("How many days?")
|
| 23 |
+
itinerary_type = st.multiselect(
|
| 24 |
+
"Itinerary Type(s):",
|
| 25 |
+
(
|
| 26 |
+
"Standard",
|
| 27 |
+
"Adventure",
|
| 28 |
+
"Bachelor Party",
|
| 29 |
+
"Bachelor Party",
|
| 30 |
+
"Bicycling",
|
| 31 |
+
"City Experiences",
|
| 32 |
+
"Cultural Immersion",
|
| 33 |
+
"Dog Friendly",
|
| 34 |
+
"Eco Friendly",
|
| 35 |
+
"Educational",
|
| 36 |
+
"Family Friendly",
|
| 37 |
+
"Foodie",
|
| 38 |
+
"Honeymoon",
|
| 39 |
+
"Luxury",
|
| 40 |
+
"Motorcycle Riding",
|
| 41 |
+
"Nature",
|
| 42 |
+
"Relaxation",
|
| 43 |
+
"Rail/Train Trip",
|
| 44 |
+
"Road Trip",
|
| 45 |
+
"Shoestring Budget",
|
| 46 |
+
"Volunteering",
|
| 47 |
+
)
|
| 48 |
+
)
|
| 49 |
+
when_your_trip_start = st.date_input("When your trip start?", datetime.date(2024, 7, 6))
|
| 50 |
+
when_your_trip_end = st.date_input("When your trip end?", datetime.date(2024, 7, 8))
|
| 51 |
+
travel_preference = st.text_area("Any travel preference?")
|
| 52 |
+
st.button("Generate Trip Plan", on_click=click_button)
|
| 53 |
+
|
| 54 |
+
if st.session_state.clicked:
|
| 55 |
+
if where_to and number_of_days and itinerary_type:
|
| 56 |
+
message_placeholder = st.empty()
|
| 57 |
+
full_response = ""
|
| 58 |
+
prompt = f"""PLACE:```{where_to}``` , NUMBER_OF_DAYS:```{number_of_days}```, TRIP_TYPE: ```{itinerary_type}```""" + \
|
| 59 |
+
PROMPT_FOR_MANDATE
|
| 60 |
+
for response in client.chat.completions.create(
|
| 61 |
+
model="gpt-4",
|
| 62 |
+
messages=[{'role': 'user', 'content': prompt}],
|
| 63 |
+
stream=True,
|
| 64 |
+
):
|
| 65 |
+
if response.choices[0].delta.content is not None:
|
| 66 |
+
full_response += response.choices[0].delta.content
|
| 67 |
+
message_placeholder.markdown(full_response + "▌")
|
| 68 |
+
message_placeholder.markdown(full_response)
|
| 69 |
+
elif where_to and number_of_days and itinerary_type or when_your_trip_start or when_your_trip_end or travel_preference:
|
| 70 |
+
message_placeholder = st.empty()
|
| 71 |
+
full_response = ""
|
| 72 |
+
prompt = f"""PLACE:```{where_to}``` , NUMBER_OF_DAYS:```{number_of_days}```, TRIP_TYPE: ```{itinerary_type}```,
|
| 73 |
+
TRIP_START: ```{when_your_trip_start}```, TRIP_END:```{when_your_trip_end}```, TRAVEL_PREFERENCE:```{travel_preference}```""" + \
|
| 74 |
+
PROMPT_FOR_MANDATE
|
| 75 |
+
for response in client.chat.completions.create(
|
| 76 |
+
model="gpt-4",
|
| 77 |
+
messages=[{'role': 'user', 'content': prompt}],
|
| 78 |
+
stream=True,
|
| 79 |
+
):
|
| 80 |
+
if response.choices[0].delta.content is not None:
|
| 81 |
+
full_response += response.choices[0].delta.content
|
| 82 |
+
message_placeholder.markdown(full_response + "▌")
|
| 83 |
+
message_placeholder.markdown(full_response)
|
prompts.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
PROMPT_FOR_MANDATE = """User is going to place:PLACE, for number of days:NUMBER_OF_DAYS, for a this type of trip: TRIP_TYPE. Your task is to
|
| 2 |
+
create a complete Trip Planner. Lets divide how you will give the trip planner step by step:
|
| 3 |
+
1.) First check where the user is going , for how many days and which type of trip the user is planning.
|
| 4 |
+
2.) Take time to think and plan the trip on your own first.
|
| 5 |
+
3.) You should provide where the user will go on which day, on a single day time based trip planning, at what time user will visit at
|
| 6 |
+
what site seeing area, also add a small comment about that area, where the user will have breakfast, shopping, dinner etc.
|
| 7 |
+
4.) Final Output will be a Point based Drop down, for example if the user is going to Goa , for 6 days for a standard trip then the output
|
| 8 |
+
from your side will look like this:
|
| 9 |
+
```
|
| 10 |
+
DAY 1\n
|
| 11 |
+
North Goa Delights\n
|
| 12 |
+
North Goa, India\n\n
|
| 13 |
+
* 8:00AM \t Breakfast at Infantaria\n Price: 100 Rs \n Time: 1 Hour \n Start your day with a delicious breakfast at Infantaria,
|
| 14 |
+
a famous Goan eatery known for its fresh bakes and coffee.\n
|
| 15 |
+
* 10:00AM \t Explore Fort Aguada \n Price: 1000 Rs \n Time: 1 Hour \n Visit the historic Fort Aguada, offering stunning views of the
|
| 16 |
+
Arabian Sea and a glimpse into Goa's colonial past.\n\n
|
| 17 |
+
```
|
| 18 |
+
"""
|
| 19 |
+
|
| 20 |
+
PROMPT_FOR_ALL = """User is going to place:PLACE, for number of days:NUMBER_OF_DAYS, for a this type of trip: TRIP_TYPE, user is
|
| 21 |
+
starting the trip on TRIP_START, and ending the trip on TRIP_END, also the user have some preferences TRAVEL_PREFERENCE.
|
| 22 |
+
Your task is to
|
| 23 |
+
create a complete Trip Planner. Lets divide how you will give the trip planner step by step:
|
| 24 |
+
1.) First check where the user is going , for how many days and which type of trip the user is planning, about trip start and end, also
|
| 25 |
+
the preferences of the user. Always be customised and personalised for the user.
|
| 26 |
+
2.) Take time to think and plan the trip on your own first.
|
| 27 |
+
3.) You should provide where the user will go on which day, on a single day time based trip planning, at what time user will visit at
|
| 28 |
+
what site seeing area, also add a small comment about that area, where the user will have breakfast, shopping, dinner etc.
|
| 29 |
+
4.) Final Output will be a Point based Drop down, for example if the user is going to Goa , for 6 days for a standard trip then the output
|
| 30 |
+
from your side will look like this:
|
| 31 |
+
```
|
| 32 |
+
DAY 1\n
|
| 33 |
+
North Goa Delights\n
|
| 34 |
+
North Goa, India\n\n
|
| 35 |
+
* 8:00AM \t Breakfast at Infantaria\n Price: 100 Rs \n Time: 1 Hour \n Start your day with a delicious breakfast at Infantaria,
|
| 36 |
+
a famous Goan eatery known for its fresh bakes and coffee.\n
|
| 37 |
+
* 10:00AM \t Explore Fort Aguada \n Price: 1000 Rs \n Time: 1 Hour \n Visit the historic Fort Aguada, offering stunning views of the
|
| 38 |
+
Arabian Sea and a glimpse into Goa's colonial past.\n\n
|
| 39 |
+
```
|
| 40 |
+
"""
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
openai
|
| 2 |
+
streamlit
|
| 3 |
+
datetime
|