ydshieh HF Staff commited on
Commit
20e9753
Β·
verified Β·
1 Parent(s): e511123

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +85 -45
app.py CHANGED
@@ -231,44 +231,92 @@ def _filter_records(repo: str, pr: str, sha: str) -> List[dict]:
231
  return records[:MAX_ROWS]
232
 
233
 
234
- def _generate_summary_tables(record: dict) -> Tuple[List[List[str]], List[List[str]]]:
235
- """Generate by_test and by_model summary tables from a record."""
236
 
237
  # By test table
238
- by_test_rows = []
 
 
 
 
 
 
 
 
 
 
 
 
239
  by_test_data = record.get("by_test", {})
240
- for test_name, test_info in by_test_data.items():
241
  count = test_info.get("count", 0)
242
  errors = test_info.get("errors", {})
243
 
244
- # Format errors with each on a NEW line, like GitHub table format
245
  error_lines = []
246
  for err, cnt in errors.items():
247
- error_lines.append(f"{cnt}Γ— {err}")
 
248
 
249
- # Join with actual newlines - Gradio will render these in the table
250
- error_str = "\n".join(error_lines)
251
 
252
- by_test_rows.append([test_name, str(count), error_str])
 
 
 
 
 
 
 
 
 
 
 
 
253
 
254
  # By model table
255
- by_model_rows = []
 
 
 
 
 
 
 
 
 
 
 
 
256
  by_model_data = record.get("by_model", {})
257
- for model_name, model_info in by_model_data.items():
258
  count = model_info.get("count", 0)
259
  errors = model_info.get("errors", {})
260
 
261
- # Format errors with each on a NEW line
262
  error_lines = []
263
  for err, cnt in errors.items():
264
- error_lines.append(f"{cnt}Γ— {err}")
 
265
 
266
- # Join with actual newlines
267
- error_str = "\n".join(error_lines)
268
 
269
- by_model_rows.append([model_name, str(count), error_str])
 
 
 
 
 
 
270
 
271
- return by_test_rows, by_model_rows
 
 
 
 
 
 
272
 
273
 
274
 
@@ -359,8 +407,8 @@ def _generate_pytest_commands(record: dict) -> str:
359
 
