-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathstreamlit_app.py
134 lines (107 loc) · 4.17 KB
/
streamlit_app.py
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
from crewai import Crew
from trip_agents import TripAgents, StreamToExpander
from trip_tasks import TripTasks
import streamlit as st
import datetime
import sys
st.set_page_config(page_icon="✈️", layout="wide")
def icon(emoji: str):
"""Shows an emoji as a Notion-style page icon."""
st.write(
f'<span style="font-size: 78px; line-height: 1">{emoji}</span>',
unsafe_allow_html=True,
)
class TripCrew:
def __init__(self, origin, cities, date_range, interests):
self.cities = cities
self.origin = origin
self.interests = interests
self.date_range = date_range
self.output_placeholder = st.empty()
def run(self):
agents = TripAgents()
tasks = TripTasks()
city_selector_agent = agents.city_selection_agent()
local_expert_agent = agents.local_expert()
travel_concierge_agent = agents.travel_concierge()
identify_task = tasks.identify_task(
city_selector_agent,
self.origin,
self.cities,
self.interests,
self.date_range
)
gather_task = tasks.gather_task(
local_expert_agent,
self.origin,
self.interests,
self.date_range
)
plan_task = tasks.plan_task(
travel_concierge_agent,
self.origin,
self.interests,
self.date_range
)
crew = Crew(
agents=[
city_selector_agent, local_expert_agent, travel_concierge_agent
],
tasks=[identify_task, gather_task, plan_task],
verbose=True
)
result = crew.kickoff()
self.output_placeholder.markdown(result)
return result
if __name__ == "__main__":
icon("🏖️ VacAIgent")
st.subheader("Let AI agents plan your next vacation!",
divider="rainbow", anchor=False)
import datetime
today = datetime.datetime.now().date()
next_year = today.year + 1
jan_16_next_year = datetime.date(next_year, 1, 10)
with st.sidebar:
st.header("👇 Enter your trip details")
with st.form("my_form"):
location = st.text_input(
"Where are you currently located?", placeholder="San Mateo, CA")
cities = st.text_input(
"City and country are you interested in vacationing at?", placeholder="Bali, Indonesia")
date_range = st.date_input(
"Date range you are interested in traveling?",
min_value=today,
value=(today, jan_16_next_year + datetime.timedelta(days=6)),
format="MM/DD/YYYY",
)
interests = st.text_area("High level interests and hobbies or extra details about your trip?",
placeholder="2 adults who love swimming, dancing, hiking, and eating")
submitted = st.form_submit_button("Submit")
st.divider()
# Credits to joaomdmoura/CrewAI for the code: https://github.com/joaomdmoura/crewAI
st.sidebar.markdown(
"""
Credits to [**@joaomdmoura**](https://twitter.com/joaomdmoura)
for creating **crewAI** 🚀
""",
unsafe_allow_html=True
)
st.sidebar.info("Click the logo to visit GitHub repo", icon="👇")
st.sidebar.markdown(
"""
<a href="https://github.com/joaomdmoura/crewAI" target="_blank">
<img src="https://raw.githubusercontent.com/joaomdmoura/crewAI/main/docs/crewai_logo.png" alt="CrewAI Logo" style="width:100px;"/>
</a>
""",
unsafe_allow_html=True
)
if submitted:
with st.status("🤖 **Agents at work...**", state="running", expanded=True) as status:
with st.container(height=500, border=False):
sys.stdout = StreamToExpander(st)
trip_crew = TripCrew(location, cities, date_range, interests)
result = trip_crew.run()
status.update(label="✅ Trip Plan Ready!",
state="complete", expanded=False)
st.subheader("Here is your Trip Plan", anchor=False, divider="rainbow")
st.markdown(result)