f1-mcp-server / app.py
arre99's picture
added constructors standings and tidied up the UI for driver standings
44e58a6
raw
history blame
3.09 kB
import gradio as gr
# Local modules
import tools
from utils.constants import (
DRIVER_NAMES,
CONSTRUCTOR_NAMES,
CURRENT_YEAR
)
iface_driver_championship_standings = gr.Interface(
fn=tools.driver_championship_standings,
inputs=[
gr.Number(label="Calendar year", value=CURRENT_YEAR, minimum=1950, maximum=CURRENT_YEAR),
gr.Dropdown(label="Driver", choices=DRIVER_NAMES)
],
outputs="text",
title="Driver Championship Standings",
description="Get the driver championship standings"
)
iface_constructor_championship_standings = gr.Interface(
fn=tools.constructor_championship_standings,
inputs=[
gr.Number(label="Calendar year", value=CURRENT_YEAR, minimum=1950, maximum=CURRENT_YEAR),
gr.Dropdown(label="Constructor", choices=CONSTRUCTOR_NAMES)
],
outputs="text",
title="Constructor Championship Standings",
description="Get the constructor championship standings"
)
iface_event_info = gr.Interface(
fn=tools.get_event_info,
inputs=[
gr.Number(label="Calendar year", value=CURRENT_YEAR, minimum=1950, maximum=CURRENT_YEAR),
gr.Textbox(label="Grand Prix", placeholder="Ex: Monaco", info="The name of the GP/country/location (Fuzzy matching supported)"),
gr.Radio(["human", "LLM"], label="Display format", value="human")
],
outputs="text",
title="Event Info",
description="Get the Grand Prix event info for a specific race week"
)
iface_season_calendar = gr.Interface(
fn=tools.get_season_calendar,
inputs=[
gr.Number(label="Calendar year", value=CURRENT_YEAR, minimum=1950, maximum=CURRENT_YEAR),
],
outputs="text",
title="Season Calendar",
description="Get the season calendar information for the given year"
)
iface_track_visualization = gr.Interface(
fn=tools.track_visualization,
inputs=[
gr.Number(label="Calendar year", value=CURRENT_YEAR, minimum=1950, maximum=CURRENT_YEAR),
gr.Textbox(label="Grand Prix", placeholder="Ex: Monaco", info="The name of the GP/country/location (Fuzzy matching supported)"),
gr.Radio(["speed", "corners", "gear"], label="Visualization type", value="speed"),
gr.Dropdown(DRIVER_NAMES)
],
outputs="image",
title="Track Visualizations",
description="Get the track visualization for the given Grand Prix"
)
named_interfaces = {
"Driver Championship Standings": iface_driver_championship_standings,
"Constructor Championship Standings": iface_constructor_championship_standings,
"Event Info": iface_event_info,
"Season Calendar": iface_season_calendar,
"Track Visualizations": iface_track_visualization
}
# Tab names and interfaces
tab_names = list(named_interfaces.keys())
interface_list = list(named_interfaces.values())
# Combine all the interfaces into a single TabbedInterface
gradio_server = gr.TabbedInterface(
interface_list,
tab_names=tab_names,
title="Formula 1 MCP server"
)
# Launch the interface and MCP server
if __name__ == "__main__":
gradio_server.launch(mcp_server=True)