|
import gradio as gr |
|
from camptocamp_api import CamptocampAPI |
|
from typing import Tuple, Optional |
|
|
|
|
|
|
|
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() |
|
|