Commit
Β·
bb498b2
1
Parent(s):
ffb4f17
app.py fixed
Browse files- dashboard/app.py +67 -55
dashboard/app.py
CHANGED
@@ -276,98 +276,110 @@ def run(from_results_dir, datasource, port):
|
|
276 |
|
277 |
|
278 |
@click.command()
|
279 |
-
@click.option('--from-results-dir', default=None, help='Load inference-benchmarker results from
|
280 |
-
@click.option('--datasource', default='file://benchmarks.parquet', help='Load
|
281 |
@click.option('--port', default=7860, help='Port to run the dashboard')
|
282 |
-
def main(
|
283 |
print("===== Starting Application =====")
|
284 |
-
print(f"Environment variables: {os.environ}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
285 |
|
286 |
-
|
287 |
-
|
288 |
-
|
|
|
|
|
289 |
output_filename = 'benchmarks.parquet'
|
290 |
-
|
291 |
|
292 |
-
|
293 |
-
check_file_exists(
|
294 |
|
295 |
-
#
|
296 |
-
|
297 |
-
|
|
|
|
|
298 |
|
299 |
-
#
|
300 |
-
|
301 |
-
|
302 |
-
os.makedirs(abs_results_dir, exist_ok=True)
|
303 |
-
|
304 |
-
# Call build_results with absolute paths
|
305 |
-
full_output_path = os.path.join(abs_results_dir, output_filename)
|
306 |
-
print(f"π‘ Debug - Expected output path: {full_output_path}")
|
307 |
|
308 |
try:
|
309 |
-
build_results(
|
310 |
-
print("β
Build results completed")
|
311 |
-
except Exception as
|
312 |
-
print(f"β Error in build_results: {str(
|
313 |
print(f"Stack trace: {traceback.format_exc()}")
|
314 |
print("β οΈ Attempting fallback method: direct JSON processing")
|
315 |
-
|
316 |
-
# Fallback: Directly process the JSON files
|
317 |
try:
|
318 |
-
|
319 |
-
json_files
|
320 |
-
print(f"Found {len(json_files)} JSON files: {json_files}")
|
321 |
-
|
322 |
if not json_files:
|
323 |
-
raise FileNotFoundError("No JSON files found in results directory")
|
324 |
|
325 |
-
# Create a combined DataFrame from the JSON files
|
326 |
combined_data = []
|
327 |
for json_file in json_files:
|
328 |
try:
|
329 |
with open(json_file, 'r') as f:
|
330 |
data = json.load(f)
|
331 |
-
|
332 |
-
# Extract model name from filename
|
333 |
filename = os.path.basename(json_file)
|
334 |
-
|
|
|
335 |
|
336 |
-
# Process the benchmarks - basic structure expected in the JSON files
|
337 |
if 'benchmarks' in data:
|
338 |
for benchmark in data['benchmarks']:
|
339 |
benchmark['model'] = model_name
|
340 |
benchmark['run_id'] = os.path.splitext(filename)[0]
|
341 |
combined_data.append(benchmark)
|
342 |
else:
|
343 |
-
print(f"β οΈ No 'benchmarks' key in {json_file}")
|
344 |
except Exception as json_err:
|
345 |
-
print(f"β Error processing {json_file}: {str(json_err)}")
|
346 |
|
347 |
if combined_data:
|
348 |
df_direct = pd.DataFrame(combined_data)
|
349 |
-
|
350 |
-
|
351 |
-
print(f"β
Created parquet file via fallback method: {full_output_path}")
|
352 |
else:
|
353 |
-
raise ValueError("No data could be extracted from JSON files")
|
354 |
-
|
355 |
-
|
356 |
-
print(f"β Fallback method failed: {str(fallback_err)}")
|
357 |
print(f"Stack trace: {traceback.format_exc()}")
|
358 |
|
359 |
-
#
|
360 |
-
check_file_exists(
|
361 |
-
|
362 |
-
|
363 |
-
|
|
|
|
|
|
|
364 |
else:
|
365 |
-
#
|
366 |
-
|
|
|
367 |
|
368 |
-
print(f"Final
|
369 |
|
370 |
-
run(None
|
|
|
|
|
371 |
|
372 |
|
373 |
if __name__ == '__main__':
|
|
|
276 |
|
277 |
|
278 |
@click.command()
|
279 |
+
@click.option('--from-results-dir', 'cli_from_results_dir', default=None, help='Load inference-benchmarker results from this directory. Overrides DASHBOARD_FROM_RESULTS_DIR.')
|
280 |
+
@click.option('--datasource', 'cli_datasource', default='file://benchmarks.parquet', help='Load this Parquet file directly if not building from a results directory.')
|
281 |
@click.option('--port', default=7860, help='Port to run the dashboard')
|
282 |
+
def main(cli_from_results_dir, cli_datasource, port):
|
283 |
print("===== Starting Application =====")
|
284 |
+
# print(f"Environment variables: {os.environ}") # Already in user's code or logs
|
285 |
+
|
286 |
+
# Determine the directory from which to process JSON results
|
287 |
+
# Priority: 1. CLI option, 2. Env Var, 3. Default to 'results' dir
|
288 |
+
processing_dir = cli_from_results_dir
|
289 |
+
|
290 |
+
if processing_dir is None:
|
291 |
+
env_var_value = os.environ.get('DASHBOARD_FROM_RESULTS_DIR')
|
292 |
+
if env_var_value:
|
293 |
+
print(f"Using environment variable DASHBOARD_FROM_RESULTS_DIR='{env_var_value}' for processing.")
|
294 |
+
processing_dir = env_var_value
|
295 |
+
elif os.path.exists('results') and os.path.isdir('results'):
|
296 |
+
print(f"No --from-results-dir option or DASHBOARD_FROM_RESULTS_DIR env var. Defaulting to 'results' directory for processing as it exists.")
|
297 |
+
processing_dir = 'results'
|
298 |
+
else:
|
299 |
+
print(f"No directory specified for processing (no --from-results-dir, no DASHBOARD_FROM_RESULTS_DIR env var, and 'results' dir not found).")
|
300 |
+
# processing_dir remains None
|
301 |
|
302 |
+
path_to_load_by_run_function = None # This will be the path to the .parquet file
|
303 |
+
|
304 |
+
if processing_dir:
|
305 |
+
# A directory for processing JSONs has been determined.
|
306 |
+
# Use the existing logic to build/fallback and generate benchmarks.parquet.
|
307 |
output_filename = 'benchmarks.parquet'
|
308 |
+
abs_processing_dir = os.path.abspath(processing_dir)
|
309 |
|
310 |
+
print(f"π‘ Debug - Will process JSONs from directory: {abs_processing_dir}")
|
311 |
+
check_file_exists(abs_processing_dir, "Source directory for JSONs")
|
312 |
|
313 |
+
# Ensure the directory exists (it might be 'results' or user-provided)
|
314 |
+
# build_results might expect the output directory to exist.
|
315 |
+
if not os.path.exists(abs_processing_dir):
|
316 |
+
print(f"π‘ Debug - Creating directory for processing/output: {abs_processing_dir}")
|
317 |
+
os.makedirs(abs_processing_dir, exist_ok=True)
|
318 |
|
319 |
+
# The generated parquet file will be placed inside the abs_processing_dir
|
320 |
+
generated_parquet_filepath = os.path.join(abs_processing_dir, output_filename)
|
321 |
+
print(f"π‘ Debug - Expected path for generated parquet file: {generated_parquet_filepath}")
|
|
|
|
|
|
|
|
|
|
|
322 |
|
323 |
try:
|
324 |
+
build_results(abs_processing_dir, output_filename, None) # output_filename is relative to abs_processing_dir
|
325 |
+
print("β
Build results completed using build_results.")
|
326 |
+
except Exception as e_build:
|
327 |
+
print(f"β Error in build_results: {str(e_build)}")
|
328 |
print(f"Stack trace: {traceback.format_exc()}")
|
329 |
print("β οΈ Attempting fallback method: direct JSON processing")
|
|
|
|
|
330 |
try:
|
331 |
+
json_files = glob.glob(os.path.join(abs_processing_dir, "*.json"))
|
332 |
+
print(f"Found {len(json_files)} JSON files for fallback: {json_files}")
|
|
|
|
|
333 |
if not json_files:
|
334 |
+
raise FileNotFoundError("Fallback: No JSON files found in results directory")
|
335 |
|
|
|
336 |
combined_data = []
|
337 |
for json_file in json_files:
|
338 |
try:
|
339 |
with open(json_file, 'r') as f:
|
340 |
data = json.load(f)
|
|
|
|
|
341 |
filename = os.path.basename(json_file)
|
342 |
+
model_name_parts = filename.split('_')
|
343 |
+
model_name = f"{model_name_parts[0]}_{model_name_parts[1]}" if len(model_name_parts) > 1 else model_name_parts[0]
|
344 |
|
|
|
345 |
if 'benchmarks' in data:
|
346 |
for benchmark in data['benchmarks']:
|
347 |
benchmark['model'] = model_name
|
348 |
benchmark['run_id'] = os.path.splitext(filename)[0]
|
349 |
combined_data.append(benchmark)
|
350 |
else:
|
351 |
+
print(f"β οΈ Fallback: No 'benchmarks' key in {json_file}")
|
352 |
except Exception as json_err:
|
353 |
+
print(f"β Fallback: Error processing {json_file}: {str(json_err)}")
|
354 |
|
355 |
if combined_data:
|
356 |
df_direct = pd.DataFrame(combined_data)
|
357 |
+
df_direct.to_parquet(generated_parquet_filepath)
|
358 |
+
print(f"β
Created parquet file via fallback method: {generated_parquet_filepath}")
|
|
|
359 |
else:
|
360 |
+
raise ValueError("Fallback: No data could be extracted from JSON files")
|
361 |
+
except Exception as e_fallback:
|
362 |
+
print(f"β Fallback method failed: {str(e_fallback)}")
|
|
|
363 |
print(f"Stack trace: {traceback.format_exc()}")
|
364 |
|
365 |
+
# After attempting to build/generate, check if the file exists
|
366 |
+
check_file_exists(generated_parquet_filepath, "Parquet file after build/fallback attempts")
|
367 |
+
if os.path.exists(generated_parquet_filepath):
|
368 |
+
path_to_load_by_run_function = generated_parquet_filepath
|
369 |
+
else:
|
370 |
+
print(f"β CRITICAL: Failed to generate or find parquet file at '{generated_parquet_filepath}' after all attempts.")
|
371 |
+
# path_to_load_by_run_function remains None.
|
372 |
+
# The run() function's error handling will create an empty DataFrame.
|
373 |
else:
|
374 |
+
# No directory for processing JSONs was determined. Use the cli_datasource directly.
|
375 |
+
print(f"Not processing a results directory. Using --datasource option directly: '{cli_datasource}'")
|
376 |
+
path_to_load_by_run_function = cli_datasource
|
377 |
|
378 |
+
print(f"π‘ Final path to be loaded by run() function: '{path_to_load_by_run_function}'")
|
379 |
|
380 |
+
# Call run(). The first argument (from_results_dir for run()) is None because main handles processing.
|
381 |
+
# The second argument (datasource for run()) is the actual file path to load.
|
382 |
+
run(None, path_to_load_by_run_function, port)
|
383 |
|
384 |
|
385 |
if __name__ == '__main__':
|