File size: 25,565 Bytes
57d5537
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6834f57
57d5537
 
4fce9b8
57d5537
 
 
 
 
 
4fce9b8
57d5537
4fce9b8
57d5537
 
 
 
 
c6fc807
57d5537
 
c6fc807
57d5537
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fc51ead
57d5537
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c6fc807
57d5537
 
 
 
 
 
 
 
 
 
a8d8165
57d5537
4fce9b8
57d5537
4fce9b8
57d5537
efbf2f4
57d5537
acfe5db
57d5537
 
 
 
c6fc807
57d5537
 
 
 
c6fc807
57d5537
 
 
c6fc807
57d5537
 
 
 
 
 
 
 
 
 
 
c6fc807
57d5537
 
 
 
c6fc807
57d5537
 
 
 
 
 
 
 
 
c6fc807
57d5537
 
 
 
c6fc807
57d5537
 
 
c6fc807
57d5537
 
 
 
c6fc807
57d5537
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
# from reviewer_feedback_agent.apps import app
# app()

import streamlit as st
import pandas as pd
import ast
import re
import PyPDF2
from PyPDF2 import PdfReader
import openreview
import json
import urllib.request
import requests
import os
import pickle
import openai
from openai import OpenAI
import anthropic
from anthropic import Anthropic

openai_api_key = os.environ["OPENAI_API_KEY"]
client_openai = OpenAI(api_key=openai_api_key)

anthropic_api_key = os.environ["ANTHROPIC_API_KEY"]
client_anthropic = Anthropic(api_key=anthropic_api_key)

def parse_quotes(input_string, pdf_text):

    header_pattern = r'\d+Under review as a conference paper at ICLR 2024'
    #r'^\d+Under review as a conference paper at ICLR 2024\s*'  # Pattern to match headers with variable page numbers
    # r'(?m)^Under review as a conference paper at ICLR 2024*$'

    pdf_text_wo_header = re.sub(header_pattern, '', pdf_text)
    # Remove new lines that are not followed by a period, exclamation mark, or question mark
    pdf_text_wo_header = re.sub(r'(?<!\.\s)(?<!\!\s)(?<!\?\s)\n+', ' ', pdf_text_wo_header)
    # Remove extra spaces that may have been introduced
    pdf_text_wo_header = re.sub(r'\s{2,}', ' ', pdf_text_wo_header).strip()
    
    # Find all matches of <quote>...</quote> and extract the content between the tags
    matches = re.findall(r'<quote>(.*?)</quote>', input_string)
    
    count = len(matches)
    extracted_texts = matches
    # with open('pdf_text.txt', 'w') as file:
    #     file.write(pdf_text_wo_header)
    # print(extracted_texts)
    match_count = sum(1 for text in extracted_texts if text in pdf_text_wo_header)
    
    return count, match_count

# load manual (human) annotations
def load_annotations():
    path = './annotations_8_26.csv'
    annotations = pd.read_csv(path)
    annotations.columns = annotations.columns.str.replace(' ', '_').str.lower()

    # 36 0, 15 1
    annotations['annotation_label'] = annotations['annotation_label'].astype(int)
    
    return annotations

# Check if the password matches the env variable
def check_password():
    def password_entered():
        if st.session_state["password"] == os.environ["APP_PASSCODE"]:
            st.session_state["password_correct"] = True
            del st.session_state["password"]  # Clear password from memory
        else:
            st.session_state["password_correct"] = False

    if "password_correct" not in st.session_state:
        st.text_input("Enter Password", type="password", on_change=password_entered, key="password")
        return False
    elif not st.session_state["password_correct"]:
        st.error("Password incorrect")
        return False
    else:
        return True

# Ask for password at the beginning
if not check_password():
    st.stop()

# converts paper pdf into text
def pdf_to_text(pdf):
    paper_text = ''

    reader = PdfReader(pdf)
    number_of_pages = len(reader.pages)
    for p in range(number_of_pages):
        page = reader.pages[p].get_object()
        text = page.extract_text()
        paper_text += text

    return paper_text

