introduction is written in HTML now
Browse files- app.py +4 -1
- utils/constants.py +129 -31
app.py
CHANGED
@@ -9,6 +9,7 @@ from utils.constants import (
|
|
9 |
CURRENT_YEAR,
|
10 |
DROPDOWN_SESSION_TYPES,
|
11 |
MARKDOWN_INTRODUCTION,
|
|
|
12 |
MARKDOWN_OPENF1_EXAMPLES,
|
13 |
OPENF1_TOOL_DESCRIPTION,
|
14 |
CONSTRUCTORS_PER_SEASON,
|
@@ -134,9 +135,11 @@ iface_constructor_info = gr.Interface(
|
|
134 |
)
|
135 |
|
136 |
|
|
|
137 |
# About introduction tab
|
138 |
with gr.Blocks() as markdown_tab:
|
139 |
-
gr.Markdown(MARKDOWN_INTRODUCTION)
|
|
|
140 |
|
141 |
|
142 |
# OpenF1 tools tab
|
|
|
9 |
CURRENT_YEAR,
|
10 |
DROPDOWN_SESSION_TYPES,
|
11 |
MARKDOWN_INTRODUCTION,
|
12 |
+
HTML_INTRODUCTION,
|
13 |
MARKDOWN_OPENF1_EXAMPLES,
|
14 |
OPENF1_TOOL_DESCRIPTION,
|
15 |
CONSTRUCTORS_PER_SEASON,
|
|
|
135 |
)
|
136 |
|
137 |
|
138 |
+
|
139 |
# About introduction tab
|
140 |
with gr.Blocks() as markdown_tab:
|
141 |
+
#gr.Markdown(MARKDOWN_INTRODUCTION)
|
142 |
+
gr.HTML(HTML_INTRODUCTION)
|
143 |
|
144 |
|
145 |
# OpenF1 tools tab
|
utils/constants.py
CHANGED
@@ -36,6 +36,52 @@ CONSTRUCTORS_PER_SEASON: dict[int, list[str]] = json.load(open("assets/construct
|
|
36 |
# Load in driver per season
|
37 |
DRIVERS_PER_SEASON: dict[int, list[str]] = json.load(open("assets/drivers_per_season.json"))
|
38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
MARKDOWN_INTRODUCTION = f"""
|
40 |
# 🏁 Formula 1 MCP server 🏎️
|
41 |
|
@@ -45,10 +91,15 @@ This application leverages the FastF1 library and OpenF1 API to provide detailed
|
|
45 |
|
46 |
## Video Demonstration & Submissions
|
47 |
|
48 |
-
|
|
|
|
|
|
|
|
|
|
|
49 |
<!-- <iframe src="https://www.loom.com/embed/4e0a5dbf7b8e4c428a7e2a8a8a8edc3b" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;"></iframe> -->
|
50 |
|
51 |
-
## Architecture
|
52 |
|
53 |
<img src="data:image/png;base64,{IMAGE_BASE64}" width="800" />
|
54 |
|
@@ -117,46 +168,93 @@ For Claude Desktop, the following configuration can instead be used, but make su
|
|
117 |
"""
|
118 |
|
119 |
|
120 |
-
|
121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
|
123 |
-
|
124 |
-
|
125 |
-
The API exposes several **_endpoints_** that can be used to access different types of real-time and historical data about Formula 1 races, sessions, drivers, and constructor teams.
|
126 |
-
Each of these endpoints have different **_filters_** that can be used to specify the data returned from the endpoint. The data communication is entirely in JSON format making it optimized for the LLM.
|
127 |
|
128 |
-
The implemented functions make it possible to:
|
129 |
-
- Get all available endpoints - `get_api_endpoints()`
|
130 |
-
- Get api string for a specific endpoint - `get_api_endpoint(endpoint)`
|
131 |
-
- Get details about a specific endpoint - `get_endpoint_info(endpoint)`
|
132 |
-
- Get information about a specific filter - `get_filter_info(filter_name)`
|
133 |
-
- Get a filter string for a specific filter - `get_filter_string(filter_name, filter_value, operator)`
|
134 |
-
- Apply filters to an API string - `apply_filters(api_string, *filters)`
|
135 |
-
- Send a request to the OpenF1 API - `send_request(api_string)`
|
136 |
|
137 |
-
The inputs are strings while the output is a JSON object. The examples are listed in an order that would be expected to be used in a real-life scenario. Some example API strings are listed below in the final tool `send_request(api_string)`.
|
138 |
|
139 |
-
"""
|
140 |
|
|
|
|
|
141 |
|
142 |
-
MARKDOWN_OPENF1_EXAMPLES = """
|
143 |
|
144 |
-
Retrieve data about car number 55 with session_key 9159 where the speed was greater than 315 <br>
|
145 |
-
```https://api.openf1.org/v1/car_data?driver_number=55&session_key=9159&speed>=315```
|
146 |
|
147 |
-
Retrieve data about driver number 1 with session_key 9158 <br>
|
148 |
-
```https://api.openf1.org/v1/drivers?driver_number=1&session_key=9158```
|
149 |
|
150 |
-
|
151 |
-
|
152 |
|
153 |
-
|
154 |
-
|
|
|
|
|
|
|
|
|
155 |
|
156 |
-
|
157 |
-
|
|
|
|
|
|
|
|
|
158 |
|
159 |
-
|
160 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
|
162 |
"""
|
|
|
|
|
|
36 |
# Load in driver per season
|
37 |
DRIVERS_PER_SEASON: dict[int, list[str]] = json.load(open("assets/drivers_per_season.json"))
|
38 |
|
39 |
+
OPENF1_TOOL_DESCRIPTION = """
|
40 |
+
## OpenF1 Tools - API Endpoints.
|
41 |
+
|
42 |
+
This UI Interface/Tab collects all the MCP tools that are based on the `OpenF1` API, which are a bit less user friendly compared to the tools in the other tabs, which are implemented using the `FastF1` library.
|
43 |
+
In essence, the tools listed below make it possible to access the `OpenF1` API directly within the MCP server, thus allowing a LLM to interact with the `OpenF1` API using natural language.
|
44 |
+
The API exposes several **_endpoints_** that can be used to access different types of real-time and historical data about Formula 1 races, sessions, drivers, and constructor teams.
|
45 |
+
Each of these endpoints have different **_filters_** that can be used to specify the data returned from the endpoint. The data communication is entirely in JSON format making it optimized for the LLM.
|
46 |
+
|
47 |
+
The implemented functions make it possible to:
|
48 |
+
- Get all available endpoints - `get_api_endpoints()`
|
49 |
+
- Get api string for a specific endpoint - `get_api_endpoint(endpoint)`
|
50 |
+
- Get details about a specific endpoint - `get_endpoint_info(endpoint)`
|
51 |
+
- Get information about a specific filter - `get_filter_info(filter_name)`
|
52 |
+
- Get a filter string for a specific filter - `get_filter_string(filter_name, filter_value, operator)`
|
53 |
+
- Apply filters to an API string - `apply_filters(api_string, *filters)`
|
54 |
+
- Send a request to the OpenF1 API - `send_request(api_string)`
|
55 |
+
|
56 |
+
The inputs are strings while the output is a JSON object. The examples are listed in an order that would be expected to be used in a real-life scenario. Some example API strings are listed below in the final tool `send_request(api_string)`.
|
57 |
+
|
58 |
+
"""
|
59 |
+
|
60 |
+
|
61 |
+
MARKDOWN_OPENF1_EXAMPLES = """
|
62 |
+
|
63 |
+
Retrieve data about car number 55 with session_key 9159 where the speed was greater than 315 <br>
|
64 |
+
```https://api.openf1.org/v1/car_data?driver_number=55&session_key=9159&speed>=315```
|
65 |
+
|
66 |
+
Retrieve data about driver number 1 with session_key 9158 <br>
|
67 |
+
```https://api.openf1.org/v1/drivers?driver_number=1&session_key=9158```
|
68 |
+
|
69 |
+
Retrieve data about intervals with session_key 9165 where the interval was less than 0.005s <br>
|
70 |
+
```https://api.openf1.org/v1/intervals?session_key=9165&interval<0.005```
|
71 |
+
|
72 |
+
Retrieve data about laps with session_key 9161 for driver number 63 on lap number 8 <br>
|
73 |
+
```https://api.openf1.org/v1/laps?session_key=9161&driver_number=63&lap_number=8```
|
74 |
+
|
75 |
+
Retrieve data about meetings in 2023 for Singapore <br>
|
76 |
+
```https://api.openf1.org/v1/meetings?year=2023&country_name=Singapore```
|
77 |
+
|
78 |
+
Retrieve data about pit stops with session_key 9158 where the pit duration was less than 31s <br>
|
79 |
+
```https://api.openf1.org/v1/pit?session_key=9158&pit_duration<31```
|
80 |
+
|
81 |
+
"""
|
82 |
+
|
83 |
+
|
84 |
+
|
85 |
MARKDOWN_INTRODUCTION = f"""
|
86 |
# 🏁 Formula 1 MCP server 🏎️
|
87 |
|
|
|
91 |
|
92 |
## Video Demonstration & Submissions
|
93 |
|
94 |
+
### Short demo (Claude Desktop)
|
95 |
+
Minimalistic demo of the MCP server using Claude Desktop.
|
96 |
+
<!-- <iframe src="https://www.loom.com/embed/4e0a5dbf7b8e4c428a7e2a8a8a8edc3b" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;"></iframe> -->
|
97 |
+
|
98 |
+
### Longer demo and yap sesh (Gradio UI + mcp_client.py + Claude Desktop)
|
99 |
+
More in-depth demo of interacting with the MCP server using Gradio UI, mcp_client.py and Claude Desktop.
|
100 |
<!-- <iframe src="https://www.loom.com/embed/4e0a5dbf7b8e4c428a7e2a8a8a8edc3b" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;"></iframe> -->
|
101 |
|
102 |
+
## Architecture (Created with Excalidraw and icons from Lobehub)
|
103 |
|
104 |
<img src="data:image/png;base64,{IMAGE_BASE64}" width="800" />
|
105 |
|
|
|
168 |
"""
|
169 |
|
170 |
|
171 |
+
HTML_INTRODUCTION = f"""
|
172 |
+
<!DOCTYPE html>
|
173 |
+
<html>
|
174 |
+
<head>
|
175 |
+
<title>Formula 1 MCP Server</title>
|
176 |
+
</head>
|
177 |
+
<body>
|
178 |
+
<h1>Formula 1 MCP Server</h1>
|
179 |
+
<p>Welcome to the Formula 1 MCP server, your one-stop destination for Formula 1 data retrieval and race real-time race strategy analysis.</p>
|
180 |
+
<p>This application leverages the FastF1 library and OpenF1 API to provide detailed insights into Formula 1 races, drivers, and teams.</p>
|
181 |
+
<h2>Video Demonstration & Submissions</h2>
|
182 |
+
<h3>Short demo (Claude Desktop)</h3>
|
183 |
|
184 |
+
<p>Minimalistic demo of the MCP server using Claude Desktop.</p>
|
185 |
+
<iframe width="800" height="499" src="https://www.loom.com/embed/4ef9cf2e691143db8e5d807a1aef9672?sid=2acf26b1-49a0-4157-ac6b-3fdf08be8ea2" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
|
|
|
|
|
186 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
187 |
|
|
|
188 |
|
|
|
189 |
|
190 |
+
<h3>Longer demo and yap sesh (Gradio UI + mcp_client.py + Claude Desktop)</h3>
|
191 |
+
<p>More in-depth demo of interacting with the MCP server using Gradio UI, mcp_client.py and Claude Desktop.</p>
|
192 |
|
|
|
193 |
|
|
|
|
|
194 |
|
|
|
|
|
195 |
|
196 |
+
<h2>Architecture (Created with Excalidraw and icons from Lobehub)</h2>
|
197 |
+
<img src="data:image/png;base64,{IMAGE_BASE64}" width="800" />
|
198 |
|
199 |
+
<h2>Available Tools in Gradio UI</h2>
|
200 |
+
<h3>Championship Standings</h3>
|
201 |
+
<ul>
|
202 |
+
<li>Driver Standings: Retrieve live or past driver championship standings for a specific driver</li>
|
203 |
+
<li>Constructor Standings: Retrieve live or past constructor championship standings for a specific constructor</li>
|
204 |
+
</ul>
|
205 |
|
206 |
+
<h3>Race Information</h3>
|
207 |
+
<ul>
|
208 |
+
<li>Event Info: Get detailed information about a specific Grand Prix event</li>
|
209 |
+
<li>Season Calendar: View the complete race calendar for any season</li>
|
210 |
+
<li>Session Results: Access race, qualifying, and sprint session results</li>
|
211 |
+
</ul>
|
212 |
|
213 |
+
<h3>Driver & Team Data</h3>
|
214 |
+
<ul>
|
215 |
+
<li>Driver Info: Retrieve detailed driver information from the 2025 Formula 1 season</li>
|
216 |
+
<li>Constructor Info: Retrieve detailed constructor information from the 2025 Formula 1 season</li>
|
217 |
+
<li>Track Visualizations: Explore interactive track maps with speed, gear, and corner visualizations</li>
|
218 |
+
</ul>
|
219 |
+
|
220 |
+
<h3>OpenF1 Tools</h3>
|
221 |
+
<ul>
|
222 |
+
<li>OpenF1 Tools: Access the OpenF1 API directly within the MCP server, allowing a LLM to interact with the API using natural language.</li>
|
223 |
+
</ul>
|
224 |
+
""" + """
|
225 |
+
|
226 |
+
<h2>MCP json configuration file</h2>
|
227 |
+
<p>For MCP clients that support SSE transport (For Claude desktop see below), the following configuration can be used in your <code>mcp.json</code> file (or its equivalent):</p>
|
228 |
+
<pre><code>
|
229 |
+
{
|
230 |
+
"mcpServers": {
|
231 |
+
"gradio": {
|
232 |
+
"url": "https://agents-mcp-hackathon-f1-mcp-server.hf.space/gradio_api/mcp/sse"
|
233 |
+
}
|
234 |
+
}
|
235 |
+
}
|
236 |
+
</code></pre>
|
237 |
+
|
238 |
+
<p>For Claude Desktop, the following configuration can instead be used, but make sure you have Node.js installed:</p>
|
239 |
+
<pre><code>
|
240 |
+
{
|
241 |
+
"mcpServers": {
|
242 |
+
"gradio": {
|
243 |
+
"command": "npx",
|
244 |
+
"args": [
|
245 |
+
"mcp-remote",
|
246 |
+
"https://agents-mcp-hackathon-f1-mcp-server.hf.space/gradio_api/mcp/sse",
|
247 |
+
"--transport",
|
248 |
+
"sse-only"
|
249 |
+
]
|
250 |
+
}
|
251 |
+
}
|
252 |
+
}
|
253 |
+
</code></pre>
|
254 |
+
|
255 |
+
</body>
|
256 |
+
</html>
|
257 |
|
258 |
"""
|
259 |
+
|
260 |
+
|