File size: 2,676 Bytes
488b328
 
1c19586
488b328
1c19586
 
 
488b328
1c19586
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
488b328
2582114
488b328
1c19586
488b328
 
 
 
2582114
 
 
488b328
 
1c19586
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
488b328
1c19586
 
488b328
 
 
1c19586
488b328
 
2582114
 
 
1c19586
 
d317083
1c19586
488b328
62eb936
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
#!/usr/bin/env python
import sys
import json
import gradio as gr
import plotly.graph_objects as go
import logging
from crew import SurpriseTravelCrew, AddressSummaryCrew

def filter_map(text_list, lat, lon):
    fig = go.Figure(go.Scattermapbox(
            lat=lat,
            lon=lon,
            mode='markers',
            marker=go.scattermapbox.Marker(
                size=11
            ),
            hovertext=text_list
        ))

    fig.update_layout(
        mapbox_style="open-street-map",
        hovermode='closest',
        mapbox=dict(
            bearing=0,
            center=go.layout.mapbox.Center(
                lat=lat[1],
                lon=lon[1]
            ),
            pitch=0,
            zoom=10
        ),
    )
    return fig

def run(origin, destination, age, trip_duration, children, budget):
    # Replace with your inputs, it will automatically interpolate any tasks and agents information
    logger.info(f"Origin: {origin}, Destination: {destination}, Age: {age}, Duration: {trip_duration}, Children: {children}, Daily Budget: {budget}")
    inputs = {
        'origin': origin,
        'destination': destination,
        'age': age,
        'trip_duration': trip_duration,
        'children': children,
        'budget': budget
    }
    result = SurpriseTravelCrew().crew().kickoff(inputs=inputs)
    inputs_for_address = {
        'text': str(result)
    }

    addresses = AddressSummaryCrew().crew().kickoff(inputs=inputs_for_address)
    json_addresses = None
    if addresses.json_dict:
        json_addresses = addresses.json_dict
    if not json_addresses:
        try:
            json_addresses = json.loads(addresses.raw)
        except json.JSONDecodeError as e:
            print ("Error loading Crew Output for addresses")
            return (result, None)
    fig = filter_map(json_addresses["name"], json_addresses["lat"], json_addresses["lon"])
    return (result, fig)

logger = logging.getLogger()
logger.setLevel(logging.INFO)

demo = gr.Interface(
    title="Plan your itinerary with the help of AI",
    description="Use this app to create a detailed itinerary on how to explore a new place. Itinerary is customized to your taste.",
    fn=run,
    inputs=["text", "text", gr.Slider(value=30, minimum=15, maximum=90, step=5), 
            gr.Slider(value=5, minimum=1, maximum=14, step=1),
            gr.Checkbox(),
            gr.Slider(value=100, minimum=20, maximum=1000, step=20)],
    outputs=[
        gr.Textbox(label="Complete Itinerary", show_copy_button=True, autoscroll=False),
        gr.Plot(label="Venues on a Map. Please verify with a Navigation System before going")
    ]
)
demo.launch()