# loads all 2024 ICLR submissions from OpenReview
submissions_path = "./submissions_iclr2024.pkl"
# API V2
client = openreview.api.OpenReviewClient(
    baseurl='https://api2.openreview.net',
)

# Get ICLR venues
venues = client.get_group(id='venues').members
iclr_venues = [v for v in venues if "iclr.cc" in v.lower() and "conference" in v.lower()]

@st.cache_data
def load_ICLR_submissions():
    if os.path.exists(submissions_path):
        with open(submissions_path, "rb") as f:
            return pickle.load(f)
    else:
        # Select the second latest venue
        venue_id = iclr_venues[-2]
        venue_group = client.get_group(venue_id)
        submission_name = venue_group.content['submission_name']['value']
        submissions = client.get_all_notes(invitation=f'{venue_id}/-/{submission_name}', details='replies')
        with open(submissions_path, "wb") as f:
            pickle.dump(submissions, f)
        return submissions

# returns review and pdf paper text given paper id and reviewer id
def parse_openreview_id(submissions, paper_id, reviewer_id):
    paper_url = f"https://openreview.net/pdf?id={paper_id}"
    fields = ['summary', 'soundness', 'presentation', 'contribution', 'strengths', 'weaknesses', 'questions']

    ind = next((index for index, entry in enumerate(submissions) if entry.id == paper_id), None)
    curr_review = submissions[ind]
    bad_review = next((i for i, entry in enumerate(curr_review.details['replies'])
              if entry['signatures'][0].split('_')[-1] == reviewer_id), None)

    try:
        review_content = curr_review.details["replies"][bad_review]["content"]
    except:
        st.error("Paper ID or reviewer ID are incorrect")

    review_content = {key: review_content[key] if key in fields else None for key in review_content.keys() if key in fields}

    urllib.request.urlretrieve(paper_url, f"{paper_id}.pdf")
    pdf = f"{paper_id}.pdf"
    pdf_text = pdf_to_text(pdf)

    return review_content, pdf, pdf_text


def create_feedback(review, pdf_text, agent_prompt, model):

    messages = [{
        "role": "user",
        "content": [
      {
        "type": "text",
        "text": agent_prompt
      },
      {
        "type": "text",
        "text": "Here is the ML conference review"
      },
      {
        "type": "text",
        "text": json.dumps(review) #json.dumps(review)
      },
      {
        "type": "text",
        "text": "Finally, read the paper this review was written about"
      },
      {
        "type": "text",
        "text": pdf_text
      }
      ]}]

    if model == 'gpt':
        headers = {
        "Content-Type": "application/json",
        "Authorization": f"Bearer {openai_api_key}"
        }
        payload = {
        "model": "gpt-4o",
        "messages": messages,
        "max_tokens": 1000,
        "temperature": 0.2
        }

        try:
            response = requests.post("https://api.openai.com/v1/chat/completions", headers=headers, json=payload)
            feedback = response.json()["choices"][0]["message"]["content"]
        except Exception as e:
            print(f"An unexpected error occurred: {e}")
            feedback = "an error occured"

    else:
        message = client_anthropic.messages.create(max_tokens=1024, messages=messages, model="claude-3-5-sonnet-20240620")
        feedback = message.content[0].text

    return feedback

