menikev commited on
Commit
c18c6ca
·
verified ·
1 Parent(s): df9167a

create app.py

Browse files
Files changed (1) hide show
  1. app.py +199 -0
app.py ADDED
@@ -0,0 +1,199 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from crewai import Crew, Process
3
+ from textwrap import dedent
4
+ from trip_agents import TripAgents
5
+ from trip_tasks import TripTasks
6
+ from dotenv import load_dotenv
7
+
8
+ load_dotenv()
9
+
10
+ class TripCrew:
11
+ def __init__(self, origin, cities, date_range, interests):
12
+ self.cities = cities
13
+ self.origin = origin
14
+ self.interests = interests
15
+ self.date_range = date_range
16
+
17
+ def run(self):
18
+ agents = TripAgents()
19
+ tasks = TripTasks()
20
+
21
+ city_selector_agent = agents.city_selection_agent()
22
+ local_expert_agent = agents.local_expert()
23
+ travel_concierge_agent = agents.travel_concierge()
24
+
25
+ identify_task = tasks.identify_task(
26
+ city_selector_agent,
27
+ self.origin,
28
+ self.cities,
29
+ self.interests,
30
+ self.date_range
31
+ )
32
+ gather_task = tasks.gather_task(
33
+ local_expert_agent,
34
+ self.origin,
35
+ self.interests,
36
+ self.date_range
37
+ )
38
+ plan_task = tasks.plan_task(
39
+ travel_concierge_agent,
40
+ self.origin,
41
+ self.interests,
42
+ self.date_range
43
+ )
44
+
45
+ crew = Crew(
46
+ agents=[
47
+ city_selector_agent, local_expert_agent, travel_concierge_agent
48
+ ],
49
+ tasks=[identify_task, gather_task, plan_task],
50
+ verbose=True,
51
+ )
52
+
53
+ result = crew.kickoff()
54
+ return result
55
+
56
+ # Function to initialize chat history in session state
57
+ def initialize_chat_history():
58
+ if 'chat_history' not in st.session_state:
59
+ st.session_state['chat_history'] = []
60
+
61
+ # Function to handle user input and AI response
62
+ def handle_user_input():
63
+ user_input = st.session_state['user_input']
64
+ if user_input:
65
+ # Append user message to chat history
66
+ st.session_state['chat_history'].append(f"<div style='text-align: right;'>You: {user_input}</div>")
67
+
68
+ # Get user input for trip planning
69
+ location = user_input.split(",")[0].strip()
70
+ cities = user_input.split(",")[1].strip()
71
+ date_range = user_input.split(",")[2].strip()
72
+ interests = user_input.split(",")[3].strip()
73
+
74
+ # Run the trip planning agent
75
+ trip_crew = TripCrew(location, cities, date_range, interests)
76
+ result = trip_crew.run()
77
+
78
+ # Append agent response to chat history
79
+ st.session_state['chat_history'].append(f"<div style='text-align: right;'>{result}</div>")
80
+
81
+ # Clear the input field
82
+ st.session_state['user_input'] = ""
83
+
84
+ # Initialize chat history
85
+ initialize_chat_history()
86
+
87
+ # Main page layout
88
+ st.title("Welcome to Paris Travel Advisor!")
89
+
90
+ # Sidebar
91
+ st.sidebar.title("Chat History")
92
+ st.sidebar.write("Recent Conversations")
93
+ # Dummy chat history for UI demonstration
94
+ for i in range(5):
95
+ st.sidebar.write(f"Conversation {i + 1}")
96
+ st.sidebar.button("New Chat")
97
+ st.sidebar.button("Clear Conversations")
98
+ st.sidebar.write("My Account")
99
+ st.sidebar.write("Logout")
100
+
101
+ # Main content
102
+ col1, col2, col3 = st.columns(3)
103
+
104
+ # Custom CSS for box with shadow effect and equal heights
105
+ box_shadow = """
106
+ <style>
107
+ .custom-box {
108
+ box-shadow: 5px 5px 10px rgba(0, 0, 0, 0.2);
109
+ padding: 15px;
110
+ border-radius: 5px;
111
+ background-color: #fff;
112
+ height: 100%;
113
+ display: flex;
114
+ flex-direction: column;
115
+ }
116
+
117
+ .custom-box h3 {
118
+ margin-top: 0;
119
+ font-size: 1.2rem;
120
+ }
121
+
122
+ .custom-box p {
123
+ flex-grow: 1;
124
+ font-size: 0.8rem;
125
+ }
126
+ </style>
127
+ """
128
+ st.markdown(box_shadow, unsafe_allow_html=True)
129
+
130
+ with col1:
131
+ # Plan Your Trip section with box
132
+ st.markdown(
133
+ """
134
+ <div class="custom-box">
135
+ <h3>Plan Your Trip</h3>
136
+ <p>Plan your itinerary with ease. Search for flights, hotels, and activities, all in one place. Book your selections and create a personalized itinerary.</p>
137
+ </div>
138
+ """,
139
+ unsafe_allow_html=True,
140
+ )
141
+
142
+ with col2:
143
+ # Trip Inspiration section with box
144
+ st.markdown(
145
+ """
146
+ <div class="custom-box">
147
+ <h3>Trip Inspiration</h3>
148
+ <p>Find your dream vacation. Explore destinations, discover things to do, and get ideas for your next trip.</p>
149
+ </div>
150
+ """,
151
+ unsafe_allow_html=True,
152
+ )
153
+
154
+ with col3:
155
+ # Travel Restrictions and Advisories section with box
156
+ st.markdown(
157
+ """
158
+ <div class="custom-box">
159
+ <h3>Travel Restrictions and Advisories</h3>
160
+ <p>Stay informed, travel safe! Get the latest updates on travel advisories, visa requirements, and COVID-19 restrictions for your destinations.</p>
161
+ </div>
162
+ """,
163
+ unsafe_allow_html=True,
164
+ )
165
+
166
+ # Display chat history
167
+ for message in st.session_state['chat_history']:
168
+ st.markdown(message, unsafe_allow_html=True)
169
+
170
+ # CSS styles for input container with absolute positioning and flexbox for centering
171
+ st.markdown(
172
+ """
173
+ <style>
174
+ .input-container {
175
+ position: absolute;
176
+ bottom: 0;
177
+ width: 100%;
178
+ background-color: #f1f1f1;
179
+ padding: 10px;
180
+ box-sizing: border-box;
181
+ display: flex; /* Added flexbox for centering */
182
+ justify-content: center; /* Horizontally center elements */
183
+ }
184
+ .input-container .column {
185
+ margin: 0 5px;
186
+ }
187
+ </style>
188
+ """,
189
+ unsafe_allow_html=True,
190
+ )
191
+
192
+ # Input field and send button icon inside a container
193
+ input_container = st.container()
194
+ with input_container:
195
+ col1, col2 = st.columns([10, 1])
196
+ with col1:
197
+ user_input = st.text_input("", key="user_input", placeholder="Enter your trip details (location, cities, date range, interests)", help="Enter your trip details separated by commas")
198
+ with col2:
199
+ submit_button = st.button("⬆", on_click=handle_user_input)