Spaces:
Sleeping
Sleeping
import gradio as gr | |
from tools import get_coords_from_address, calculate_direct_distance, get_route_data, extract_route_time, \ | |
extract_route_distance, generate_route_image, get_points_of_interest | |
from route_utils import POI_CATEGORY_LIST | |
# --- Tools --- | |
geocoding_interface = gr.Interface( | |
fn=get_coords_from_address, | |
inputs=[ | |
gr.Textbox(label="Address", placeholder="e.g., 1600 Amphitheatre Parkway, Mountain View, CA") | |
], | |
outputs=[ | |
gr.Textbox(label="Coordinates (Lat, Lon)") | |
], | |
title="Address to Coordinates", | |
description="A tool to get the latitude and longitude for a given street address." | |
) | |
distance_interface = gr.Interface( | |
fn=calculate_direct_distance, | |
inputs=[ | |
gr.Number(label="Latitude Point A"), | |
gr.Number(label="Longitude Point A"), | |
gr.Number(label="Latitude Point B"), | |
gr.Number(label="Longitude Point B"), | |
gr.Radio(["km", "miles"], label="Unit", value="km") | |
], | |
outputs=[ | |
gr.Textbox(label="Distance") | |
], | |
title="Distance Calculator", | |
description="A tool to calculate the distance between two geographic points." | |
) | |
route_planner_interface = gr.Interface( | |
fn=get_route_data, | |
inputs=[ | |
gr.Number(label="Start Latitude"), | |
gr.Number(label="Start Longitude"), | |
gr.Number(label="End Latitude"), | |
gr.Number(label="End Longitude"), | |
gr.Dropdown(["car", "walk", "bike"], label="Mode of Transport", value="car") | |
], | |
outputs=[ | |
gr.Textbox(label="Route Details") | |
], | |
title="Route Planner", | |
description="Get optimized route data with pre-generated map image for visualization." | |
) | |
extract_time_interface = gr.Interface( | |
fn=extract_route_time, | |
inputs=gr.Textbox(label="Route Data (JSON)", lines=3), | |
outputs=gr.Textbox(label="Travel Time"), | |
title="Extract Route Time", | |
description="Extract human-readable travel time from route data" | |
) | |
extract_distance_interface = gr.Interface( | |
fn=extract_route_distance, | |
inputs=gr.Textbox(label="Route Data (JSON)", lines=3), | |
outputs=gr.Textbox(label="Distance"), | |
title="Extract Route Distance", | |
description="Extract distance in km from route data" | |
) | |
route_map_interface = gr.Interface( | |
fn=generate_route_image, | |
inputs=[ | |
gr.Textbox(label="Route Data (JSON)", lines=3), | |
gr.Textbox(label="Custom Title (Optional)", placeholder="e.g., My Route to Work") | |
], | |
outputs=gr.Image( | |
format="webp", | |
type="pil", | |
height=300, | |
width=400, | |
show_download_button=False, | |
interactive=False | |
), | |
title="Generate Route Map", | |
description="Extract route image and optionally add custom title overlay." | |
) | |
poi_interface = gr.Interface( | |
fn=get_points_of_interest, | |
inputs=[ | |
gr.Number(label="Latitude"), | |
gr.Number(label="Longitude"), | |
gr.Slider(0.1, 25.0, value=10.0, step=0.1, label="Search Radius (km)"), | |
gr.Dropdown( | |
POI_CATEGORY_LIST, | |
multiselect=True, | |
label="Categories", | |
info="Select POI categories to search for" | |
) | |
], | |
outputs=gr.Textbox(label="Points of Interest", lines=10), | |
title="Points of Interest", | |
description="Find nearby points of interest like restaurants, hotels, attractions, etc." | |
) | |
# --- About Tab --- | |
with gr.Blocks() as about_tab: | |
gr.Markdown(""" | |
# π Geocalc MCP Server | |
Welcome to the Geocalc MCP server. This application provides a collection of tools for geographic calculations. | |
This server is designed to be used by AI models (like LLMs) to perform geo-related tasks. | |
## Available Tools | |
### π Location Tools | |
- **Address Geocoding**: Converts a physical address into latitude and longitude coordinates | |
### π Distance Tools | |
- **Distance Calculator**: Calculates straight-line distance between two coordinates | |
- **Extract Route Distance**: Extracts the actual travel distance from route data | |
### π Route Planning | |
- **Route Planner**: Gets complete route data including geometry, distance and duration for car/walk/bike | |
- **Extract Route Time**: Extracts human-readable travel time from route data (e.g., "15 min", "1 h 23 min") | |
### πΊοΈ Visualization | |
- **Generate Route Map**: Extracts pre-generated route image with optional custom title overlay | |
### π Points of Interest | |
- **Points of Interest**: Find nearby restaurants, hotels, attractions, and other POIs within a specified radius | |
## Usage | |
These tools are designed to work together. For example: | |
1. Use Address Geocoding to get coordinates | |
2. Use Route Planner to get route data | |
3. Use Extract tools to get specific metrics | |
4. Use Generate Route Map to visualize the route | |
## π₯ Demo Video | |
[Watch the demo video](https://drive.google.com/file/d/1ii642MrCFl4k9Ikz7WXKtFXl5jiMBdmn/view?usp=sharing) to see how the MCP server works in action. | |
## Demo video points of interest tool | |
[Points of Interest Demo Video](https://drive.google.com/file/d/1j3rAkBMO2amTvQswnHrXbPuwW4zkTFZ4/view?usp=sharing) | |
## If you have any questions or feedback, please don't hesitate to reach me. | |
[GitHub](https://github.com/renzo4web) | |
[X](https://x.com/turbopila) | |
Use the tabs above to navigate to the desired tool. | |
""") | |
# --- Assemble the Tabbed Interface --- | |
demo = gr.TabbedInterface( | |
[about_tab, geocoding_interface, distance_interface, route_planner_interface, | |
extract_time_interface, extract_distance_interface, route_map_interface, poi_interface], | |
["About", "Address Geocoding", "Distance Calculator", "Route Planner", | |
"Extract Time", "Extract Distance", "Route Map", "Points of Interest"], | |
title="π Geocalc MCP Server" | |
) | |
# --- Launch the Server --- | |
if __name__ == "__main__": | |
demo.launch(mcp_server=True, debug=True) | |