def aggregator(feedback_list, aggregator_prompt, agent_prompt, review, pdf_text, model):

    messages = [{
        "role": "user",
        "content": [
      {
        "type": "text",
        "text": aggregator_prompt
      },
      {
        "type": "text",
        "text": "Here is the ML conference review"
      },
      {
        "type": "text",
        "text": json.dumps(review) #json.dumps(review)
      },
      {
        "type": "text",
        "text": "Here is the list of feedback about the review, where each item is separated by the '^' character"
      },
      {
        "type": "text",
        "text": "^ ".join(feedback_list)
      },
      {
        "type": "text",
        "text": "Finally, read the paper this review was written about"
      },
      {
        "type": "text",
        "text": pdf_text
      }
      ]}]

    if model == 'gpt':
        headers = {
        "Content-Type": "application/json",
        "Authorization": f"Bearer {openai_api_key}"
        }
        payload = {
        "model": "gpt-4o-mini",
        "messages": messages,
        "max_tokens": 1000,
        "temperature": 0.2
        }

        try:
            response = requests.post("https://api.openai.com/v1/chat/completions", headers=headers, json=payload)
            best_feedback = response.json()["choices"][0]["message"]["content"]
        except Exception as e:
            print(f"An unexpected error occurred: {e}")
            best_feedback = "an error occured"

    else:
        message = client_anthropic.messages.create(max_tokens=1024, messages=messages, model="claude-3-5-sonnet-20240620")
        best_feedback = message.content[0].text

    return best_feedback


def critic(review, feedback, pdf_text, critic_prompt, model):
    
    messages = [{
        "role": "user",
        "content": [
      {
        "type": "text",
        "text": critic_prompt
      },
      {
        "type": "text",
        "text": "Here is the ML conference review"
      },
      {
        "type": "text",
        "text": json.dumps(review) #json.dumps(review)
      },
      {
        "type": "text",
        "text": "Here is the feedback about the review"
      },
      {
        "type": "text",
        "text": feedback
      },
      {
        "type": "text",
        "text": "Finally, read the paper this review was written about"
      },
      {
        "type": "text",
        "text": pdf_text
      }
      ]}]

    if model == 'gpt':
        headers = {
        "Content-Type": "application/json",
        "Authorization": f"Bearer {openai_api_key}"
        }
        payload = {
        "model": "gpt-4o",
        "messages": messages,
        "max_tokens": 1000,
        "temperature": 0.2
        }

        try:
            response = requests.post("https://api.openai.com/v1/chat/completions", headers=headers, json=payload)
            revised_feedback = response.json()["choices"][0]["message"]["content"]
        except Exception as e:
            print(f"An unexpected error occurred: {e}")
            revised_feedback = "an error occured"

    else:
        message = client_anthropic.messages.create(max_tokens=1024, messages=messages, model="claude-3-5-sonnet-20240620")
        revised_feedback = message.content[0].text

    return revised_feedback

