File size: 4,589 Bytes
264bb5c
c2e4a2f
 
264bb5c
3081c81
74c8d32
 
 
 
 
 
 
 
 
 
264bb5c
 
3081c81
c2e4a2f
3081c81
 
 
 
 
 
 
 
 
 
 
 
 
 
135d1c5
c2e4a2f
135d1c5
 
 
 
 
 
 
 
 
 
 
c2e4a2f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135d1c5
 
74c8d32
 
 
 
 
 
 
 
 
 
 
c2e4a2f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16aef61
 
 
 
 
 
74c8d32
 
 
 
 
 
c2e4a2f
 
 
 
74c8d32
 
 
 
264bb5c
3081c81
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
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

# --- 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="image",
    title="Generate Route Map",
    description="Extract route image and optionally add custom title overlay."
)

# --- 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
    
    ## 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
    
    ## 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],
    ["About", "Address Geocoding", "Distance Calculator", "Route Planner",
     "Extract Time", "Extract Distance", "Route Map"],
    title="🌍 Geocalc MCP Server"
)

# --- Launch the Server ---
if __name__ == "__main__":
    demo.launch(mcp_server=True, debug=True)