File size: 3,448 Bytes
b2ff92e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from camptocamp_api import CamptocampAPI
from typing import Tuple, Optional


# Instantiate API
c2c = CamptocampAPI(language="en")

def get_recent_outings(
    west: float, south: float, east: float, north: float,
    start_date: Optional[str], end_date: Optional[str],
    activity: Optional[str], limit: int
):
    bbox = (west, south, east, north)
    date_range = (start_date, end_date) if start_date and end_date else None
    return c2c.get_recent_outings(bbox, date_range, activity, limit)

def search_routes_by_activity(
    west: float, south: float, east: float, north: float,
    activity: str, limit: int
):
    bbox = (west, south, east, north)
    return c2c.search_routes_by_activity(bbox, activity, limit)

def get_route_details(route_id: int):
    return c2c.get_route_details(route_id)

def search_waypoints(
    west: float, south: float, east: float, north: float,
    limit: int
):
    bbox = (west, south, east, north)
    return c2c.search_waypoints(bbox, limit)


with gr.Blocks(title="Camptocamp API MCP") as demo:
    gr.Markdown("# 🏔️ Camptocamp API Interface")

    with gr.Tab("Recent Outings"):
        with gr.Row():
            west = gr.Number(label="West")
            south = gr.Number(label="South")
            east = gr.Number(label="East")
            north = gr.Number(label="North")
        with gr.Row():
            start_date = gr.Textbox(label="Start Date (YYYY-MM-DD)")
            end_date = gr.Textbox(label="End Date (YYYY-MM-DD)")
            activity = gr.Textbox(label="Activity (e.g. hiking, skiing)")
            limit = gr.Number(label="Limit", value=5)
        outings_output = gr.JSON()
        outings_btn = gr.Button("Get Outings")
        outings_btn.click(get_recent_outings,
                          inputs=[west, south, east, north, start_date, end_date, activity, limit],
                          outputs=outings_output)

    with gr.Tab("Routes"):
        with gr.Row():
            r_west = gr.Number(label="West")
            r_south = gr.Number(label="South")
            r_east = gr.Number(label="East")
            r_north = gr.Number(label="North")
        r_activity = gr.Textbox(label="Activity")
        r_limit = gr.Number(label="Limit", value=5)
        route_output = gr.JSON()
        route_btn = gr.Button("Search Routes")
        route_btn.click(search_routes_by_activity,
                        inputs=[r_west, r_south, r_east, r_north, r_activity, r_limit],
                        outputs=route_output)

    with gr.Tab("Route Details"):
        route_id_input = gr.Number(label="Route ID")
        route_details_output = gr.JSON()
        route_details_btn = gr.Button("Get Route Details")
        route_details_btn.click(get_route_details,
                                inputs=[route_id_input],
                                outputs=route_details_output)

    with gr.Tab("Waypoints"):
        with gr.Row():
            w_west = gr.Number(label="West")
            w_south = gr.Number(label="South")
            w_east = gr.Number(label="East")
            w_north = gr.Number(label="North")
        w_limit = gr.Number(label="Limit", value=5)
        waypoints_output = gr.JSON()
        waypoints_btn = gr.Button("Search Waypoints")
        waypoints_btn.click(search_waypoints,
                            inputs=[w_west, w_south, w_east, w_north, w_limit],
                            outputs=waypoints_output)

demo.launch()