agent_prompt = """
You are given a peer review of a machine learning paper submitted to a top-tier ML conference on OpenReview. Your task is to provide constructive feedback to the reviewer so that it becomes a high-quality review. You will do this by evaluating the review against a checklist and providing specific feedback about where the review fails. 

Here are step-by-step instructions:
1. Read the text of the review and the paper about which the review was written.

2. Evaluate every comment in the review:
   - Focus on comments made in the "weaknesses" or "questions" sections of the review. Ignore the "summary" and "strengths" sections.
   - For each comment, evaluate it against the following checklist. Follow the examples for how to respond.

     Checklist:
     1. Check if the reviewer requests something obviously present in the paper. Only respond if certain of the reviewer's error. If so, quote the relevant paper section verbatim using <quote> </quote> tags and explain how it addresses the reviewer's point. Use only exact quotes and don't comment if uncertain.
        - Example 1: 
          - **Reviewer Comment:** *..In Figure 4, the efficiency experiments have no results for Transformer models, which is a key limitation of the paper.* 
          - **Feedback to reviewer:** You may want to check Section 3, Figure 5 of the paper which has the Transformer results. See: <quote> In Transformers, the proposed technique provides 25% relative improvement in wall-clock time (Figure 5) </quote>.
        - Example 2:
            - **Reviewer Comment:** *Figure 2. Are people forced to select a choice or could they select 'I don't know'? Did you monitor response times to see if the manipulated images required longer times for individuals to pass decisions? In Appendix A, you mention “the response times will also be released upon publication”, however, I do not see further information about this in the paper.*
            - As the reviewer already refers to the key part of the paper with quotes and asks a question that is not answered in the paper, we do not need to give feedback to this comment.

     2. Look for any vague or unjustifiable claims in the review. This results in points that are not actionable or harder to respond to. For such cases, we would like to nudge the reviewer to provide more specific details and justify their claim.
        - Example 1: 
          - **Reviewer Comment:** *A key limitation is that this paper motivates from the TTT perspective, but no TTT experiments are performed and compared, e.g., comparing with (Sun et al., 2020).*
          - **Feedback to reviewer:** In general, a “TTT experiment” is not a broadly known terminology. It would be very helpful if you could describe what specific experiment you are referring to, and why it is important for this paper.
        - Example 2:
            - **Reviewer Comment:** *W1: Many of the key pieces of this work have been considered before separately. I think some additional discussion of related work is needed. W2: It appears that the linear mode connectivity results may be somewhat brittle.*
            - **Feedback to reviewer:** For W1, It would be very helpful to specify or cite what key pieces are considered in earlier works, how they relate to the current work, and specify what is missing. For W2, could you elaborate on why you see the results as brittle and what would be convincing evidence so that the feedback is more actionable?
        - Example 3:
            - **Reviewer Comment:** *The data and model size are not large-scale, thus the paper will not be impactful.*
            - **Feedback to reviewer:** Please consider putting this claim in context. If possible, please discuss why you consider the experiments to be not large-scale using precedents, why it is important to have larger-scale experiments in this context, and how it would inform or improve the manuscript.
     3. If the reviewer claims the paper lacks novelty, ensure they specify why, including references to similar work. If they haven't, we would like to nudge the reviewer to justify the claim, by prompting them to provide the most relevant references, the relationships, and specifying similarities or differences.
        - Example 1: 
            - **Reviewer Comment:** *.. The paper's novelty is limited considering the ICLR standards, as there are very close works [1,2,3]. *
            - **Feedback to reviewer:** Please consider the reasons for why the novelty is limited, and specify what ICLR standards are in this context. In particular, it would be very helpful to all parties involved if you give examples of the closest papers, their similarities, and differences with the methods or results in the current paper.
        - Example 2:
            - **Reviewer Comment:** *.. DASHA is a mash-up between MARINA and existing distributed nonconvex optimization methods. Other than the fact that three variants of DASHA get rid of the uncompressed synchronization in MARINA, this reviewer could not pinpoint a difference between MARINA and DASHA. As such, the main novelty of this work seems to be in terms of theoretical analysis of MARINA when the uncompressed synchronization step is removed. The authors could have done a better job of clarifying where does this novelty lie in the analysis (e.g., pinpointing the key analytical approaches in the lemma that helped improve the analysis)*
            - As the novelty claim is already well-justified and an actionable question is asked, we do not need to give feedback to this review.
     4. Identify any personal attacks or inappropriate remarks made by the reviewer. This can be about the personality, the knowledge, or the experience of the authors. For example, they call the work "incompetent" without justifying why. For this case, we would like to kindly warn the reviewer about their comment and politely suggest they revise their language.
        - Example 1: 
            - **Reviewer Comment:** *.. The authors clearly do not live in the real world and do not care about people or downstream effects of their research. *
            - **Feedback to the reviewer:** We kindly suggest you revise this comment, as it includes remarks about the personalities or intents of the authors.

3. Provide feedback:
    - For each comment that fails according to the checklist, write concise feedback in the following format:
        - Comment: {{the comment of interest}}
        - Feedback: {{your short feedback}}
    - If you do not identify any issues with a comment, do not include it in your feedback list.
    - If you find no issues in the review at all, respond with: "Thanks for your hard work!"

Remember:
- Be concise, limiting your feedback for each comment to 1-2 sentences.
- Do not summarize your feedback at the end or include a preamble at the beginning.
- Do not repeat anything the reviewer already included in their review.
- Do not mention that you are using a checklist or guidelines.
- Do not address the authors at all or provide suggestions to the authors. You are only giving feedback to the reviewer.
"""

