renamed the mini functions inside the openf1 tool tab
Browse files
app.py
CHANGED
@@ -120,61 +120,61 @@ def openf1_tools_tab():
|
|
120 |
with gr.Accordion("get_api_endpoints()", open=False):
|
121 |
btn = gr.Button("Get all endpoints")
|
122 |
output = gr.JSON()
|
123 |
-
def
|
124 |
return openf1_tools.get_api_endpoints()
|
125 |
-
btn.click(
|
126 |
with gr.Accordion("get_api_endpoint(endpoint)", open=False):
|
127 |
endpoint_in = gr.Textbox(label="Endpoint", placeholder="e.g. sessions")
|
128 |
btn = gr.Button("Get endpoint info")
|
129 |
output = gr.JSON()
|
130 |
-
def
|
131 |
return openf1_tools.get_api_endpoint(endpoint)
|
132 |
-
btn.click(
|
133 |
with gr.Accordion("get_endpoint_info(endpoint)", open=False):
|
134 |
endpoint_in = gr.Textbox(label="Endpoint", placeholder="e.g. sessions")
|
135 |
btn = gr.Button("Get endpoint details")
|
136 |
output = gr.JSON()
|
137 |
-
def
|
138 |
return openf1_tools.get_endpoint_info(endpoint)
|
139 |
-
btn.click(
|
140 |
with gr.Accordion("get_filter_info(filter_name)", open=False):
|
141 |
filter_in = gr.Textbox(label="Filter name", placeholder="e.g. driver_number")
|
142 |
btn = gr.Button("Get filter info")
|
143 |
output = gr.JSON()
|
144 |
-
def
|
145 |
return openf1_tools.get_filter_info(filter_name)
|
146 |
-
btn.click(
|
147 |
with gr.Accordion("get_filter_string(filter_name, filter_value, operator)", open=False):
|
148 |
filter_name = gr.Textbox(label="Filter name", placeholder="e.g. driver_number")
|
149 |
filter_value = gr.Textbox(label="Filter value", placeholder="e.g. 16")
|
150 |
operator = gr.Dropdown(label="Operator", choices=["=", ">", "<", ">=", "<="], value="=")
|
151 |
btn = gr.Button("Get filter string")
|
152 |
output = gr.Textbox(label="Filter string", info="Example: driver_number=16&")
|
153 |
-
def
|
154 |
return openf1_tools.get_filter_string(filter_name, filter_value, operator)
|
155 |
-
btn.click(
|
156 |
with gr.Accordion("apply_filters(api_string, *filters)", open=False):
|
157 |
api_string = gr.Textbox(label="Base API string", placeholder="e.g. https://api.openf1.org/v1/sessions?")
|
158 |
filters = gr.Textbox(label="Filters (comma-separated)", placeholder="e.g. driver_number=16&,session_key=123&")
|
159 |
btn = gr.Button("Apply filters")
|
160 |
output = gr.Textbox(label="Full API string")
|
161 |
-
def
|
162 |
# Expect filters as comma-separated
|
163 |
filter_list = [f.strip() for f in filters.split(",") if f.strip()]
|
164 |
return openf1_tools.apply_filters(api_string, *filter_list)
|
165 |
-
btn.click(
|
166 |
with gr.Accordion("send_request(api_string)", open=False):
|
167 |
with gr.Accordion("Example API requests (copy & paste into text box below)", open=False):
|
168 |
gr.Markdown(MARKDOWN_OPENF1_EXAMPLES)
|
169 |
api_string = gr.Textbox(label="Full API string", placeholder="e.g. https://api.openf1.org/v1/sessions?driver_number=16")
|
170 |
btn = gr.Button("Send API request")
|
171 |
output = gr.JSON()
|
172 |
-
def
|
173 |
try:
|
174 |
return openf1_tools.send_request(api_string)
|
175 |
except Exception as e:
|
176 |
return {"error": str(e)}
|
177 |
-
btn.click(
|
178 |
return openf1_tools_tab
|
179 |
|
180 |
# OpenF1 tabs
|
|
|
120 |
with gr.Accordion("get_api_endpoints()", open=False):
|
121 |
btn = gr.Button("Get all endpoints")
|
122 |
output = gr.JSON()
|
123 |
+
def _get_api_endpoints():
|
124 |
return openf1_tools.get_api_endpoints()
|
125 |
+
btn.click(_get_api_endpoints, outputs=output)
|
126 |
with gr.Accordion("get_api_endpoint(endpoint)", open=False):
|
127 |
endpoint_in = gr.Textbox(label="Endpoint", placeholder="e.g. sessions")
|
128 |
btn = gr.Button("Get endpoint info")
|
129 |
output = gr.JSON()
|
130 |
+
def _get_api_endpoint(endpoint):
|
131 |
return openf1_tools.get_api_endpoint(endpoint)
|
132 |
+
btn.click(_get_api_endpoint, inputs=endpoint_in, outputs=output)
|
133 |
with gr.Accordion("get_endpoint_info(endpoint)", open=False):
|
134 |
endpoint_in = gr.Textbox(label="Endpoint", placeholder="e.g. sessions")
|
135 |
btn = gr.Button("Get endpoint details")
|
136 |
output = gr.JSON()
|
137 |
+
def _get_endpoint_info(endpoint):
|
138 |
return openf1_tools.get_endpoint_info(endpoint)
|
139 |
+
btn.click(_get_endpoint_info, inputs=endpoint_in, outputs=output)
|
140 |
with gr.Accordion("get_filter_info(filter_name)", open=False):
|
141 |
filter_in = gr.Textbox(label="Filter name", placeholder="e.g. driver_number")
|
142 |
btn = gr.Button("Get filter info")
|
143 |
output = gr.JSON()
|
144 |
+
def _get_filter_info(filter_name):
|
145 |
return openf1_tools.get_filter_info(filter_name)
|
146 |
+
btn.click(_get_filter_info, inputs=filter_in, outputs=output)
|
147 |
with gr.Accordion("get_filter_string(filter_name, filter_value, operator)", open=False):
|
148 |
filter_name = gr.Textbox(label="Filter name", placeholder="e.g. driver_number")
|
149 |
filter_value = gr.Textbox(label="Filter value", placeholder="e.g. 16")
|
150 |
operator = gr.Dropdown(label="Operator", choices=["=", ">", "<", ">=", "<="], value="=")
|
151 |
btn = gr.Button("Get filter string")
|
152 |
output = gr.Textbox(label="Filter string", info="Example: driver_number=16&")
|
153 |
+
def _get_filter_string(filter_name, filter_value, operator):
|
154 |
return openf1_tools.get_filter_string(filter_name, filter_value, operator)
|
155 |
+
btn.click(_get_filter_string, inputs=[filter_name, filter_value, operator], outputs=output)
|
156 |
with gr.Accordion("apply_filters(api_string, *filters)", open=False):
|
157 |
api_string = gr.Textbox(label="Base API string", placeholder="e.g. https://api.openf1.org/v1/sessions?")
|
158 |
filters = gr.Textbox(label="Filters (comma-separated)", placeholder="e.g. driver_number=16&,session_key=123&")
|
159 |
btn = gr.Button("Apply filters")
|
160 |
output = gr.Textbox(label="Full API string")
|
161 |
+
def _apply_filters(api_string, filters):
|
162 |
# Expect filters as comma-separated
|
163 |
filter_list = [f.strip() for f in filters.split(",") if f.strip()]
|
164 |
return openf1_tools.apply_filters(api_string, *filter_list)
|
165 |
+
btn.click(_apply_filters, inputs=[api_string, filters], outputs=output)
|
166 |
with gr.Accordion("send_request(api_string)", open=False):
|
167 |
with gr.Accordion("Example API requests (copy & paste into text box below)", open=False):
|
168 |
gr.Markdown(MARKDOWN_OPENF1_EXAMPLES)
|
169 |
api_string = gr.Textbox(label="Full API string", placeholder="e.g. https://api.openf1.org/v1/sessions?driver_number=16")
|
170 |
btn = gr.Button("Send API request")
|
171 |
output = gr.JSON()
|
172 |
+
def _send_request(api_string):
|
173 |
try:
|
174 |
return openf1_tools.send_request(api_string)
|
175 |
except Exception as e:
|
176 |
return {"error": str(e)}
|
177 |
+
btn.click(_send_request, inputs=api_string, outputs=output)
|
178 |
return openf1_tools_tab
|
179 |
|
180 |
# OpenF1 tabs
|