Spaces:
Running
Running
Updating app to show venues on a map
Browse files- app.py +53 -4
- config/address_agents.yaml +8 -0
- config/address_tasks.yaml +6 -0
- crew.py +35 -4
app.py
CHANGED
@@ -1,11 +1,40 @@
|
|
1 |
#!/usr/bin/env python
|
2 |
import sys
|
|
|
3 |
import gradio as gr
|
4 |
-
|
|
|
|
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
def run(origin, destination, age, trip_duration, children, budget):
|
8 |
# Replace with your inputs, it will automatically interpolate any tasks and agents information
|
|
|
9 |
inputs = {
|
10 |
'origin': origin,
|
11 |
'destination': destination,
|
@@ -15,17 +44,37 @@ def run(origin, destination, age, trip_duration, children, budget):
|
|
15 |
'budget': budget
|
16 |
}
|
17 |
result = SurpriseTravelCrew().crew().kickoff(inputs=inputs)
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
|
|
|
|
20 |
|
21 |
demo = gr.Interface(
|
22 |
title="Plan your itinerary with the help of AI",
|
23 |
-
description="Use this app to create a detailed itinerary on how to explore a new place. Itinerary is customized to your taste",
|
24 |
fn=run,
|
25 |
inputs=["text", "text", gr.Slider(value=30, minimum=15, maximum=90, step=5),
|
26 |
gr.Slider(value=5, minimum=1, maximum=14, step=1),
|
27 |
gr.Checkbox(),
|
28 |
gr.Slider(value=100, minimum=20, maximum=1000, step=20)],
|
29 |
-
outputs=[
|
|
|
|
|
|
|
30 |
)
|
31 |
demo.launch()
|
|
|
1 |
#!/usr/bin/env python
|
2 |
import sys
|
3 |
+
import json
|
4 |
import gradio as gr
|
5 |
+
import plotly.graph_objects as go
|
6 |
+
import logging
|
7 |
+
from crew import SurpriseTravelCrew, AddressSummaryCrew
|
8 |
|
9 |
+
def filter_map(text_list, lat, lon):
|
10 |
+
fig = go.Figure(go.Scattermapbox(
|
11 |
+
lat=lat,
|
12 |
+
lon=lon,
|
13 |
+
mode='markers',
|
14 |
+
marker=go.scattermapbox.Marker(
|
15 |
+
size=11
|
16 |
+
),
|
17 |
+
hovertext=text_list
|
18 |
+
))
|
19 |
+
|
20 |
+
fig.update_layout(
|
21 |
+
mapbox_style="open-street-map",
|
22 |
+
hovermode='closest',
|
23 |
+
mapbox=dict(
|
24 |
+
bearing=0,
|
25 |
+
center=go.layout.mapbox.Center(
|
26 |
+
lat=lat[1],
|
27 |
+
lon=lon[1]
|
28 |
+
),
|
29 |
+
pitch=0,
|
30 |
+
zoom=10
|
31 |
+
),
|
32 |
+
)
|
33 |
+
return fig
|
34 |
|
35 |
def run(origin, destination, age, trip_duration, children, budget):
|
36 |
# Replace with your inputs, it will automatically interpolate any tasks and agents information
|
37 |
+
logger.info(f"Origin: {origin}, Destination: {destination}, Age: {age}, Duration: {trip_duration}, Children: {children}, Daily Budget: {budget}")
|
38 |
inputs = {
|
39 |
'origin': origin,
|
40 |
'destination': destination,
|
|
|
44 |
'budget': budget
|
45 |
}
|
46 |
result = SurpriseTravelCrew().crew().kickoff(inputs=inputs)
|
47 |
+
inputs_for_address = {
|
48 |
+
'text': str(result)
|
49 |
+
}
|
50 |
+
|
51 |
+
addresses = AddressSummaryCrew().crew().kickoff(inputs=inputs_for_address)
|
52 |
+
json_addresses = None
|
53 |
+
if addresses.json_dict:
|
54 |
+
json_addresses = addresses.json_dict
|
55 |
+
if not json_addresses:
|
56 |
+
try:
|
57 |
+
json_addresses = json.loads(addresses.raw)
|
58 |
+
except json.JSONDecodeError as e:
|
59 |
+
print ("Error loading Crew Output for addresses")
|
60 |
+
return (result, None)
|
61 |
+
fig = filter_map(json_addresses["name"], json_addresses["lat"], json_addresses["lon"])
|
62 |
+
return (result, fig)
|
63 |
|
64 |
+
logger = logging.getLogger()
|
65 |
+
logger.setLevel(logging.INFO)
|
66 |
|
67 |
demo = gr.Interface(
|
68 |
title="Plan your itinerary with the help of AI",
|
69 |
+
description="Use this app to create a detailed itinerary on how to explore a new place. Itinerary is customized to your taste.",
|
70 |
fn=run,
|
71 |
inputs=["text", "text", gr.Slider(value=30, minimum=15, maximum=90, step=5),
|
72 |
gr.Slider(value=5, minimum=1, maximum=14, step=1),
|
73 |
gr.Checkbox(),
|
74 |
gr.Slider(value=100, minimum=20, maximum=1000, step=20)],
|
75 |
+
outputs=[
|
76 |
+
gr.Textbox(label="Complete Itinerary", show_copy_button=True, autoscroll=False),
|
77 |
+
gr.Plot(label="Venues on a Map")
|
78 |
+
]
|
79 |
)
|
80 |
demo.launch()
|
config/address_agents.yaml
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
address_summarizer:
|
2 |
+
role: >
|
3 |
+
Summarize Addresses into Latitude and Longitude coordinates
|
4 |
+
goal: >
|
5 |
+
You need to extract addresses from a provided text and convert those addresses into latitude and longitude coordinates so that they can be easily shown on a map
|
6 |
+
backstory: >
|
7 |
+
You are skilled at extracting addresses from lines of text into latitude and longitude coordinates
|
8 |
+
|
config/address_tasks.yaml
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
address_compilation_task:
|
2 |
+
description: >
|
3 |
+
Extract the list of addresses from {text} in convert them to latitudes and longitudes.
|
4 |
+
|
5 |
+
expected_output: >
|
6 |
+
Output is expected in simple JSON format with three lists. The first list should contain the name of the venue or the name of the restaurant and should be indexed by the keyword "name". The second list should contain the latitudes and indexed with the keyword "lat". The third list should contain the longitudes and indexed with the keyword "lon".
|
crew.py
CHANGED
@@ -48,7 +48,6 @@ class SurpriseTravelCrew():
|
|
48 |
llm=llm,
|
49 |
max_iter=1,
|
50 |
tools=[SerperDevTool(), ScrapeWebsiteTool()], # Example of custom tool, loaded at the beginning of file
|
51 |
-
verbose=True,
|
52 |
allow_delegation=False,
|
53 |
)
|
54 |
|
@@ -59,7 +58,6 @@ class SurpriseTravelCrew():
|
|
59 |
llm=llm,
|
60 |
max_iter=1,
|
61 |
tools=[SerperDevTool(), ScrapeWebsiteTool()],
|
62 |
-
verbose=True,
|
63 |
allow_delegation=False,
|
64 |
)
|
65 |
|
@@ -69,7 +67,6 @@ class SurpriseTravelCrew():
|
|
69 |
config=self.agents_config['itinerary_compiler'],
|
70 |
llm=llm,
|
71 |
max_iter=1,
|
72 |
-
verbose=True,
|
73 |
allow_delegation=False,
|
74 |
)
|
75 |
|
@@ -108,6 +105,40 @@ class SurpriseTravelCrew():
|
|
108 |
agents=self.agents, # Automatically created by the @agent decorator
|
109 |
tasks=self.tasks, # Automatically created by the @task decorator
|
110 |
process=Process.sequential,
|
111 |
-
verbose=True,
|
112 |
# process=Process.hierarchical, # In case you want to use that instead https://docs.crewai.com/how-to/Hierarchical/
|
113 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
llm=llm,
|
49 |
max_iter=1,
|
50 |
tools=[SerperDevTool(), ScrapeWebsiteTool()], # Example of custom tool, loaded at the beginning of file
|
|
|
51 |
allow_delegation=False,
|
52 |
)
|
53 |
|
|
|
58 |
llm=llm,
|
59 |
max_iter=1,
|
60 |
tools=[SerperDevTool(), ScrapeWebsiteTool()],
|
|
|
61 |
allow_delegation=False,
|
62 |
)
|
63 |
|
|
|
67 |
config=self.agents_config['itinerary_compiler'],
|
68 |
llm=llm,
|
69 |
max_iter=1,
|
|
|
70 |
allow_delegation=False,
|
71 |
)
|
72 |
|
|
|
105 |
agents=self.agents, # Automatically created by the @agent decorator
|
106 |
tasks=self.tasks, # Automatically created by the @task decorator
|
107 |
process=Process.sequential,
|
|
|
108 |
# process=Process.hierarchical, # In case you want to use that instead https://docs.crewai.com/how-to/Hierarchical/
|
109 |
)
|
110 |
+
|
111 |
+
|
112 |
+
@CrewBase
|
113 |
+
class AddressSummaryCrew():
|
114 |
+
"""Address Summary crew"""
|
115 |
+
agents_config = 'config/address_agents.yaml'
|
116 |
+
tasks_config = 'config/address_tasks.yaml'
|
117 |
+
|
118 |
+
@agent
|
119 |
+
def address_summarizer(self) -> Agent:
|
120 |
+
return Agent(
|
121 |
+
config=self.agents_config['address_summarizer'],
|
122 |
+
llm=llm,
|
123 |
+
max_iter=1,
|
124 |
+
allow_delegation=False,
|
125 |
+
)
|
126 |
+
|
127 |
+
@task
|
128 |
+
def address_compilation_task(self) -> Task:
|
129 |
+
return Task(
|
130 |
+
config=self.tasks_config['address_compilation_task'],
|
131 |
+
llm=llm,
|
132 |
+
max_iter=1,
|
133 |
+
agent=self.address_summarizer(),
|
134 |
+
)
|
135 |
+
|
136 |
+
@crew
|
137 |
+
def crew(self) -> Crew:
|
138 |
+
"""Creates the AddressSummary crew"""
|
139 |
+
crew = Crew(
|
140 |
+
agents=self.agents, # Automatically created by the @agent decorator
|
141 |
+
tasks=self.tasks, # Automatically created by the @task decorator
|
142 |
+
process=Process.sequential,
|
143 |
+
)
|
144 |
+
return crew
|