360
  def query(repo: str, pr: str, sha: str) -> Tuple[
361
  str, # metadata_info
362
- List[List[str]], # by_test_table
363
- List[List[str]], # by_model_table
364
  str, # markdown_summary
365
  str, # pytest_commands
366
  str, # raw_json
@@ -375,8 +423,8 @@ def query(repo: str, pr: str, sha: str) -> Tuple[
375
  if not pr:
376
  return (
377
  "**Error:** PR number is required.",
378
- [],
379
- [],
380
  "",
381
  "",
382
  json.dumps({"error": "PR number is required."}, indent=2),
@@ -389,8 +437,8 @@ def query(repo: str, pr: str, sha: str) -> Tuple[
389
  if not records:
390
  return (
391
  f"**No records found** for PR {pr}.",
392
- [],
393
- [],
394
  "",
395
  "",
396
  json.dumps({"error": "No records found."}, indent=2),
@@ -413,8 +461,8 @@ def query(repo: str, pr: str, sha: str) -> Tuple[
413
  ]
414
  metadata_info = "\n\n".join(metadata_lines)
415
 
416
- # Generate tables
417
- by_test_rows, by_model_rows = _generate_summary_tables(latest_record)
418
 
419
  # Generate markdown summary
420
  markdown_summary = _generate_markdown_summary(latest_record)
@@ -429,8 +477,8 @@ def query(repo: str, pr: str, sha: str) -> Tuple[
429
 
430
  return (
431
  metadata_info,
432
- by_test_rows,
433
- by_model_rows,
434
  markdown_summary,
435
  pytest_commands,
436
  raw_json,
@@ -503,23 +551,15 @@ with gr.Blocks(title="CircleCI Test Results Viewer") as demo:
503
 
504
  gr.Markdown("---")
505
  gr.Markdown("### πŸ“ By Test")
 
506
 
507
- by_test_table = gr.Dataframe(
508
- headers=["Test", "Failures", "Full error(s)"],
509
- wrap=True,
510
- interactive=False,
511
- row_count=(5, "dynamic"), # Start with 5 rows, expand as needed
512
- )
513
 
514
  gr.Markdown("---")
515
  gr.Markdown("### 🏷️ By Model")
 
516
 
517
- by_model_table = gr.Dataframe(
518
- headers=["Model", "Failures", "Full error(s)"],
519
- wrap=True,
520
- interactive=False,
521
- row_count=(3, "dynamic"), # Start with 3 rows, expand as needed
522
- )
523
 
524
  with gr.Tab("πŸ“‹ Copy for GitHub"):
525
  gr.Markdown(
@@ -574,8 +614,8 @@ with gr.Blocks(title="CircleCI Test Results Viewer") as demo:
574
  else:
575
  return (
576
  "Enter a PR number and click Search",
577
- [],
578
- [],
579
  "",
580
  "",
581
  "",
@@ -588,8 +628,8 @@ with gr.Blocks(title="CircleCI Test Results Viewer") as demo:
588
  inputs=[repo_box, pr_box, sha_box],
589
  outputs=[
590
  metadata_box,
591
- by_test_table,
592
- by_model_table,
593
  markdown_output,
594
  pytest_output,
595
  json_view,
@@ -609,8 +649,8 @@ with gr.Blocks(title="CircleCI Test Results Viewer") as demo:
609
  inputs=[repo_box, pr_box, sha_box],
610
  outputs=[
611
  metadata_box,
612
- by_test_table,
613
- by_model_table,
614
  markdown_output,
615
  pytest_output,
616
  json_view,
 
231
  return records[:MAX_ROWS]
232
 
233
 
234
+ def _generate_html_tables(record: dict) -> Tuple[str, str]:
235
+ """Generate HTML tables with proper horizontal scrolling and full text display."""
236
 
237
  # By test table
238
+ by_test_html = """
239
+ <div style="overflow-x: auto; max-width: 100%; border: 1px solid #ddd; border-radius: 8px;">
240
+ <table style="width: 100%; border-collapse: collapse; font-family: monospace; font-size: 13px;">
241
+ <thead>
242
+ <tr style="background-color: #f6f8fa; border-bottom: 2px solid #d0d7de;">
243
+ <th style="padding: 12px; text-align: left; white-space: nowrap; min-width: 400px; position: sticky; left: 0; background-color: #f6f8fa; z-index: 10;">Test</th>
244
+ <th style="padding: 12px; text-align: center; white-space: nowrap; width: 80px;">Failures</th>
245
+ <th style="padding: 12px; text-align: left; white-space: nowrap; min-width: 600px;">Full error(s)</th>
246
+ </tr>
247
+ </thead>
248
+ <tbody>
249
+ """
250
+
251
  by_test_data = record.get("by_test", {})
252
+ for idx, (test_name, test_info) in enumerate(by_test_data.items()):
253
  count = test_info.get("count", 0)
254
  errors = test_info.get("errors", {})
255
 
256
+ # Format errors with line breaks
257
  error_lines = []
258
  for err, cnt in errors.items():
259
+ error_lines.append(f"<div style='margin-bottom: 8px;'><strong>{cnt}Γ—</strong> {err}</div>")
260
+ error_html = "".join(error_lines)
261
 
262
+ row_bg = "#ffffff" if idx % 2 == 0 else "#f6f8fa"
 
263
 
264
+ by_test_html += f"""
265
+ <tr style="background-color: {row_bg}; border-bottom: 1px solid #d0d7de;">
266
+ <td style="padding: 12px; white-space: nowrap; position: sticky; left: 0; background-color: {row_bg}; border-right: 2px solid #d0d7de; z-index: 5;">{test_name}</td>
267
+ <td style="padding: 12px; text-align: center;">{count}</td>
268
+ <td style="padding: 12px; white-space: normal;">{error_html}</td>
269
+ </tr>
270
+ """
271
+
272
+ by_test_html += """
273
+ </tbody>
274
+ </table>
275
+ </div>
276
+ """
277
 
278
  # By model table
279
+ by_model_html = """
280
+ <div style="overflow-x: auto; max-width: 100%; border: 1px solid #ddd; border-radius: 8px; margin-top: 20px;">
281
+ <table style="width: 100%; border-collapse: collapse; font-family: monospace; font-size: 13px;">
282
+ <thead>
283
+ <tr style="background-color: #f6f8fa; border-bottom: 2px solid #d0d7de;">
284
+ <th style="padding: 12px; text-align: left; white-space: nowrap; min-width: 150px; position: sticky; left: 0; background-color: #f6f8fa; z-index: 10;">Model</th>
285
+ <th style="padding: 12px; text-align: center; white-space: nowrap; width: 80px;">Failures</th>
286
+ <th style="padding: 12px; text-align: left; white-space: nowrap; min-width: 600px;">Full error(s)</th>
287
+ </tr>
288
+ </thead>
289
+ <tbody>
290
+ """
291
+
292
  by_model_data = record.get("by_model", {})
293
+ for idx, (model_name, model_info) in enumerate(by_model_data.items()):
294
  count = model_info.get("count", 0)
295
  errors = model_info.get("errors", {})
296
 
297
+ # Format errors with line breaks
298
  error_lines = []
299
  for err, cnt in errors.items():
300
+ error_lines.append(f"<div style='margin-bottom: 8px;'><strong>{cnt}Γ—</strong> {err}</div>")
301
+ error_html = "".join(error_lines)
302
 
303
+ row_bg = "#ffffff" if idx % 2 == 0 else "#f6f8fa"
 
304
 
305
+ by_model_html += f"""
306
+ <tr style="background-color: {row_bg}; border-bottom: 1px solid #d0d7de;">
307
+ <td style="padding: 12px; white-space: nowrap; position: sticky; left: 0; background-color: {row_bg}; border-right: 2px solid #d0d7de; z-index: 5;">{model_name}</td>
308
+ <td style="padding: 12px; text-align: center;">{count}</td>
309
+ <td style="padding: 12px; white-space: normal;">{error_html}</td>
310
+ </tr>
311
+ """
312
 
313
+ by_model_html += """
314
+ </tbody>
315
+ </table>
316
+ </div>
317
+ """
318
+
319
+ return by_test_html, by_model_html
320
 
321
 
322
 
 
407
 
408
  def query(repo: str, pr: str, sha: str) -> Tuple[
409
  str, # metadata_info
410
+ str, # by_test_html
411
+ str, # by_model_html
412
  str, # markdown_summary
413
  str, # pytest_commands
414
  str, # raw_json
 
423
  if not pr:
424
  return (
425
  "**Error:** PR number is required.",
426
+ "",
427
+ "",
428
  "",
429
  "",
430
  json.dumps({"error": "PR number is required."}, indent=2),
 
437
  if not records:
438
  return (
439
  f"**No records found** for PR {pr}.",
440
+ "",
441
+ "",
442
  "",
443
  "",
444
  json.dumps({"error": "No records found."}, indent=2),
 
461
  ]
462
  metadata_info = "\n\n".join(metadata_lines)
463
 
464
+ # Generate HTML tables
465
+ by_test_html, by_model_html = _generate_html_tables(latest_record)
466
 
467
  # Generate markdown summary
468
  markdown_summary = _generate_markdown_summary(latest_record)
 
477
 
478
  return (
479
  metadata_info,
480
+ by_test_html,
481
+ by_model_html,
482
  markdown_summary,
483
  pytest_commands,
484
  raw_json,
 
551
 
552
  gr.Markdown("---")
553
  gr.Markdown("### πŸ“ By Test")
554
+ gr.Markdown("*Scroll horizontally to see full test names and errors*")
555
 
556
+ by_test_html = gr.HTML(label="Test Failures")
 
 
 
 
 
557
 
558
  gr.Markdown("---")
559
  gr.Markdown("### 🏷️ By Model")
560
+ gr.Markdown("*Scroll horizontally to see full error messages*")
561
 
562
+ by_model_html = gr.HTML(label="Model Failures")
 
 
 
 
 
563
 
564
  with gr.Tab("πŸ“‹ Copy for GitHub"):
565
  gr.Markdown(
 
614
  else:
615
  return (
616
  "Enter a PR number and click Search",
617
+ "",
618
+ "",
619
  "",
620
  "",
621
  "",
 
628
  inputs=[repo_box, pr_box, sha_box],
629
  outputs=[
630
  metadata_box,
631
+ by_test_html,
632
+ by_model_html,
633
  markdown_output,
634
  pytest_output,
635
  json_view,
 
649
  inputs=[repo_box, pr_box, sha_box],
650
  outputs=[
651
  metadata_box,
652
+ by_test_html,
653
+ by_model_html,
654
  markdown_output,
655
  pytest_output,
656
  json_view,