critic_prompt = f"""
You are given a list of feedback about a peer review of a machine learning paper submitted to a top-tier ML conference on OpenReview. The aim of the feedback is to guide a reviewer to make the review high-quality. Your task is to edit the feedback for correctness and clarity.

Here are step-by-step instructions:
1. Read the text of the review, the feedback list provided for that review, and the paper about which the review was written.

2. Evaluate every piece of feedback in the feedback list:
   - For each feedback item, it is imperative that you evaluate the correctness of the feedback. If there is a quote in the feedback, ensure that the quote appears VERBATIM in the paper. You need to check every quote and factual claim in the feedback and edit for correctness, as it is imperative all the feedback is correct.
   - For each feedback item, evaluate if it is clear. You should make sure it would not confuse or frustrate the reviewer who reads it.
   - Make sure every comment-feedback pair addresses an issue with the review, otherwise remove it.

3. Edit comments based on evaluations:
    - Do not add any new points unless the previous feedback obviously missed something important.
    - For each comment that needs editing, re-write the feedback concisely in the following format:
        - Comment: {{the comment of interest}}
        - Feedback: {{your short feedback}}
    - If you do not identify any issues with a comment-feedback pair, do not edit it.

4. Remove any comment-feedback pairs where the feedback is that there is no feedback, no edits needed, or the comment is good. The feedback should only be about edits that need to be made.

Remember:
- Be concise, limiting your feedback for each comment to 1-2 sentences.
- Do not summarize your feedback at the end or include a preamble at the beginning.
- Do not repeat anything the reviewer already included in their review.
- Do not mention that you are using a checklist or guidelines.
- Do not address the authors at all or provide suggestions to the authors. You are only giving feedback to the reviewer.

Here are the guidelines that were followed to generate the feedback list originally; you should adhere to these guidelines: {agent_prompt}.
"""

aggregator_prompt = f"""
You are given multiple lists of feedback about a peer review of a machine learning paper submitted to a top-tier ML conference on OpenReview. The aim of the feedback is to guide a reviewer to make the review high-quality. Your task is to aggregate the lists of feedback into one list.

Here are step-by-step instructions:
1. Read the text of the review, the multiple feedback lists provided for that review, and the paper about which the review was written.

2. For all feedback lists, aggregate them into one list with the best comment-feedback pairs from each list.
    - For each comment-feedback pair in the multiple lists that are similar, determine which provides the best feedback and keep only that pair.
    - If there are unique comment-feedback pairs in the multiple lists, criticially determine if it is an essential piece of feedback needed to improve the review. If it us unncessary or redundant, remove the comment-feedback pair.
    - You should end up with one feedback list that has no repeated comments from the review and that is high quality.
    - Return the feedback list in the format you received it in, where the pairs are formatted as:
        - Comment: {{the comment of interest}}
        - Feedback: {{your short feedback}}

Here are the guidelines that were followed to generate the feedback lists originally: {agent_prompt}.
"""

# Set page to wide mode
st.set_page_config(layout="wide")

# Sidebar for navigation
st.sidebar.title('Input review and PDF or OpenReview ID')

option = st.sidebar.radio(
    "Choose one input option:",
    ("Upload PDF with Review", "OpenReview paper ID"))

# # Add a text input box to the sidebar for user input
# user_input = st.sidebar.text_input("Enter OpenReview ID (e.g. xC8xh2RSs2)")

user_input = False

if option == "OpenReview paper ID":
    paper_id = st.text_input("Enter OpenReview ID (e.g. xC8xh2RSs2):")
    paper_id = paper_id.strip()
    reviewer_id = st.text_input("Enter reviewer ID (e.g. gNxe):")
    reviewer_id = reviewer_id.strip()
    model = st.text_input("Which model? ('gpt' or 'claude')")
    iterations = st.text_input("How many iterations to run agent for?")
    if paper_id and reviewer_id and model and iterations:
        upload_file = False
        user_input = True
        submissions = load_ICLR_submissions()
        review, pdf, pdf_text = parse_openreview_id(submissions, paper_id, reviewer_id)
        # st.write(f"Review text: {pdf_text}")

