import gradio as gr from camptocamp_api import CamptocampAPI from typing import Tuple, Optional # Instantiate the Camptocamp API wrapper c2c = CamptocampAPI(language="en") def get_recent_outings( west: float, south: float, east: float, north: float, start_date: Optional[str] = None, end_date: Optional[str] = None, activity: Optional[str] = None, limit: int = 10 ) -> dict: """ Get recent outings near a given location and date range. Args: west: Western longitude of the bounding box. south: Southern latitude of the bounding box. east: Eastern longitude of the bounding box. north: Northern latitude of the bounding box. start_date: Start of the date range (YYYY-MM-DD). end_date: End of the date range (YYYY-MM-DD). activity: Optional activity filter (e.g. "hiking", "rock_climbing"). limit: Number of results to return. Returns: JSON dictionary of matching outings. """ 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 = 10 ) -> dict: """ Search for climbing or hiking routes in a given region. Args: west: Western longitude of the bounding box. south: Southern latitude of the bounding box. east: Eastern longitude of the bounding box. north: Northern latitude of the bounding box. activity: Activity type (e.g. "rock_climbing", "hiking"). limit: Number of routes to return. Returns: JSON dictionary of matching route metadata. """ bbox = (west, south, east, north) return c2c.search_routes_by_activity(bbox, activity, limit) def get_route_details(route_id: int) -> dict: """ Retrieve detailed route information by route ID. Args: route_id: Unique numeric ID of the route. Returns: JSON dictionary of route information including description, grade, etc. """ return c2c.get_route_details(route_id) def search_waypoints( west: float, south: float, east: float, north: float, limit: int = 10 ) -> dict: """ Get known waypoints (e.g. huts, peaks, cols) in a given area. Args: west: Western longitude of the bounding box. south: Southern latitude of the bounding box. east: Eastern longitude of the bounding box. north: Northern latitude of the bounding box. limit: Maximum number of results. Returns: JSON dictionary of waypoints. """ bbox = (west, south, east, north) return c2c.search_waypoints(bbox, limit) # ========== Gradio UI Layer ========== 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()