Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -350,20 +350,20 @@ def load_and_display_json(file):
|
|
| 350 |
<div class="color-legend">
|
| 351 |
<h3>Row Color Legend</h3>
|
| 352 |
<div class="legend-item">
|
| 353 |
-
<div class="color-box
|
| 354 |
-
<div>
|
| 355 |
</div>
|
| 356 |
<div class="legend-item">
|
| 357 |
-
<div class="color-box
|
| 358 |
-
<div>
|
| 359 |
</div>
|
| 360 |
<div class="legend-item">
|
| 361 |
<div class="color-box" style="background-color: #a9dfbf;"></div>
|
| 362 |
<div>Shallow Green: Medium Information Coverage - Information Coverage score is between 0.5 and 0.8</div>
|
| 363 |
</div>
|
| 364 |
<div class="legend-item">
|
| 365 |
-
<div class="color-box" style="background-color: #
|
| 366 |
-
<div>
|
| 367 |
</div>
|
| 368 |
</div>
|
| 369 |
|
|
@@ -384,7 +384,8 @@ def load_and_display_json(file):
|
|
| 384 |
|
| 385 |
# Calculate statistics for each row type
|
| 386 |
total_rows = len(df)
|
| 387 |
-
send_to_human_count = 0
|
|
|
|
| 388 |
low_coverage_count = 0
|
| 389 |
medium_coverage_count = 0
|
| 390 |
high_coverage_count = 0
|
|
@@ -393,6 +394,10 @@ def load_and_display_json(file):
|
|
| 393 |
# Check for metrics to determine row type
|
| 394 |
is_send_to_human = row['Send to Human'] is True
|
| 395 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 396 |
# Extract coverage score
|
| 397 |
coverage_score = None
|
| 398 |
if row['Evaluation Metrics']:
|
|
@@ -403,19 +408,20 @@ def load_and_display_json(file):
|
|
| 403 |
except (ValueError, TypeError):
|
| 404 |
pass
|
| 405 |
|
| 406 |
-
# Count row types (
|
| 407 |
-
if
|
| 408 |
-
|
|
|
|
|
|
|
| 409 |
elif coverage_score is not None:
|
| 410 |
-
if coverage_score
|
| 411 |
-
low_coverage_count += 1
|
| 412 |
-
elif coverage_score >= 0.8:
|
| 413 |
-
high_coverage_count += 1
|
| 414 |
-
else: # Between 0.5 and 0.8
|
| 415 |
medium_coverage_count += 1
|
|
|
|
|
|
|
| 416 |
|
| 417 |
# Calculate percentages
|
| 418 |
send_to_human_percent = (send_to_human_count / total_rows * 100) if total_rows > 0 else 0
|
|
|
|
| 419 |
low_coverage_percent = (low_coverage_count / total_rows * 100) if total_rows > 0 else 0
|
| 420 |
medium_coverage_percent = (medium_coverage_count / total_rows * 100) if total_rows > 0 else 0
|
| 421 |
high_coverage_percent = (high_coverage_count / total_rows * 100) if total_rows > 0 else 0
|
|
@@ -425,25 +431,29 @@ def load_and_display_json(file):
|
|
| 425 |
<div style="margin-bottom: 20px; padding: 15px; border: 1px solid #e0e0e0; border-radius: 5px; background-color: #f9f9f9;">
|
| 426 |
<h3>Row Type Statistics</h3>
|
| 427 |
<div style="display: flex; flex-wrap: wrap; gap: 15px;">
|
| 428 |
-
<div style="background-color: #
|
| 429 |
-
<strong>
|
| 430 |
</div>
|
| 431 |
-
<div style="background-color: #
|
| 432 |
-
<strong>
|
| 433 |
</div>
|
| 434 |
<div style="background-color: #a9dfbf; padding: 10px; border-radius: 5px; min-width: 200px;">
|
| 435 |
<strong>Medium Coverage:</strong> {:.1f}% ({} of {} rows)
|
| 436 |
</div>
|
| 437 |
-
<div style="background-color: #
|
| 438 |
-
<strong>
|
|
|
|
|
|
|
|
|
|
| 439 |
</div>
|
| 440 |
</div>
|
| 441 |
</div>
|
| 442 |
""".format(
|
|
|
|
| 443 |
send_to_human_percent, send_to_human_count, total_rows,
|
| 444 |
-
low_coverage_percent, low_coverage_count, total_rows,
|
| 445 |
medium_coverage_percent, medium_coverage_count, total_rows,
|
| 446 |
-
|
|
|
|
| 447 |
)
|
| 448 |
|
| 449 |
# Add table
|
|
@@ -504,20 +514,20 @@ def load_and_display_json(file):
|
|
| 504 |
except (ValueError, TypeError) as e:
|
| 505 |
logger.warning(f"Could not convert {info_coverage_value} to float: {e}")
|
| 506 |
|
| 507 |
-
# Determine row class (prioritize
|
| 508 |
row_class = ""
|
| 509 |
-
if
|
| 510 |
-
row_class = " class='send-to-human'"
|
| 511 |
-
logger.info(f"Row {row['Index']} marked as 'Send to Human'")
|
| 512 |
-
elif low_coverage:
|
| 513 |
-
row_class = " class='low-coverage'"
|
| 514 |
-
logger.info(f"Row {row['Index']} marked as 'Low Information Coverage'")
|
| 515 |
-
elif high_coverage:
|
| 516 |
row_class = " class='high-coverage'"
|
| 517 |
logger.info(f"Row {row['Index']} marked as 'High Information Coverage'")
|
|
|
|
|
|
|
|
|
|
| 518 |
elif medium_coverage:
|
| 519 |
row_class = " class='medium-coverage'"
|
| 520 |
logger.info(f"Row {row['Index']} marked as 'Medium Information Coverage'")
|
|
|
|
|
|
|
|
|
|
| 521 |
|
| 522 |
html_output += f"<tr{row_class}>"
|
| 523 |
html_output += f"<td style='text-align: center;'>{row['Index'] + 1}</td>"
|
|
@@ -642,10 +652,12 @@ with gr.Blocks() as demo:
|
|
| 642 |
|
| 643 |
with gr.Accordion("Row Color Legend", open=True):
|
| 644 |
gr.Markdown("""
|
| 645 |
-
* **
|
| 646 |
-
* **
|
| 647 |
* **Shallow Green rows**: Medium Information Coverage - Information Coverage score is between 0.5 and 0.8
|
| 648 |
-
* **
|
|
|
|
|
|
|
| 649 |
""")
|
| 650 |
|
| 651 |
file_input = gr.File(label="Upload JSON File", file_types=[".json"])
|
|
|
|
| 350 |
<div class="color-legend">
|
| 351 |
<h3>Row Color Legend</h3>
|
| 352 |
<div class="legend-item">
|
| 353 |
+
<div class="color-box" style="background-color: #1e8449; color: white;"></div>
|
| 354 |
+
<div>Dark Green: High Information Coverage - Information Coverage score is at least 0.8 (highest priority)</div>
|
| 355 |
</div>
|
| 356 |
<div class="legend-item">
|
| 357 |
+
<div class="color-box red-box"></div>
|
| 358 |
+
<div>Red: "Send to Human" is true but with Information Coverage below 0.8</div>
|
| 359 |
</div>
|
| 360 |
<div class="legend-item">
|
| 361 |
<div class="color-box" style="background-color: #a9dfbf;"></div>
|
| 362 |
<div>Shallow Green: Medium Information Coverage - Information Coverage score is between 0.5 and 0.8</div>
|
| 363 |
</div>
|
| 364 |
<div class="legend-item">
|
| 365 |
+
<div class="color-box" style="background-color: #e0e0e0;"></div>
|
| 366 |
+
<div>Light Gray: Low Information Coverage - Information Coverage score is below 0.5</div>
|
| 367 |
</div>
|
| 368 |
</div>
|
| 369 |
|
|
|
|
| 384 |
|
| 385 |
# Calculate statistics for each row type
|
| 386 |
total_rows = len(df)
|
| 387 |
+
send_to_human_count = 0 # Send to Human with less than 0.8 coverage
|
| 388 |
+
all_send_to_human_count = 0 # All Send to Human (regardless of coverage)
|
| 389 |
low_coverage_count = 0
|
| 390 |
medium_coverage_count = 0
|
| 391 |
high_coverage_count = 0
|
|
|
|
| 394 |
# Check for metrics to determine row type
|
| 395 |
is_send_to_human = row['Send to Human'] is True
|
| 396 |
|
| 397 |
+
# Count all send to human regardless of coverage
|
| 398 |
+
if is_send_to_human:
|
| 399 |
+
all_send_to_human_count += 1
|
| 400 |
+
|
| 401 |
# Extract coverage score
|
| 402 |
coverage_score = None
|
| 403 |
if row['Evaluation Metrics']:
|
|
|
|
| 408 |
except (ValueError, TypeError):
|
| 409 |
pass
|
| 410 |
|
| 411 |
+
# Count row types (matching the same priority logic used for display)
|
| 412 |
+
if coverage_score is not None and coverage_score >= 0.8:
|
| 413 |
+
high_coverage_count += 1
|
| 414 |
+
elif is_send_to_human:
|
| 415 |
+
send_to_human_count += 1 # This is now "Send to Human with less than 0.8 coverage"
|
| 416 |
elif coverage_score is not None:
|
| 417 |
+
if coverage_score >= 0.5: # Between 0.5 and 0.8
|
|
|
|
|
|
|
|
|
|
|
|
|
| 418 |
medium_coverage_count += 1
|
| 419 |
+
else: # Below 0.5
|
| 420 |
+
low_coverage_count += 1
|
| 421 |
|
| 422 |
# Calculate percentages
|
| 423 |
send_to_human_percent = (send_to_human_count / total_rows * 100) if total_rows > 0 else 0
|
| 424 |
+
all_send_to_human_percent = (all_send_to_human_count / total_rows * 100) if total_rows > 0 else 0
|
| 425 |
low_coverage_percent = (low_coverage_count / total_rows * 100) if total_rows > 0 else 0
|
| 426 |
medium_coverage_percent = (medium_coverage_count / total_rows * 100) if total_rows > 0 else 0
|
| 427 |
high_coverage_percent = (high_coverage_count / total_rows * 100) if total_rows > 0 else 0
|
|
|
|
| 431 |
<div style="margin-bottom: 20px; padding: 15px; border: 1px solid #e0e0e0; border-radius: 5px; background-color: #f9f9f9;">
|
| 432 |
<h3>Row Type Statistics</h3>
|
| 433 |
<div style="display: flex; flex-wrap: wrap; gap: 15px;">
|
| 434 |
+
<div style="background-color: #1e8449; color: white; padding: 10px; border-radius: 5px; min-width: 200px;">
|
| 435 |
+
<strong>High Coverage:</strong> {:.1f}% ({} of {} rows)
|
| 436 |
</div>
|
| 437 |
+
<div style="background-color: #ffcccc; padding: 10px; border-radius: 5px; min-width: 200px;">
|
| 438 |
+
<strong>Send to Human (<0.8 coverage):</strong> {:.1f}% ({} of {} rows)
|
| 439 |
</div>
|
| 440 |
<div style="background-color: #a9dfbf; padding: 10px; border-radius: 5px; min-width: 200px;">
|
| 441 |
<strong>Medium Coverage:</strong> {:.1f}% ({} of {} rows)
|
| 442 |
</div>
|
| 443 |
+
<div style="background-color: #e0e0e0; padding: 10px; border-radius: 5px; min-width: 200px;">
|
| 444 |
+
<strong>Low Coverage:</strong> {:.1f}% ({} of {} rows)
|
| 445 |
+
</div>
|
| 446 |
+
<div style="background-color: #f8d7da; padding: 10px; border-radius: 5px; min-width: 200px; border: 1px dashed #721c24;">
|
| 447 |
+
<strong>All Send to Human:</strong> {:.1f}% ({} of {} rows)
|
| 448 |
</div>
|
| 449 |
</div>
|
| 450 |
</div>
|
| 451 |
""".format(
|
| 452 |
+
high_coverage_percent, high_coverage_count, total_rows,
|
| 453 |
send_to_human_percent, send_to_human_count, total_rows,
|
|
|
|
| 454 |
medium_coverage_percent, medium_coverage_count, total_rows,
|
| 455 |
+
low_coverage_percent, low_coverage_count, total_rows,
|
| 456 |
+
all_send_to_human_percent, all_send_to_human_count, total_rows
|
| 457 |
)
|
| 458 |
|
| 459 |
# Add table
|
|
|
|
| 514 |
except (ValueError, TypeError) as e:
|
| 515 |
logger.warning(f"Could not convert {info_coverage_value} to float: {e}")
|
| 516 |
|
| 517 |
+
# Determine row class (prioritize high coverage over send_to_human, then medium, then low)
|
| 518 |
row_class = ""
|
| 519 |
+
if high_coverage:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 520 |
row_class = " class='high-coverage'"
|
| 521 |
logger.info(f"Row {row['Index']} marked as 'High Information Coverage'")
|
| 522 |
+
elif row['Send to Human'] is True:
|
| 523 |
+
row_class = " class='send-to-human'"
|
| 524 |
+
logger.info(f"Row {row['Index']} marked as 'Send to Human'")
|
| 525 |
elif medium_coverage:
|
| 526 |
row_class = " class='medium-coverage'"
|
| 527 |
logger.info(f"Row {row['Index']} marked as 'Medium Information Coverage'")
|
| 528 |
+
elif low_coverage:
|
| 529 |
+
row_class = " class='low-coverage'"
|
| 530 |
+
logger.info(f"Row {row['Index']} marked as 'Low Information Coverage'")
|
| 531 |
|
| 532 |
html_output += f"<tr{row_class}>"
|
| 533 |
html_output += f"<td style='text-align: center;'>{row['Index'] + 1}</td>"
|
|
|
|
| 652 |
|
| 653 |
with gr.Accordion("Row Color Legend", open=True):
|
| 654 |
gr.Markdown("""
|
| 655 |
+
* **Dark Green rows**: High Information Coverage - Information Coverage score is at least 0.8 (highest priority)
|
| 656 |
+
* **Red rows**: "Send to Human" is true but with Information Coverage below 0.8
|
| 657 |
* **Shallow Green rows**: Medium Information Coverage - Information Coverage score is between 0.5 and 0.8
|
| 658 |
+
* **Light Gray rows**: Low Information Coverage - Information Coverage score is below 0.5
|
| 659 |
+
|
| 660 |
+
The statistics section also includes "All Send to Human" count (including those with high coverage).
|
| 661 |
""")
|
| 662 |
|
| 663 |
file_input = gr.File(label="Upload JSON File", file_types=[".json"])
|