Commit
·
bd0b666
1
Parent(s):
b1d592c
fix: Keep the selected models if they're valid. Add more logging
Browse files
app.py
CHANGED
|
@@ -197,7 +197,7 @@ def main() -> None:
|
|
| 197 |
|
| 198 |
language_names_dropdown.change(
|
| 199 |
fn=partial(update_model_ids_dropdown, results_dfs=results_dfs),
|
| 200 |
-
inputs=language_names_dropdown,
|
| 201 |
outputs=model_ids_dropdown,
|
| 202 |
)
|
| 203 |
|
|
@@ -228,24 +228,36 @@ def main() -> None:
|
|
| 228 |
|
| 229 |
|
| 230 |
def update_model_ids_dropdown(
|
| 231 |
-
language_names: list[str],
|
|
|
|
|
|
|
| 232 |
) -> dict:
|
| 233 |
"""When the language names are updated, update the model ids dropdown.
|
| 234 |
|
| 235 |
Args:
|
| 236 |
language_names:
|
| 237 |
The names of the languages to include in the plot.
|
|
|
|
|
|
|
| 238 |
results_dfs:
|
| 239 |
The results dataframes for each language.
|
| 240 |
|
| 241 |
Returns:
|
| 242 |
The Gradio update to the model ids dropdown.
|
| 243 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 244 |
if results_dfs is None or len(language_names) == 0:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 245 |
return gr.update(choices=[], value=[])
|
| 246 |
|
| 247 |
-
# Download the newest records if it has been more than 5 minutes since the last
|
| 248 |
-
|
| 249 |
filtered_results_dfs = {
|
| 250 |
language: df
|
| 251 |
for language, df in results_dfs.items()
|
|
@@ -265,9 +277,23 @@ def update_model_ids_dropdown(
|
|
| 265 |
]
|
| 266 |
|
| 267 |
if len(filtered_models) == 0:
|
|
|
|
|
|
|
|
|
|
| 268 |
return gr.update(choices=[], value=[])
|
| 269 |
|
| 270 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 271 |
|
| 272 |
|
| 273 |
def produce_radial_plot(
|
|
@@ -291,15 +317,21 @@ def produce_radial_plot(
|
|
| 291 |
Returns:
|
| 292 |
A plotly figure.
|
| 293 |
"""
|
| 294 |
-
if results_dfs is None or len(language_names) == 0 or len(model_ids) == 0:
|
| 295 |
-
return go.Figure()
|
| 296 |
-
|
| 297 |
global last_fetch
|
| 298 |
minutes_since_last_fetch = (dt.datetime.now() - last_fetch).total_seconds() / 60
|
| 299 |
if minutes_since_last_fetch > UPDATE_FREQUENCY_MINUTES:
|
| 300 |
results_dfs = fetch_results()
|
| 301 |
last_fetch = dt.datetime.now()
|
| 302 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 303 |
logger.info(
|
| 304 |
f"Producing radial plot for models {model_ids!r} on languages "
|
| 305 |
f"{language_names!r}..."
|
|
|
|
| 197 |
|
| 198 |
language_names_dropdown.change(
|
| 199 |
fn=partial(update_model_ids_dropdown, results_dfs=results_dfs),
|
| 200 |
+
inputs=[language_names_dropdown, model_ids_dropdown],
|
| 201 |
outputs=model_ids_dropdown,
|
| 202 |
)
|
| 203 |
|
|
|
|
| 228 |
|
| 229 |
|
| 230 |
def update_model_ids_dropdown(
|
| 231 |
+
language_names: list[str],
|
| 232 |
+
model_ids: list[str],
|
| 233 |
+
results_dfs: dict[Language, pd.DataFrame] | None,
|
| 234 |
) -> dict:
|
| 235 |
"""When the language names are updated, update the model ids dropdown.
|
| 236 |
|
| 237 |
Args:
|
| 238 |
language_names:
|
| 239 |
The names of the languages to include in the plot.
|
| 240 |
+
model_ids:
|
| 241 |
+
The ids of the models to include in the plot.
|
| 242 |
results_dfs:
|
| 243 |
The results dataframes for each language.
|
| 244 |
|
| 245 |
Returns:
|
| 246 |
The Gradio update to the model ids dropdown.
|
| 247 |
"""
|
| 248 |
+
global last_fetch
|
| 249 |
+
minutes_since_last_fetch = (dt.datetime.now() - last_fetch).total_seconds() / 60
|
| 250 |
+
if minutes_since_last_fetch > UPDATE_FREQUENCY_MINUTES:
|
| 251 |
+
results_dfs = fetch_results()
|
| 252 |
+
last_fetch = dt.datetime.now()
|
| 253 |
+
|
| 254 |
if results_dfs is None or len(language_names) == 0:
|
| 255 |
+
if results_dfs is None:
|
| 256 |
+
logger.info("No results fetched yet. Resetting model ids dropdown.")
|
| 257 |
+
else:
|
| 258 |
+
logger.info("No languages selected. Resetting model ids dropdown.")
|
| 259 |
return gr.update(choices=[], value=[])
|
| 260 |
|
|
|
|
|
|
|
| 261 |
filtered_results_dfs = {
|
| 262 |
language: df
|
| 263 |
for language, df in results_dfs.items()
|
|
|
|
| 277 |
]
|
| 278 |
|
| 279 |
if len(filtered_models) == 0:
|
| 280 |
+
logger.info(
|
| 281 |
+
"No valid models for the selected languages. Resetting model ids dropdown."
|
| 282 |
+
)
|
| 283 |
return gr.update(choices=[], value=[])
|
| 284 |
|
| 285 |
+
valid_selected_models = [
|
| 286 |
+
model_id for model_id in model_ids if model_id in filtered_models
|
| 287 |
+
]
|
| 288 |
+
if not valid_selected_models:
|
| 289 |
+
valid_selected_models = random.sample(filtered_models, k=1)
|
| 290 |
+
|
| 291 |
+
logger.info(
|
| 292 |
+
f"Updated model ids dropdown with {len(filtered_models)} valid models for "
|
| 293 |
+
f"the selected languages, with {len(valid_selected_models)} selected."
|
| 294 |
+
)
|
| 295 |
+
|
| 296 |
+
return gr.update(choices=filtered_models, value=valid_selected_models)
|
| 297 |
|
| 298 |
|
| 299 |
def produce_radial_plot(
|
|
|
|
| 317 |
Returns:
|
| 318 |
A plotly figure.
|
| 319 |
"""
|
|
|
|
|
|
|
|
|
|
| 320 |
global last_fetch
|
| 321 |
minutes_since_last_fetch = (dt.datetime.now() - last_fetch).total_seconds() / 60
|
| 322 |
if minutes_since_last_fetch > UPDATE_FREQUENCY_MINUTES:
|
| 323 |
results_dfs = fetch_results()
|
| 324 |
last_fetch = dt.datetime.now()
|
| 325 |
|
| 326 |
+
if results_dfs is None or len(language_names) == 0 or len(model_ids) == 0:
|
| 327 |
+
if results_dfs is None:
|
| 328 |
+
logger.info("No results fetched yet. Resetting plot.")
|
| 329 |
+
elif len(language_names) == 0:
|
| 330 |
+
logger.info("No languages selected. Resetting plot.")
|
| 331 |
+
else:
|
| 332 |
+
logger.info("No models selected. Resetting plot.")
|
| 333 |
+
return go.Figure()
|
| 334 |
+
|
| 335 |
logger.info(
|
| 336 |
f"Producing radial plot for models {model_ids!r} on languages "
|
| 337 |
f"{language_names!r}..."
|