File size: 5,327 Bytes
b2ff92e 96d425d b2ff92e 96d425d b2ff92e 96d425d b2ff92e 96d425d b2ff92e 96d425d b2ff92e 96d425d b2ff92e 96d425d b2ff92e 96d425d b2ff92e 96d425d 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 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 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
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()
|