| import os |
| import gradio as gr |
|
|
| from tools import ( |
| geo_search_address, |
| validate_address, |
| cityinfra_lookup_asset, |
| get_nearby_reports, |
| weather_get_current, |
| get_department_info, |
| pdf_generate_report, |
| sendgrid_send_email, |
| ) |
|
|
|
|
| |
| geo_interface = gr.Interface( |
| fn=geo_search_address, |
| inputs=[ |
| gr.Number(label="Latitude", value=40.7580), |
| gr.Number(label="Longitude", value=-73.9855) |
| ], |
| outputs=gr.JSON(label="Location Data"), |
| title="Geo Search Address", |
| description="Reverse geocode coordinates to NYC address with borough detection", |
| api_name="geo_search_address" |
| ) |
|
|
| validate_interface = gr.Interface( |
| fn=validate_address, |
| inputs=[ |
| gr.Textbox(label="Address", value="123 Broadway, Manhattan, NY") |
| ], |
| outputs=gr.JSON(label="Validation Result"), |
| title="Validate Address", |
| description="Validate and normalize NYC address with borough detection", |
| api_name="validate_address" |
| ) |
|
|
| asset_interface = gr.Interface( |
| fn=cityinfra_lookup_asset, |
| inputs=[ |
| gr.Textbox(label="Address", value="123 Broadway"), |
| gr.Dropdown( |
| label="Asset Type", |
| choices=["road", "streetlight", "drain", "sidewalk", "traffic_signal", "fire_hydrant"], |
| value="road" |
| ) |
| ], |
| outputs=gr.JSON(label="Asset Data"), |
| title="City Infrastructure Lookup", |
| description="Look up NYC infrastructure asset records with condition rating", |
| api_name="cityinfra_lookup_asset" |
| ) |
|
|
| nearby_interface = gr.Interface( |
| fn=get_nearby_reports, |
| inputs=[ |
| gr.Textbox(label="Address", value="123 Broadway"), |
| gr.Textbox(label="Issue Type", value="pothole"), |
| gr.Slider(label="Radius (blocks)", minimum=1, maximum=10, value=3, step=1) |
| ], |
| outputs=gr.JSON(label="Nearby Reports"), |
| title="Get Nearby Reports", |
| description="Find similar infrastructure reports near an address", |
| api_name="get_nearby_reports" |
| ) |
|
|
| weather_interface = gr.Interface( |
| fn=weather_get_current, |
| inputs=[ |
| gr.Number(label="Latitude", value=40.7580), |
| gr.Number(label="Longitude", value=-73.9855) |
| ], |
| outputs=gr.JSON(label="Weather Data"), |
| title="Weather Current", |
| description="Get current weather with hazard assessment for infrastructure", |
| api_name="weather_get_current" |
| ) |
|
|
| dept_interface = gr.Interface( |
| fn=get_department_info, |
| inputs=[ |
| gr.Dropdown( |
| label="Department Code", |
| choices=["DOT", "DEP", "DSNY", "FDNY", "311"], |
| value="DOT" |
| ) |
| ], |
| outputs=gr.JSON(label="Department Info"), |
| title="Department Information", |
| description="Get NYC department contact info and response times", |
| api_name="get_department_info" |
| ) |
|
|
| pdf_interface = gr.Interface( |
| fn=pdf_generate_report, |
| inputs=[ |
| gr.Textbox(label="Issue Type", value="pothole"), |
| gr.Textbox(label="Address", value="123 Broadway"), |
| gr.Dropdown(label="Urgency", choices=["low", "medium", "high", "critical"], value="medium"), |
| gr.Textbox(label="Description", lines=3, value="Large pothole causing traffic issues") |
| ], |
| outputs=gr.JSON(label="Report Data"), |
| title="Generate PDF Report", |
| description="Generate a PDF report from infrastructure issue data", |
| api_name="pdf_generate_report" |
| ) |
|
|
| email_interface = gr.Interface( |
| fn=sendgrid_send_email, |
| inputs=[ |
| gr.Textbox(label="To", value="311@nyc.gov"), |
| gr.Textbox(label="Subject", value="Infrastructure Issue Report"), |
| gr.Textbox(label="Body", lines=3, value="Please see attached report for infrastructure issue details."), |
| gr.Textbox(label="API Key (optional)", value="", type="password", placeholder="Resend API key (or set RESEND_API_KEY env var)"), |
| gr.Textbox(label="From Email (optional)", value="", placeholder="Sender email (or set RESEND_FROM_EMAIL env var)"), |
| gr.Textbox(label="Report ID (optional)", value="", placeholder="Report ID to attach PDF (e.g., FMN-20251127050500)") |
| ], |
| outputs=gr.JSON(label="Email Status"), |
| title="Send Email", |
| description="Send email report to municipal department with optional PDF attachment.", |
| api_name="sendgrid_send_email" |
| ) |
|
|
| |
| GRADIO_THEME = os.getenv("GRADIO_THEME", "gstaff/xkcd") |
| theme = gr.Theme.from_hub(GRADIO_THEME) |
|
|
| |
| demo = gr.TabbedInterface( |
| [ |
| geo_interface, |
| validate_interface, |
| asset_interface, |
| nearby_interface, |
| weather_interface, |
| dept_interface, |
| pdf_interface, |
| email_interface, |
| ], |
| [ |
| "Geocode", |
| "Validate", |
| "Assets", |
| "Nearby", |
| "Weather", |
| "Departments", |
| "PDF Report", |
| "Send Email", |
| ], |
| title="FixMyNeighborhood MCP Server", |
| ) |
|
|
| if __name__ == "__main__": |
| |
| |
| demo.launch(mcp_server=True, theme=theme) |
|
|