File size: 6,956 Bytes
014f597 1d0b9d1 89c9126 35aeee0 89c9126 44e58a6 c6542ed 6269c32 89c9126 6bdfadb 35aeee0 6bdfadb 44e58a6 6bdfadb 89c9126 6bdfadb 44e58a6 35aeee0 44e58a6 89c9126 6bdfadb 35aeee0 89c9126 b139634 89c9126 1d0b9d1 89c9126 014f597 6bdfadb 35aeee0 89c9126 6bdfadb 35aeee0 6bdfadb 44e58a6 6bdfadb b139634 6bdfadb c6542ed 35aeee0 c6542ed 6269c32 35aeee0 6269c32 6bdfadb 97a44d4 d07810d 97a44d4 d07810d 97a44d4 d07810d d69ce5a d07810d d69ce5a 6bdfadb 97a44d4 b139634 44e58a6 b139634 c6542ed 6269c32 97a44d4 6bdfadb 89c9126 b139634 89c9126 1d0b9d1 89c9126 97a44d4 1d0b9d1 014f597 1d0b9d1 014f597 1d0b9d1 |
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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
import gradio as gr
# Local modules
import fastf1_tools
from utils.constants import (
DRIVER_NAMES,
CONSTRUCTOR_NAMES,
CURRENT_YEAR,
AVAILABLE_SESSION_TYPES,
DROPDOWN_SESSION_TYPES,
DRIVER_DETAILS
)
iface_driver_championship_standings = gr.Interface(
fn=fastf1_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=fastf1_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=fastf1_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=fastf1_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=fastf1_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"
)
iface_session_results = gr.Interface(
fn=fastf1_tools.get_session_results,
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.Dropdown([session_type for session_type in DROPDOWN_SESSION_TYPES if "practice" not in session_type], label="Session type", value="race")
],
outputs=gr.DataFrame(),
title="Session Results",
description="Get the session results for the given Grand Prix"
)
iface_driver_info = gr.Interface(
fn=fastf1_tools.get_driver_info,
inputs=[
gr.Dropdown(label="Driver", choices=DRIVER_NAMES)
],
outputs="text",
title="Driver Info",
description="Get personal information about a driver"
)
# Create your markdown-only tab using Blocks
with gr.Blocks() as markdown_tab:
gr.Markdown("""
# π Formula 1 MCP server ποΈ
Welcome to the Formula 1 MCP server, your one-stop destination for comprehensive Formula 1 data and visualizations.
<br>
This application leverages the FastF1 library to provide detailed insights into Formula 1 races, drivers, and teams.
## Available Tools in Gradio UI
### Championship Standings
- **Driver Championship**: Track driver positions, points, and wins
- **Constructor Championship**: Monitor team performances and rankings
### Race Information
- **Event Info**: Get detailed information about specific Grand Prix events
- **Season Calendar**: View the complete race calendar for any season
- **Session Results**: Access race, qualifying, and sprint session results
### Driver & Team Data
- **Driver Info**: View detailed driver profiles and statistics
- **Track Visualizations**: Explore interactive track maps with speed, gear, and corner data
## Usage
There are different ways to interact with the MCP server:
1) (recommended) Add the MCP server to your `mcp.json` file. This is the most user-friendly way to interact with the MCP server. See the section below for the config file.
2) (not recommended) One can establish an MCP client by running `mcp_client.py` locally. This client is connected to the MCP server hosted on HuggingFace spaces. Warning: I personally had trouble getting this to work properly using local Ollama models.
3) (limited functionality) One can also use the Gradio interface directly to interact with the MCP server. However, I have limited the number of tools/functions available in the Gradio interface due to there not being a clean and nice way to implement the `OpenF1` tools in Gradio (literally just direct HTTP endpoints with tons of filters xD).
## MCP json configuration
For MCP clients that support SSE transport (For Claude desktop see below), the following configuration can be used in your `mcp.json` file (or its equivalent):
```json
{
"mcpServers": {
"gradio": {
"url": "https://agents-mcp-hackathon-f1-mcp-server.hf.space/gradio_api/mcp/sse"
}
}
}
```
For Claude Desktop, the following configuration can instead be used, but make sure you have Node.js installed:
```json
{
"mcpServers": {
"gradio": {
"command": "npx",
"args": [
"mcp-remote",
"https://agents-mcp-hackathon-f1-mcp-server.hf.space/gradio_api/mcp/sse",
"--transport",
"sse-only"
]
}
}
}
```
""")
named_interfaces = {
"About": markdown_tab,
"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,
"Session Results": iface_session_results,
"Driver Info": iface_driver_info,
}
# 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) |