elif option == "Upload PDF with Review":
    user_text = st.text_area("Enter review:")
    uploaded_file = st.file_uploader("Upload PDF", type="pdf")
    model = st.text_input("Which model? ('gpt' or 'claude')")
    iterations = st.text_input("How many iterations to run agent for?")
    if user_text and uploaded_file and model and iterations:
        upload_file = True
        user_input = True
        review, pdf = user_text, uploaded_file
        pdf_text = pdf_to_text(pdf)

        # st.write(f"Review text: {pdf_text}")
        # st.write(f"You entered review: {user_text}")
        # st.write(f"Uploaded file: {uploaded_file.name}")

if user_input:
    annotations = load_annotations()
    
    feedback_list = []
    # Run your pipeline to generate the dataframe based on user input
    iterations = int(iterations)
    if iterations > 1:
        for _ in range(iterations):
            feedback = create_feedback(review, pdf_text, agent_prompt, model)
            feedback_list.append(feedback)
        best_feedback = aggregator(feedback_list, aggregator_prompt, agent_prompt, review, pdf_text, model)
    else:
        best_feedback = create_feedback(review, pdf_text, agent_prompt, model)
    
    revised_feedback = critic(review, best_feedback, pdf_text, critic_prompt, model)
    
    count, match_count = parse_quotes(revised_feedback, pdf_text)
    
    revised_feedback = revised_feedback.replace("<quote>", "'").replace("</quote>", "'")

    st.title(f'Review feedback')

    if not upload_file and annotations['submission_id'].str.contains(str(paper_id)).any():
        st.write(f'We have a human annotation for {paper_id}')
        # Create four columns
        col1, col2, col3, col4 = st.columns(4)
    
        # Column 1: Display review fields
        with col1:
            st.subheader("Review")
            st.write(json.dumps(review))
    
            if not upload_file:
                pdf_url = f"https://openreview.net/pdf?id={paper_id}"
                st.markdown(f"[Click here to view PDF]({pdf_url})")
    
        # Column 2: Display human annotations
        with col2:
            st.subheader('Human annotations')
            if annotations.loc[(annotations['submission_id'] == paper_id), 'annotation_label'].item() == 1:
                sentences = annotations.loc[(annotations['submission_id'] == paper_id), 'annotation_sentences'].item()
                sentences = ast.literal_eval(sentences)
                st.write(sentences)
                # for s in sentences:
                #     st.write(f"- {s}")
            else:
                st.write("No human feedback on this review")
        
        # Column 3: Display feedback
        with col3:
            st.subheader('Best Feedback')
            st.write(best_feedback)
    
        # Column 4: Display revised feedback (from critic)
        with col4:
            st.subheader('Revised Feedback')
            if count > 0: st.write(f"Quotes found verbatim in pdf text: {match_count}/{count}")
            st.write(revised_feedback)
    else:

        # Create three columns
        col1, col2, col3 = st.columns(3)
    
        # Column 1: Display review fields
        with col1:
            st.subheader("Review")
            st.write(json.dumps(review))
    
            if not upload_file:
                pdf_url = f"https://openreview.net/pdf?id={paper_id}"
                st.markdown(f"[Click here to view PDF]({pdf_url})")
    
        # Column 2: Display feedback
        with col2:
            st.subheader('Best Feedback')
            st.write(best_feedback)
    
        # Column 3: Display revised feedback (from critic)
        with col3:
            st.subheader('Revised Feedback')
            if count > 0: st.write(f"Quotes found verbatim in pdf text: {match_count}/{count}")
            st.write(revised_feedback)

else:
    st.title('Please enter OpenReview ID or upload PDF with review to generate feedback')