Sina1138 commited on
Commit Β·
07f31c1
1
Parent(s): 97f478d
Enhance review display: add HTML formatting for rebuttals and update state handling for rebuttal visibility
Browse files- interface/Demo.py +31 -21
interface/Demo.py
CHANGED
|
@@ -543,19 +543,28 @@ with gr.Blocks(title="ReView", css=CUSTOM_CSS) as demo:
|
|
| 543 |
|
| 544 |
number_of_displayed_reviews = len(current_review)
|
| 545 |
review_updates = []
|
|
|
|
| 546 |
consensuality_dict = {}
|
| 547 |
-
all_rebuttals = []
|
| 548 |
|
| 549 |
for i in range(10):
|
| 550 |
if i < number_of_displayed_reviews:
|
| 551 |
# Handle new structure: current_review[i] can be dict with "sentences" and "rebuttal"
|
| 552 |
# OR old structure: just a dict of sentences
|
| 553 |
review_data = current_review[i]
|
|
|
|
|
|
|
| 554 |
if isinstance(review_data, dict) and "sentences" in review_data:
|
| 555 |
review_item = list(review_data["sentences"].items())
|
| 556 |
rebuttal = review_data.get("rebuttal", "")
|
| 557 |
if rebuttal and rebuttal.strip():
|
| 558 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 559 |
else:
|
| 560 |
# Backward compatibility with old format
|
| 561 |
review_item = list(review_data.items())
|
|
@@ -605,6 +614,7 @@ with gr.Blocks(title="ReView", css=CUSTOM_CSS) as demo:
|
|
| 605 |
key=f"updated_{score_type}_{i}"
|
| 606 |
)
|
| 607 |
)
|
|
|
|
| 608 |
else:
|
| 609 |
review_updates.append(
|
| 610 |
gr.update(
|
|
@@ -615,20 +625,10 @@ with gr.Blocks(title="ReView", css=CUSTOM_CSS) as demo:
|
|
| 615 |
key=f"updated_{score_type}_{i}"
|
| 616 |
)
|
| 617 |
)
|
|
|
|
| 618 |
|
| 619 |
-
#
|
| 620 |
-
|
| 621 |
-
if all_rebuttals:
|
| 622 |
-
rebuttal_text = "\n\n---\n\n".join(all_rebuttals)
|
| 623 |
-
else:
|
| 624 |
-
# Fallback to metadata for backward compatibility
|
| 625 |
-
current_forum_id = review_ids[current_index]
|
| 626 |
-
paper_metadata = state.get("metadata_for_year", {}).get(current_forum_id, {})
|
| 627 |
-
rebuttal_text = paper_metadata.get("rebuttal", "") or ""
|
| 628 |
-
|
| 629 |
-
has_rebuttal = bool(rebuttal_text.strip())
|
| 630 |
-
rebuttal_header_update = gr.update(visible=has_rebuttal)
|
| 631 |
-
rebuttal_display_update = gr.update(visible=has_rebuttal, value=rebuttal_text if has_rebuttal else "")
|
| 632 |
|
| 633 |
# Set most consensual / unique sentences
|
| 634 |
if show_consensuality and consensuality_dict:
|
|
@@ -671,8 +671,8 @@ with gr.Blocks(title="ReView", css=CUSTOM_CSS) as demo:
|
|
| 671 |
most_common_visibility,
|
| 672 |
most_unique_visibility,
|
| 673 |
topic_color_map_visibility,
|
| 674 |
-
|
| 675 |
-
|
| 676 |
state
|
| 677 |
)
|
| 678 |
|
|
@@ -680,7 +680,7 @@ with gr.Blocks(title="ReView", css=CUSTOM_CSS) as demo:
|
|
| 680 |
|
| 681 |
# Precompute the initial outputs so something is shown on load.
|
| 682 |
init_display = update_review_display(initial_state, score_type="Original")
|
| 683 |
-
# init_display returns: (review_id, review1..10, most_common, most_unique, topic_box,
|
| 684 |
|
| 685 |
with gr.Row():
|
| 686 |
|
|
@@ -726,18 +726,28 @@ with gr.Blocks(title="ReView", css=CUSTOM_CSS) as demo:
|
|
| 726 |
|
| 727 |
gr.Markdown("### π Reviews", elem_classes=["review-section-header"])
|
| 728 |
review1 = gr.HighlightedText(show_legend=False, label="π Review 1", visible=number_of_displayed_reviews >= 1, key="initial_review1")
|
|
|
|
| 729 |
review2 = gr.HighlightedText(show_legend=False, label="π Review 2", visible=number_of_displayed_reviews >= 2, key="initial_review2")
|
|
|
|
| 730 |
review3 = gr.HighlightedText(show_legend=False, label="π Review 3", visible=number_of_displayed_reviews >= 3, key="initial_review3")
|
|
|
|
| 731 |
review4 = gr.HighlightedText(show_legend=False, label="π Review 4", visible=number_of_displayed_reviews >= 4, key="initial_review4")
|
|
|
|
| 732 |
review5 = gr.HighlightedText(show_legend=False, label="π Review 5", visible=number_of_displayed_reviews >= 5, key="initial_review5")
|
|
|
|
| 733 |
review6 = gr.HighlightedText(show_legend=False, label="π Review 6", visible=number_of_displayed_reviews >= 6, key="initial_review6")
|
|
|
|
| 734 |
review7 = gr.HighlightedText(show_legend=False, label="π Review 7", visible=number_of_displayed_reviews >= 7, key="initial_review7")
|
|
|
|
| 735 |
review8 = gr.HighlightedText(show_legend=False, label="π Review 8", visible=number_of_displayed_reviews >= 8, key="initial_review8")
|
|
|
|
| 736 |
review9 = gr.HighlightedText(show_legend=False, label="π Review 9", visible=number_of_displayed_reviews >= 9, key="initial_review9")
|
|
|
|
| 737 |
review10 = gr.HighlightedText(show_legend=False, label="π Review 10", visible=number_of_displayed_reviews >= 10, key="initial_review10")
|
|
|
|
| 738 |
|
| 739 |
-
|
| 740 |
-
|
| 741 |
|
| 742 |
# Callback functions that update state.
|
| 743 |
def year_change(year, state, score_type):
|
|
@@ -760,7 +770,7 @@ with gr.Blocks(title="ReView", css=CUSTOM_CSS) as demo:
|
|
| 760 |
return update_review_display(state, score_type)
|
| 761 |
|
| 762 |
# Hook up the callbacks with the session state.
|
| 763 |
-
_review_outputs = [review_id, review1, review2, review3, review4, review5, review6, review7, review8, review9, review10, most_common_sentences, most_unique_sentences, topic_text_box,
|
| 764 |
year.change(fn=year_change, inputs=[year, state, score_type], outputs=_review_outputs)
|
| 765 |
score_type.change(fn=update_review_display, inputs=[state, score_type], outputs=_review_outputs)
|
| 766 |
next_button.click(fn=next_review, inputs=[state, score_type], outputs=_review_outputs)
|
|
|
|
| 543 |
|
| 544 |
number_of_displayed_reviews = len(current_review)
|
| 545 |
review_updates = []
|
| 546 |
+
rebuttal_updates = []
|
| 547 |
consensuality_dict = {}
|
|
|
|
| 548 |
|
| 549 |
for i in range(10):
|
| 550 |
if i < number_of_displayed_reviews:
|
| 551 |
# Handle new structure: current_review[i] can be dict with "sentences" and "rebuttal"
|
| 552 |
# OR old structure: just a dict of sentences
|
| 553 |
review_data = current_review[i]
|
| 554 |
+
rebuttal_html = ""
|
| 555 |
+
|
| 556 |
if isinstance(review_data, dict) and "sentences" in review_data:
|
| 557 |
review_item = list(review_data["sentences"].items())
|
| 558 |
rebuttal = review_data.get("rebuttal", "")
|
| 559 |
if rebuttal and rebuttal.strip():
|
| 560 |
+
# Format rebuttal as HTML card
|
| 561 |
+
rebuttal_html = (
|
| 562 |
+
'<div style="margin-top:8px;margin-bottom:12px;border-radius:6px;overflow:hidden;border:1px solid #fde68a;background:#fffef5;">'
|
| 563 |
+
'<div style="padding:10px 14px;">'
|
| 564 |
+
'<div style="font-size:0.75em;color:#92400e;font-weight:600;margin-bottom:4px;">π¬ Author Response:</div>'
|
| 565 |
+
f'<div style="white-space:pre-wrap;color:#1f2937;font-size:0.85em;line-height:1.5;">{rebuttal}</div>'
|
| 566 |
+
'</div></div>'
|
| 567 |
+
)
|
| 568 |
else:
|
| 569 |
# Backward compatibility with old format
|
| 570 |
review_item = list(review_data.items())
|
|
|
|
| 614 |
key=f"updated_{score_type}_{i}"
|
| 615 |
)
|
| 616 |
)
|
| 617 |
+
rebuttal_updates.append(gr.update(visible=bool(rebuttal_html), value=rebuttal_html))
|
| 618 |
else:
|
| 619 |
review_updates.append(
|
| 620 |
gr.update(
|
|
|
|
| 625 |
key=f"updated_{score_type}_{i}"
|
| 626 |
)
|
| 627 |
)
|
| 628 |
+
rebuttal_updates.append(gr.update(visible=False, value=""))
|
| 629 |
|
| 630 |
+
# General rebuttal display (currently unused in new format, kept for backward compat)
|
| 631 |
+
general_rebuttal_update = gr.update(visible=False, value="")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 632 |
|
| 633 |
# Set most consensual / unique sentences
|
| 634 |
if show_consensuality and consensuality_dict:
|
|
|
|
| 671 |
most_common_visibility,
|
| 672 |
most_unique_visibility,
|
| 673 |
topic_color_map_visibility,
|
| 674 |
+
*rebuttal_updates, # 10 per-review rebuttals
|
| 675 |
+
general_rebuttal_update, # General rebuttal section
|
| 676 |
state
|
| 677 |
)
|
| 678 |
|
|
|
|
| 680 |
|
| 681 |
# Precompute the initial outputs so something is shown on load.
|
| 682 |
init_display = update_review_display(initial_state, score_type="Original")
|
| 683 |
+
# init_display returns: (review_id, review1..10, most_common, most_unique, topic_box, prep_rebuttal1..10, prep_general_rebuttal, state)
|
| 684 |
|
| 685 |
with gr.Row():
|
| 686 |
|
|
|
|
| 726 |
|
| 727 |
gr.Markdown("### π Reviews", elem_classes=["review-section-header"])
|
| 728 |
review1 = gr.HighlightedText(show_legend=False, label="π Review 1", visible=number_of_displayed_reviews >= 1, key="initial_review1")
|
| 729 |
+
prep_rebuttal1 = gr.HTML(visible=False, value="")
|
| 730 |
review2 = gr.HighlightedText(show_legend=False, label="π Review 2", visible=number_of_displayed_reviews >= 2, key="initial_review2")
|
| 731 |
+
prep_rebuttal2 = gr.HTML(visible=False, value="")
|
| 732 |
review3 = gr.HighlightedText(show_legend=False, label="π Review 3", visible=number_of_displayed_reviews >= 3, key="initial_review3")
|
| 733 |
+
prep_rebuttal3 = gr.HTML(visible=False, value="")
|
| 734 |
review4 = gr.HighlightedText(show_legend=False, label="π Review 4", visible=number_of_displayed_reviews >= 4, key="initial_review4")
|
| 735 |
+
prep_rebuttal4 = gr.HTML(visible=False, value="")
|
| 736 |
review5 = gr.HighlightedText(show_legend=False, label="π Review 5", visible=number_of_displayed_reviews >= 5, key="initial_review5")
|
| 737 |
+
prep_rebuttal5 = gr.HTML(visible=False, value="")
|
| 738 |
review6 = gr.HighlightedText(show_legend=False, label="π Review 6", visible=number_of_displayed_reviews >= 6, key="initial_review6")
|
| 739 |
+
prep_rebuttal6 = gr.HTML(visible=False, value="")
|
| 740 |
review7 = gr.HighlightedText(show_legend=False, label="π Review 7", visible=number_of_displayed_reviews >= 7, key="initial_review7")
|
| 741 |
+
prep_rebuttal7 = gr.HTML(visible=False, value="")
|
| 742 |
review8 = gr.HighlightedText(show_legend=False, label="π Review 8", visible=number_of_displayed_reviews >= 8, key="initial_review8")
|
| 743 |
+
prep_rebuttal8 = gr.HTML(visible=False, value="")
|
| 744 |
review9 = gr.HighlightedText(show_legend=False, label="π Review 9", visible=number_of_displayed_reviews >= 9, key="initial_review9")
|
| 745 |
+
prep_rebuttal9 = gr.HTML(visible=False, value="")
|
| 746 |
review10 = gr.HighlightedText(show_legend=False, label="π Review 10", visible=number_of_displayed_reviews >= 10, key="initial_review10")
|
| 747 |
+
prep_rebuttal10 = gr.HTML(visible=False, value="")
|
| 748 |
|
| 749 |
+
# General rebuttal section (for rebuttals not tied to specific reviews)
|
| 750 |
+
prep_general_rebuttal = gr.HTML(visible=False, value="")
|
| 751 |
|
| 752 |
# Callback functions that update state.
|
| 753 |
def year_change(year, state, score_type):
|
|
|
|
| 770 |
return update_review_display(state, score_type)
|
| 771 |
|
| 772 |
# Hook up the callbacks with the session state.
|
| 773 |
+
_review_outputs = [review_id, review1, review2, review3, review4, review5, review6, review7, review8, review9, review10, most_common_sentences, most_unique_sentences, topic_text_box, prep_rebuttal1, prep_rebuttal2, prep_rebuttal3, prep_rebuttal4, prep_rebuttal5, prep_rebuttal6, prep_rebuttal7, prep_rebuttal8, prep_rebuttal9, prep_rebuttal10, prep_general_rebuttal, state]
|
| 774 |
year.change(fn=year_change, inputs=[year, state, score_type], outputs=_review_outputs)
|
| 775 |
score_type.change(fn=update_review_display, inputs=[state, score_type], outputs=_review_outputs)
|
| 776 |
next_button.click(fn=next_review, inputs=[state, score_type], outputs=_review_outputs)
|