nityathakkar commited on
Commit
86c3e09
·
verified ·
1 Parent(s): 4f2fae6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +529 -526
app.py CHANGED
@@ -1,548 +1,551 @@
1
- import streamlit as st
2
- import pandas as pd
3
- import ast
4
- import re
5
- import PyPDF2
6
- from PyPDF2 import PdfReader
7
- import openreview
8
- import json
9
- import urllib.request
10
- import requests
11
- import os
12
- import pickle
13
- import openai
14
- from openai import OpenAI
15
- import anthropic
16
- from anthropic import Anthropic
17
-
18
- openai_api_key = os.environ["OPENAI_API_KEY"]
19
- client_openai = OpenAI(api_key=openai_api_key)
20
-
21
- anthropic_api_key = os.environ["ANTHROPIC_API_KEY"]
22
- client_anthropic = Anthropic(api_key=anthropic_api_key)
23
-
24
- def parse_quotes(input_string, pdf_text):
25
-
26
- header_pattern = r'\d+Under review as a conference paper at ICLR 2024'
27
- #r'^\d+Under review as a conference paper at ICLR 2024\s*' # Pattern to match headers with variable page numbers
28
- # r'(?m)^Under review as a conference paper at ICLR 2024*$'
29
-
30
- pdf_text_wo_header = re.sub(header_pattern, '', pdf_text)
31
- # Remove new lines that are not followed by a period, exclamation mark, or question mark
32
- pdf_text_wo_header = re.sub(r'(?<!\.\s)(?<!\!\s)(?<!\?\s)\n+', ' ', pdf_text_wo_header)
33
- # Remove extra spaces that may have been introduced
34
- pdf_text_wo_header = re.sub(r'\s{2,}', ' ', pdf_text_wo_header).strip()
 
 
 
35
 
36
- # Find all matches of <quote>...</quote> and extract the content between the tags
37
- matches = re.findall(r'<quote>(.*?)</quote>', input_string)
38
 
39
- count = len(matches)
40
- extracted_texts = matches
41
- # with open('pdf_text.txt', 'w') as file:
42
- # file.write(pdf_text_wo_header)
43
- # print(extracted_texts)
44
- match_count = sum(1 for text in extracted_texts if text in pdf_text_wo_header)
45
 
46
- return count, match_count
47
 
48
- # load manual (human) annotations
49
- def load_annotations():
50
- path = './annotations_8_26.csv'
51
- annotations = pd.read_csv(path)
52
- annotations.columns = annotations.columns.str.replace(' ', '_').str.lower()
53
 
54
- # 36 0, 15 1
55
- annotations['annotation_label'] = annotations['annotation_label'].astype(int)
56
 
57
- return annotations
58
-
59
- # Check if the password matches the env variable
60
- def check_password():
61
- def password_entered():
62
- if st.session_state["password"] == os.environ["APP_PASSCODE"]:
63
- st.session_state["password_correct"] = True
64
- del st.session_state["password"] # Clear password from memory
65
- else:
66
- st.session_state["password_correct"] = False
67
-
68
- if "password_correct" not in st.session_state:
69
- st.text_input("Enter Password", type="password", on_change=password_entered, key="password")
70
- return False
71
- elif not st.session_state["password_correct"]:
72
- st.error("Password incorrect")
73
- return False
74
- else:
75
- return True
76
-
77
- # Ask for password at the beginning
78
- if not check_password():
79
- st.stop()
80
-
81
- # converts paper pdf into text
82
- def pdf_to_text(pdf):
83
- paper_text = ''
84
-
85
- reader = PdfReader(pdf)
86
- number_of_pages = len(reader.pages)
87
- for p in range(number_of_pages):
88
- page = reader.pages[p].get_object()
89
- text = page.extract_text()
90
- paper_text += text
91
-
92
- return paper_text
93
-
94
- # loads all 2024 ICLR submissions from OpenReview
95
- submissions_path = "./submissions_iclr2024.pkl"
96
- # API V2
97
- client = openreview.api.OpenReviewClient(
98
- baseurl='https://api2.openreview.net',
99
- )
100
-
101
- # Get ICLR venues
102
- venues = client.get_group(id='venues').members
103
- iclr_venues = [v for v in venues if "iclr.cc" in v.lower() and "conference" in v.lower()]
104
-
105
- @st.cache_data
106
- def load_ICLR_submissions():
107
- if os.path.exists(submissions_path):
108
- with open(submissions_path, "rb") as f:
109
- return pickle.load(f)
110
- else:
111
- # Select the second latest venue
112
- venue_id = iclr_venues[-2]
113
- venue_group = client.get_group(venue_id)
114
- submission_name = venue_group.content['submission_name']['value']
115
- submissions = client.get_all_notes(invitation=f'{venue_id}/-/{submission_name}', details='replies')
116
- with open(submissions_path, "wb") as f:
117
- pickle.dump(submissions, f)
118
- return submissions
119
-
120
- # returns review and pdf paper text given paper id and reviewer id
121
- def parse_openreview_id(submissions, paper_id, reviewer_id):
122
- paper_url = f"https://openreview.net/pdf?id={paper_id}"
123
- fields = ['summary', 'soundness', 'presentation', 'contribution', 'strengths', 'weaknesses', 'questions']
124
-
125
- ind = next((index for index, entry in enumerate(submissions) if entry.id == paper_id), None)
126
- curr_review = submissions[ind]
127
- bad_review = next((i for i, entry in enumerate(curr_review.details['replies'])
128
- if entry['signatures'][0].split('_')[-1] == reviewer_id), None)
129
-
130
- try:
131
- review_content = curr_review.details["replies"][bad_review]["content"]
132
- except:
133
- st.error("Paper ID or reviewer ID are incorrect")
134
-
135
- review_content = {key: review_content[key] if key in fields else None for key in review_content.keys() if key in fields}
136
-
137
- urllib.request.urlretrieve(paper_url, f"{paper_id}.pdf")
138
- pdf = f"{paper_id}.pdf"
139
- pdf_text = pdf_to_text(pdf)
140
-
141
- return review_content, pdf, pdf_text
142
-
143
-
144
- def create_feedback(review, pdf_text, agent_prompt, model):
145
-
146
- messages = [{
147
- "role": "user",
148
- "content": [
149
- {
150
- "type": "text",
151
- "text": agent_prompt
152
- },
153
- {
154
- "type": "text",
155
- "text": "Here is the ML conference review"
156
- },
157
- {
158
- "type": "text",
159
- "text": json.dumps(review) #json.dumps(review)
160
- },
161
- {
162
- "type": "text",
163
- "text": "Finally, read the paper this review was written about"
164
- },
165
- {
166
- "type": "text",
167
- "text": pdf_text
168
- }
169
- ]}]
170
-
171
- if model == 'gpt':
172
- headers = {
173
- "Content-Type": "application/json",
174
- "Authorization": f"Bearer {openai_api_key}"
175
- }
176
- payload = {
177
- "model": "gpt-4o",
178
- "messages": messages,
179
- "max_tokens": 1000,
180
- "temperature": 0.2
181
- }
182
-
183
- try:
184
- response = requests.post("https://api.openai.com/v1/chat/completions", headers=headers, json=payload)
185
- feedback = response.json()["choices"][0]["message"]["content"]
186
- except Exception as e:
187
- print(f"An unexpected error occurred: {e}")
188
- feedback = "an error occured"
189
-
190
- else:
191
- message = client_anthropic.messages.create(max_tokens=1024, messages=messages, model="claude-3-5-sonnet-20240620")
192
- feedback = message.content[0].text
193
-
194
- return feedback
195
-
196
- def aggregator(feedback_list, aggregator_prompt, agent_prompt, review, pdf_text, model):
197
-
198
- messages = [{
199
- "role": "user",
200
- "content": [
201
- {
202
- "type": "text",
203
- "text": aggregator_prompt
204
- },
205
- {
206
- "type": "text",
207
- "text": "Here is the ML conference review"
208
- },
209
- {
210
- "type": "text",
211
- "text": json.dumps(review) #json.dumps(review)
212
- },
213
- {
214
- "type": "text",
215
- "text": "Here is the list of feedback about the review, where each item is separated by the '^' character"
216
- },
217
- {
218
- "type": "text",
219
- "text": "^ ".join(feedback_list)
220
- },
221
- {
222
- "type": "text",
223
- "text": "Finally, read the paper this review was written about"
224
- },
225
- {
226
- "type": "text",
227
- "text": pdf_text
228
- }
229
- ]}]
230
-
231
- if model == 'gpt':
232
- headers = {
233
- "Content-Type": "application/json",
234
- "Authorization": f"Bearer {openai_api_key}"
235
- }
236
- payload = {
237
- "model": "gpt-4o-mini",
238
- "messages": messages,
239
- "max_tokens": 1000,
240
- "temperature": 0.2
241
- }
242
-
243
- try:
244
- response = requests.post("https://api.openai.com/v1/chat/completions", headers=headers, json=payload)
245
- best_feedback = response.json()["choices"][0]["message"]["content"]
246
- except Exception as e:
247
- print(f"An unexpected error occurred: {e}")
248
- best_feedback = "an error occured"
249
-
250
- else:
251
- message = client_anthropic.messages.create(max_tokens=1024, messages=messages, model="claude-3-5-sonnet-20240620")
252
- best_feedback = message.content[0].text
253
-
254
- return best_feedback
255
-
256
-
257
- def critic(review, feedback, pdf_text, critic_prompt, model):
258
 
259
- messages = [{
260
- "role": "user",
261
- "content": [
262
- {
263
- "type": "text",
264
- "text": critic_prompt
265
- },
266
- {
267
- "type": "text",
268
- "text": "Here is the ML conference review"
269
- },
270
- {
271
- "type": "text",
272
- "text": json.dumps(review) #json.dumps(review)
273
- },
274
- {
275
- "type": "text",
276
- "text": "Here is the feedback about the review"
277
- },
278
- {
279
- "type": "text",
280
- "text": feedback
281
- },
282
- {
283
- "type": "text",
284
- "text": "Finally, read the paper this review was written about"
285
- },
286
- {
287
- "type": "text",
288
- "text": pdf_text
289
- }
290
- ]}]
291
-
292
- if model == 'gpt':
293
- headers = {
294
- "Content-Type": "application/json",
295
- "Authorization": f"Bearer {openai_api_key}"
296
- }
297
- payload = {
298
- "model": "gpt-4o",
299
- "messages": messages,
300
- "max_tokens": 1000,
301
- "temperature": 0.2
302
- }
303
-
304
- try:
305
- response = requests.post("https://api.openai.com/v1/chat/completions", headers=headers, json=payload)
306
- revised_feedback = response.json()["choices"][0]["message"]["content"]
307
- except Exception as e:
308
- print(f"An unexpected error occurred: {e}")
309
- revised_feedback = "an error occured"
310
-
311
- else:
312
- message = client_anthropic.messages.create(max_tokens=1024, messages=messages, model="claude-3-5-sonnet-20240620")
313
- revised_feedback = message.content[0].text
314
-
315
- return revised_feedback
316
-
317
- agent_prompt = """
318
- 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.
319
-
320
- Here are step-by-step instructions:
321
- 1. Read the text of the review and the paper about which the review was written.
322
-
323
- 2. Evaluate every comment in the review:
324
- - Focus on comments made in the "weaknesses" or "questions" sections of the review. Ignore the "summary" and "strengths" sections.
325
- - For each comment, evaluate it against the following checklist. Follow the examples for how to respond.
326
-
327
- Checklist:
328
- 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.
329
- - Example 1:
330
- - **Reviewer Comment:** *..In Figure 4, the efficiency experiments have no results for Transformer models, which is a key limitation of the paper.*
331
- - **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>.
332
- - Example 2:
333
- - **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.*
334
- - 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.
335
-
336
- 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.
337
- - Example 1:
338
- - **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).*
339
- - **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.
340
- - Example 2:
341
- - **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.*
342
- - **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?
343
- - Example 3:
344
- - **Reviewer Comment:** *The data and model size are not large-scale, thus the paper will not be impactful.*
345
- - **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.
346
- 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.
347
- - Example 1:
348
- - **Reviewer Comment:** *.. The paper's novelty is limited considering the ICLR standards, as there are very close works [1,2,3]. *
349
- - **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.
350
- - Example 2:
351
- - **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)*
352
- - As the novelty claim is already well-justified and an actionable question is asked, we do not need to give feedback to this review.
353
- 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.
354
- - Example 1:
355
- - **Reviewer Comment:** *.. The authors clearly do not live in the real world and do not care about people or downstream effects of their research. *
356
- - **Feedback to the reviewer:** We kindly suggest you revise this comment, as it includes remarks about the personalities or intents of the authors.
357
-
358
- 3. Provide feedback:
359
- - For each comment that fails according to the checklist, write concise feedback in the following format:
360
- - Comment: {{the comment of interest}}
361
- - Feedback: {{your short feedback}}
362
- - If you do not identify any issues with a comment, do not include it in your feedback list.
363
- - If you find no issues in the review at all, respond with: "Thanks for your hard work!"
364
-
365
- Remember:
366
- - Be concise, limiting your feedback for each comment to 1-2 sentences.
367
- - Do not summarize your feedback at the end or include a preamble at the beginning.
368
- - Do not repeat anything the reviewer already included in their review.
369
- - Do not mention that you are using a checklist or guidelines.
370
- - Do not address the authors at all or provide suggestions to the authors. You are only giving feedback to the reviewer.
371
- """
372
-
373
- critic_prompt = f"""
374
- 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.
375
-
376
- Here are step-by-step instructions:
377
- 1. Read the text of the review, the feedback list provided for that review, and the paper about which the review was written.
378
-
379
- 2. Evaluate every piece of feedback in the feedback list:
380
- - 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.
381
- - For each feedback item, evaluate if it is clear. You should make sure it would not confuse or frustrate the reviewer who reads it.
382
- - Make sure every comment-feedback pair addresses an issue with the review, otherwise remove it.
383
-
384
- 3. Edit comments based on evaluations:
385
- - Do not add any new points unless the previous feedback obviously missed something important.
386
- - For each comment that needs editing, re-write the feedback concisely in the following format:
387
- - Comment: {{the comment of interest}}
388
- - Feedback: {{your short feedback}}
389
- - If you do not identify any issues with a comment-feedback pair, do not edit it.
390
-
391
- 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.
392
-
393
- Remember:
394
- - Be concise, limiting your feedback for each comment to 1-2 sentences.
395
- - Do not summarize your feedback at the end or include a preamble at the beginning.
396
- - Do not repeat anything the reviewer already included in their review.
397
- - Do not mention that you are using a checklist or guidelines.
398
- - Do not address the authors at all or provide suggestions to the authors. You are only giving feedback to the reviewer.
399
-
400
- Here are the guidelines that were followed to generate the feedback list originally; you should adhere to these guidelines: {agent_prompt}.
401
- """
402
-
403
- aggregator_prompt = f"""
404
- 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.
405
-
406
- Here are step-by-step instructions:
407
- 1. Read the text of the review, the multiple feedback lists provided for that review, and the paper about which the review was written.
408
-
409
- 2. For all feedback lists, aggregate them into one list with the best comment-feedback pairs from each list.
410
- - For each comment-feedback pair in the multiple lists that are similar, determine which provides the best feedback and keep only that pair.
411
- - 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.
412
- - You should end up with one feedback list that has no repeated comments from the review and that is high quality.
413
- - Return the feedback list in the format you received it in, where the pairs are formatted as:
414
- - Comment: {{the comment of interest}}
415
- - Feedback: {{your short feedback}}
416
-
417
- Here are the guidelines that were followed to generate the feedback lists originally: {agent_prompt}.
418
- """
419
-
420
- # Set page to wide mode
421
- st.set_page_config(layout="wide")
422
-
423
- # Sidebar for navigation
424
- st.sidebar.title('Input review and PDF or OpenReview ID')
425
-
426
- option = st.sidebar.radio(
427
- "Choose one input option:",
428
- ("Upload PDF with Review", "OpenReview paper ID"))
429
-
430
- # # Add a text input box to the sidebar for user input
431
- # user_input = st.sidebar.text_input("Enter OpenReview ID (e.g. xC8xh2RSs2)")
432
-
433
- user_input = False
434
-
435
- if option == "OpenReview paper ID":
436
- paper_id = st.text_input("Enter OpenReview ID (e.g. xC8xh2RSs2):")
437
- paper_id = paper_id.strip()
438
- reviewer_id = st.text_input("Enter reviewer ID (e.g. gNxe):")
439
- reviewer_id = reviewer_id.strip()
440
- model = st.text_input("Which model? ('gpt' or 'claude')")
441
- iterations = st.text_input("How many iterations to run agent for?")
442
- if paper_id and reviewer_id and model and iterations:
443
- upload_file = False
444
- user_input = True
445
- submissions = load_ICLR_submissions()
446
- review, pdf, pdf_text = parse_openreview_id(submissions, paper_id, reviewer_id)
447
- # st.write(f"Review text: {pdf_text}")
448
-
449
- elif option == "Upload PDF with Review":
450
- user_text = st.text_area("Enter review:")
451
- uploaded_file = st.file_uploader("Upload PDF", type="pdf")
452
- model = st.text_input("Which model? ('gpt' or 'claude')")
453
- iterations = st.text_input("How many iterations to run agent for?")
454
- if user_text and uploaded_file and model and iterations:
455
- upload_file = True
456
- user_input = True
457
- review, pdf = user_text, uploaded_file
458
- pdf_text = pdf_to_text(pdf)
459
-
460
- # st.write(f"Review text: {pdf_text}")
461
- # st.write(f"You entered review: {user_text}")
462
- # st.write(f"Uploaded file: {uploaded_file.name}")
463
-
464
- if user_input:
465
- annotations = load_annotations()
466
 
467
- feedback_list = []
468
- # Run your pipeline to generate the dataframe based on user input
469
- iterations = int(iterations)
470
- if iterations > 1:
471
- for _ in range(iterations):
472
- feedback = create_feedback(review, pdf_text, agent_prompt, model)
473
- feedback_list.append(feedback)
474
- best_feedback = aggregator(feedback_list, aggregator_prompt, agent_prompt, review, pdf_text, model)
475
- else:
476
- best_feedback = create_feedback(review, pdf_text, agent_prompt, model)
477
 
478
- revised_feedback = critic(review, best_feedback, pdf_text, critic_prompt, model)
479
 
480
- count, match_count = parse_quotes(revised_feedback, pdf_text)
481
 
482
- revised_feedback = revised_feedback.replace("<quote>", "'").replace("</quote>", "'")
483
 
484
- st.title(f'Review feedback')
485
 
486
- if not upload_file and annotations['submission_id'].str.contains(str(paper_id)).any():
487
- st.write(f'We have a human annotation for {paper_id}')
488
- # Create four columns
489
- col1, col2, col3, col4 = st.columns(4)
490
 
491
- # Column 1: Display review fields
492
- with col1:
493
- st.subheader("Review")
494
- st.write(json.dumps(review))
495
 
496
- if not upload_file:
497
- pdf_url = f"https://openreview.net/pdf?id={paper_id}"
498
- st.markdown(f"[Click here to view PDF]({pdf_url})")
499
 
500
- # Column 2: Display human annotations
501
- with col2:
502
- st.subheader('Human annotations')
503
- if annotations.loc[(annotations['submission_id'] == paper_id), 'annotation_label'].item() == 1:
504
- sentences = annotations.loc[(annotations['submission_id'] == paper_id), 'annotation_sentences'].item()
505
- sentences = ast.literal_eval(sentences)
506
- st.write(sentences)
507
- # for s in sentences:
508
- # st.write(f"- {s}")
509
- else:
510
- st.write("No human feedback on this review")
511
 
512
- # Column 3: Display feedback
513
- with col3:
514
- st.subheader('Best Feedback')
515
- st.write(best_feedback)
516
 
517
- # Column 4: Display revised feedback (from critic)
518
- with col4:
519
- st.subheader('Revised Feedback')
520
- if count > 0: st.write(f"Quotes found verbatim in pdf text: {match_count}/{count}")
521
- st.write(revised_feedback)
522
- else:
523
-
524
- # Create three columns
525
- col1, col2, col3 = st.columns(3)
526
 
527
- # Column 1: Display review fields
528
- with col1:
529
- st.subheader("Review")
530
- st.write(json.dumps(review))
531
 
532
- if not upload_file:
533
- pdf_url = f"https://openreview.net/pdf?id={paper_id}"
534
- st.markdown(f"[Click here to view PDF]({pdf_url})")
535
 
536
- # Column 2: Display feedback
537
- with col2:
538
- st.subheader('Best Feedback')
539
- st.write(best_feedback)
540
 
541
- # Column 3: Display revised feedback (from critic)
542
- with col3:
543
- st.subheader('Revised Feedback')
544
- if count > 0: st.write(f"Quotes found verbatim in pdf text: {match_count}/{count}")
545
- st.write(revised_feedback)
546
-
547
- else:
548
- st.title('Please enter OpenReview ID or upload PDF with review to generate feedback')
 
1
+ from reviewer_feedback_agent.apps import app
2
+ app()
3
+
4
+ # import streamlit as st
5
+ # import pandas as pd
6
+ # import ast
7
+ # import re
8
+ # import PyPDF2
9
+ # from PyPDF2 import PdfReader
10
+ # import openreview
11
+ # import json
12
+ # import urllib.request
13
+ # import requests
14
+ # import os
15
+ # import pickle
16
+ # import openai
17
+ # from openai import OpenAI
18
+ # import anthropic
19
+ # from anthropic import Anthropic
20
+
21
+ # openai_api_key = os.environ["OPENAI_API_KEY"]
22
+ # client_openai = OpenAI(api_key=openai_api_key)
23
+
24
+ # anthropic_api_key = os.environ["ANTHROPIC_API_KEY"]
25
+ # client_anthropic = Anthropic(api_key=anthropic_api_key)
26
+
27
+ # def parse_quotes(input_string, pdf_text):
28
+
29
+ # header_pattern = r'\d+Under review as a conference paper at ICLR 2024'
30
+ # #r'^\d+Under review as a conference paper at ICLR 2024\s*' # Pattern to match headers with variable page numbers
31
+ # # r'(?m)^Under review as a conference paper at ICLR 2024*$'
32
+
33
+ # pdf_text_wo_header = re.sub(header_pattern, '', pdf_text)
34
+ # # Remove new lines that are not followed by a period, exclamation mark, or question mark
35
+ # pdf_text_wo_header = re.sub(r'(?<!\.\s)(?<!\!\s)(?<!\?\s)\n+', ' ', pdf_text_wo_header)
36
+ # # Remove extra spaces that may have been introduced
37
+ # pdf_text_wo_header = re.sub(r'\s{2,}', ' ', pdf_text_wo_header).strip()
38
 
39
+ # # Find all matches of <quote>...</quote> and extract the content between the tags
40
+ # matches = re.findall(r'<quote>(.*?)</quote>', input_string)
41
 
42
+ # count = len(matches)
43
+ # extracted_texts = matches
44
+ # # with open('pdf_text.txt', 'w') as file:
45
+ # # file.write(pdf_text_wo_header)
46
+ # # print(extracted_texts)
47
+ # match_count = sum(1 for text in extracted_texts if text in pdf_text_wo_header)
48
 
49
+ # return count, match_count
50
 
51
+ # # load manual (human) annotations
52
+ # def load_annotations():
53
+ # path = './annotations_8_26.csv'
54
+ # annotations = pd.read_csv(path)
55
+ # annotations.columns = annotations.columns.str.replace(' ', '_').str.lower()
56
 
57
+ # # 36 0, 15 1
58
+ # annotations['annotation_label'] = annotations['annotation_label'].astype(int)
59
 
60
+ # return annotations
61
+
62
+ # # Check if the password matches the env variable
63
+ # def check_password():
64
+ # def password_entered():
65
+ # if st.session_state["password"] == os.environ["APP_PASSCODE"]:
66
+ # st.session_state["password_correct"] = True
67
+ # del st.session_state["password"] # Clear password from memory
68
+ # else:
69
+ # st.session_state["password_correct"] = False
70
+
71
+ # if "password_correct" not in st.session_state:
72
+ # st.text_input("Enter Password", type="password", on_change=password_entered, key="password")
73
+ # return False
74
+ # elif not st.session_state["password_correct"]:
75
+ # st.error("Password incorrect")
76
+ # return False
77
+ # else:
78
+ # return True
79
+
80
+ # # Ask for password at the beginning
81
+ # if not check_password():
82
+ # st.stop()
83
+
84
+ # # converts paper pdf into text
85
+ # def pdf_to_text(pdf):
86
+ # paper_text = ''
87
+
88
+ # reader = PdfReader(pdf)
89
+ # number_of_pages = len(reader.pages)
90
+ # for p in range(number_of_pages):
91
+ # page = reader.pages[p].get_object()
92
+ # text = page.extract_text()
93
+ # paper_text += text
94
+
95
+ # return paper_text
96
+
97
+ # # loads all 2024 ICLR submissions from OpenReview
98
+ # submissions_path = "./submissions_iclr2024.pkl"
99
+ # # API V2
100
+ # client = openreview.api.OpenReviewClient(
101
+ # baseurl='https://api2.openreview.net',
102
+ # )
103
+
104
+ # # Get ICLR venues
105
+ # venues = client.get_group(id='venues').members
106
+ # iclr_venues = [v for v in venues if "iclr.cc" in v.lower() and "conference" in v.lower()]
107
+
108
+ # @st.cache_data
109
+ # def load_ICLR_submissions():
110
+ # if os.path.exists(submissions_path):
111
+ # with open(submissions_path, "rb") as f:
112
+ # return pickle.load(f)
113
+ # else:
114
+ # # Select the second latest venue
115
+ # venue_id = iclr_venues[-2]
116
+ # venue_group = client.get_group(venue_id)
117
+ # submission_name = venue_group.content['submission_name']['value']
118
+ # submissions = client.get_all_notes(invitation=f'{venue_id}/-/{submission_name}', details='replies')
119
+ # with open(submissions_path, "wb") as f:
120
+ # pickle.dump(submissions, f)
121
+ # return submissions
122
+
123
+ # # returns review and pdf paper text given paper id and reviewer id
124
+ # def parse_openreview_id(submissions, paper_id, reviewer_id):
125
+ # paper_url = f"https://openreview.net/pdf?id={paper_id}"
126
+ # fields = ['summary', 'soundness', 'presentation', 'contribution', 'strengths', 'weaknesses', 'questions']
127
+
128
+ # ind = next((index for index, entry in enumerate(submissions) if entry.id == paper_id), None)
129
+ # curr_review = submissions[ind]
130
+ # bad_review = next((i for i, entry in enumerate(curr_review.details['replies'])
131
+ # if entry['signatures'][0].split('_')[-1] == reviewer_id), None)
132
+
133
+ # try:
134
+ # review_content = curr_review.details["replies"][bad_review]["content"]
135
+ # except:
136
+ # st.error("Paper ID or reviewer ID are incorrect")
137
+
138
+ # review_content = {key: review_content[key] if key in fields else None for key in review_content.keys() if key in fields}
139
+
140
+ # urllib.request.urlretrieve(paper_url, f"{paper_id}.pdf")
141
+ # pdf = f"{paper_id}.pdf"
142
+ # pdf_text = pdf_to_text(pdf)
143
+
144
+ # return review_content, pdf, pdf_text
145
+
146
+
147
+ # def create_feedback(review, pdf_text, agent_prompt, model):
148
+
149
+ # messages = [{
150
+ # "role": "user",
151
+ # "content": [
152
+ # {
153
+ # "type": "text",
154
+ # "text": agent_prompt
155
+ # },
156
+ # {
157
+ # "type": "text",
158
+ # "text": "Here is the ML conference review"
159
+ # },
160
+ # {
161
+ # "type": "text",
162
+ # "text": json.dumps(review) #json.dumps(review)
163
+ # },
164
+ # {
165
+ # "type": "text",
166
+ # "text": "Finally, read the paper this review was written about"
167
+ # },
168
+ # {
169
+ # "type": "text",
170
+ # "text": pdf_text
171
+ # }
172
+ # ]}]
173
+
174
+ # if model == 'gpt':
175
+ # headers = {
176
+ # "Content-Type": "application/json",
177
+ # "Authorization": f"Bearer {openai_api_key}"
178
+ # }
179
+ # payload = {
180
+ # "model": "gpt-4o",
181
+ # "messages": messages,
182
+ # "max_tokens": 1000,
183
+ # "temperature": 0.2
184
+ # }
185
+
186
+ # try:
187
+ # response = requests.post("https://api.openai.com/v1/chat/completions", headers=headers, json=payload)
188
+ # feedback = response.json()["choices"][0]["message"]["content"]
189
+ # except Exception as e:
190
+ # print(f"An unexpected error occurred: {e}")
191
+ # feedback = "an error occured"
192
+
193
+ # else:
194
+ # message = client_anthropic.messages.create(max_tokens=1024, messages=messages, model="claude-3-5-sonnet-20240620")
195
+ # feedback = message.content[0].text
196
+
197
+ # return feedback
198
+
199
+ # def aggregator(feedback_list, aggregator_prompt, agent_prompt, review, pdf_text, model):
200
+
201
+ # messages = [{
202
+ # "role": "user",
203
+ # "content": [
204
+ # {
205
+ # "type": "text",
206
+ # "text": aggregator_prompt
207
+ # },
208
+ # {
209
+ # "type": "text",
210
+ # "text": "Here is the ML conference review"
211
+ # },
212
+ # {
213
+ # "type": "text",
214
+ # "text": json.dumps(review) #json.dumps(review)
215
+ # },
216
+ # {
217
+ # "type": "text",
218
+ # "text": "Here is the list of feedback about the review, where each item is separated by the '^' character"
219
+ # },
220
+ # {
221
+ # "type": "text",
222
+ # "text": "^ ".join(feedback_list)
223
+ # },
224
+ # {
225
+ # "type": "text",
226
+ # "text": "Finally, read the paper this review was written about"
227
+ # },
228
+ # {
229
+ # "type": "text",
230
+ # "text": pdf_text
231
+ # }
232
+ # ]}]
233
+
234
+ # if model == 'gpt':
235
+ # headers = {
236
+ # "Content-Type": "application/json",
237
+ # "Authorization": f"Bearer {openai_api_key}"
238
+ # }
239
+ # payload = {
240
+ # "model": "gpt-4o-mini",
241
+ # "messages": messages,
242
+ # "max_tokens": 1000,
243
+ # "temperature": 0.2
244
+ # }
245
+
246
+ # try:
247
+ # response = requests.post("https://api.openai.com/v1/chat/completions", headers=headers, json=payload)
248
+ # best_feedback = response.json()["choices"][0]["message"]["content"]
249
+ # except Exception as e:
250
+ # print(f"An unexpected error occurred: {e}")
251
+ # best_feedback = "an error occured"
252
+
253
+ # else:
254
+ # message = client_anthropic.messages.create(max_tokens=1024, messages=messages, model="claude-3-5-sonnet-20240620")
255
+ # best_feedback = message.content[0].text
256
+
257
+ # return best_feedback
258
+
259
+
260
+ # def critic(review, feedback, pdf_text, critic_prompt, model):
261
 
262
+ # messages = [{
263
+ # "role": "user",
264
+ # "content": [
265
+ # {
266
+ # "type": "text",
267
+ # "text": critic_prompt
268
+ # },
269
+ # {
270
+ # "type": "text",
271
+ # "text": "Here is the ML conference review"
272
+ # },
273
+ # {
274
+ # "type": "text",
275
+ # "text": json.dumps(review) #json.dumps(review)
276
+ # },
277
+ # {
278
+ # "type": "text",
279
+ # "text": "Here is the feedback about the review"
280
+ # },
281
+ # {
282
+ # "type": "text",
283
+ # "text": feedback
284
+ # },
285
+ # {
286
+ # "type": "text",
287
+ # "text": "Finally, read the paper this review was written about"
288
+ # },
289
+ # {
290
+ # "type": "text",
291
+ # "text": pdf_text
292
+ # }
293
+ # ]}]
294
+
295
+ # if model == 'gpt':
296
+ # headers = {
297
+ # "Content-Type": "application/json",
298
+ # "Authorization": f"Bearer {openai_api_key}"
299
+ # }
300
+ # payload = {
301
+ # "model": "gpt-4o",
302
+ # "messages": messages,
303
+ # "max_tokens": 1000,
304
+ # "temperature": 0.2
305
+ # }
306
+
307
+ # try:
308
+ # response = requests.post("https://api.openai.com/v1/chat/completions", headers=headers, json=payload)
309
+ # revised_feedback = response.json()["choices"][0]["message"]["content"]
310
+ # except Exception as e:
311
+ # print(f"An unexpected error occurred: {e}")
312
+ # revised_feedback = "an error occured"
313
+
314
+ # else:
315
+ # message = client_anthropic.messages.create(max_tokens=1024, messages=messages, model="claude-3-5-sonnet-20240620")
316
+ # revised_feedback = message.content[0].text
317
+
318
+ # return revised_feedback
319
+
320
+ # agent_prompt = """
321
+ # 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.
322
+
323
+ # Here are step-by-step instructions:
324
+ # 1. Read the text of the review and the paper about which the review was written.
325
+
326
+ # 2. Evaluate every comment in the review:
327
+ # - Focus on comments made in the "weaknesses" or "questions" sections of the review. Ignore the "summary" and "strengths" sections.
328
+ # - For each comment, evaluate it against the following checklist. Follow the examples for how to respond.
329
+
330
+ # Checklist:
331
+ # 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.
332
+ # - Example 1:
333
+ # - **Reviewer Comment:** *..In Figure 4, the efficiency experiments have no results for Transformer models, which is a key limitation of the paper.*
334
+ # - **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>.
335
+ # - Example 2:
336
+ # - **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.*
337
+ # - 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.
338
+
339
+ # 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.
340
+ # - Example 1:
341
+ # - **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).*
342
+ # - **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.
343
+ # - Example 2:
344
+ # - **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.*
345
+ # - **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?
346
+ # - Example 3:
347
+ # - **Reviewer Comment:** *The data and model size are not large-scale, thus the paper will not be impactful.*
348
+ # - **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.
349
+ # 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.
350
+ # - Example 1:
351
+ # - **Reviewer Comment:** *.. The paper's novelty is limited considering the ICLR standards, as there are very close works [1,2,3]. *
352
+ # - **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.
353
+ # - Example 2:
354
+ # - **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)*
355
+ # - As the novelty claim is already well-justified and an actionable question is asked, we do not need to give feedback to this review.
356
+ # 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.
357
+ # - Example 1:
358
+ # - **Reviewer Comment:** *.. The authors clearly do not live in the real world and do not care about people or downstream effects of their research. *
359
+ # - **Feedback to the reviewer:** We kindly suggest you revise this comment, as it includes remarks about the personalities or intents of the authors.
360
+
361
+ # 3. Provide feedback:
362
+ # - For each comment that fails according to the checklist, write concise feedback in the following format:
363
+ # - Comment: {{the comment of interest}}
364
+ # - Feedback: {{your short feedback}}
365
+ # - If you do not identify any issues with a comment, do not include it in your feedback list.
366
+ # - If you find no issues in the review at all, respond with: "Thanks for your hard work!"
367
+
368
+ # Remember:
369
+ # - Be concise, limiting your feedback for each comment to 1-2 sentences.
370
+ # - Do not summarize your feedback at the end or include a preamble at the beginning.
371
+ # - Do not repeat anything the reviewer already included in their review.
372
+ # - Do not mention that you are using a checklist or guidelines.
373
+ # - Do not address the authors at all or provide suggestions to the authors. You are only giving feedback to the reviewer.
374
+ # """
375
+
376
+ # critic_prompt = f"""
377
+ # 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.
378
+
379
+ # Here are step-by-step instructions:
380
+ # 1. Read the text of the review, the feedback list provided for that review, and the paper about which the review was written.
381
+
382
+ # 2. Evaluate every piece of feedback in the feedback list:
383
+ # - 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.
384
+ # - For each feedback item, evaluate if it is clear. You should make sure it would not confuse or frustrate the reviewer who reads it.
385
+ # - Make sure every comment-feedback pair addresses an issue with the review, otherwise remove it.
386
+
387
+ # 3. Edit comments based on evaluations:
388
+ # - Do not add any new points unless the previous feedback obviously missed something important.
389
+ # - For each comment that needs editing, re-write the feedback concisely in the following format:
390
+ # - Comment: {{the comment of interest}}
391
+ # - Feedback: {{your short feedback}}
392
+ # - If you do not identify any issues with a comment-feedback pair, do not edit it.
393
+
394
+ # 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.
395
+
396
+ # Remember:
397
+ # - Be concise, limiting your feedback for each comment to 1-2 sentences.
398
+ # - Do not summarize your feedback at the end or include a preamble at the beginning.
399
+ # - Do not repeat anything the reviewer already included in their review.
400
+ # - Do not mention that you are using a checklist or guidelines.
401
+ # - Do not address the authors at all or provide suggestions to the authors. You are only giving feedback to the reviewer.
402
+
403
+ # Here are the guidelines that were followed to generate the feedback list originally; you should adhere to these guidelines: {agent_prompt}.
404
+ # """
405
+
406
+ # aggregator_prompt = f"""
407
+ # 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.
408
+
409
+ # Here are step-by-step instructions:
410
+ # 1. Read the text of the review, the multiple feedback lists provided for that review, and the paper about which the review was written.
411
+
412
+ # 2. For all feedback lists, aggregate them into one list with the best comment-feedback pairs from each list.
413
+ # - For each comment-feedback pair in the multiple lists that are similar, determine which provides the best feedback and keep only that pair.
414
+ # - 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.
415
+ # - You should end up with one feedback list that has no repeated comments from the review and that is high quality.
416
+ # - Return the feedback list in the format you received it in, where the pairs are formatted as:
417
+ # - Comment: {{the comment of interest}}
418
+ # - Feedback: {{your short feedback}}
419
+
420
+ # Here are the guidelines that were followed to generate the feedback lists originally: {agent_prompt}.
421
+ # """
422
+
423
+ # # Set page to wide mode
424
+ # st.set_page_config(layout="wide")
425
+
426
+ # # Sidebar for navigation
427
+ # st.sidebar.title('Input review and PDF or OpenReview ID')
428
+
429
+ # option = st.sidebar.radio(
430
+ # "Choose one input option:",
431
+ # ("Upload PDF with Review", "OpenReview paper ID"))
432
+
433
+ # # # Add a text input box to the sidebar for user input
434
+ # # user_input = st.sidebar.text_input("Enter OpenReview ID (e.g. xC8xh2RSs2)")
435
+
436
+ # user_input = False
437
+
438
+ # if option == "OpenReview paper ID":
439
+ # paper_id = st.text_input("Enter OpenReview ID (e.g. xC8xh2RSs2):")
440
+ # paper_id = paper_id.strip()
441
+ # reviewer_id = st.text_input("Enter reviewer ID (e.g. gNxe):")
442
+ # reviewer_id = reviewer_id.strip()
443
+ # model = st.text_input("Which model? ('gpt' or 'claude')")
444
+ # iterations = st.text_input("How many iterations to run agent for?")
445
+ # if paper_id and reviewer_id and model and iterations:
446
+ # upload_file = False
447
+ # user_input = True
448
+ # submissions = load_ICLR_submissions()
449
+ # review, pdf, pdf_text = parse_openreview_id(submissions, paper_id, reviewer_id)
450
+ # # st.write(f"Review text: {pdf_text}")
451
+
452
+ # elif option == "Upload PDF with Review":
453
+ # user_text = st.text_area("Enter review:")
454
+ # uploaded_file = st.file_uploader("Upload PDF", type="pdf")
455
+ # model = st.text_input("Which model? ('gpt' or 'claude')")
456
+ # iterations = st.text_input("How many iterations to run agent for?")
457
+ # if user_text and uploaded_file and model and iterations:
458
+ # upload_file = True
459
+ # user_input = True
460
+ # review, pdf = user_text, uploaded_file
461
+ # pdf_text = pdf_to_text(pdf)
462
+
463
+ # # st.write(f"Review text: {pdf_text}")
464
+ # # st.write(f"You entered review: {user_text}")
465
+ # # st.write(f"Uploaded file: {uploaded_file.name}")
466
+
467
+ # if user_input:
468
+ # annotations = load_annotations()
469
 
470
+ # feedback_list = []
471
+ # # Run your pipeline to generate the dataframe based on user input
472
+ # iterations = int(iterations)
473
+ # if iterations > 1:
474
+ # for _ in range(iterations):
475
+ # feedback = create_feedback(review, pdf_text, agent_prompt, model)
476
+ # feedback_list.append(feedback)
477
+ # best_feedback = aggregator(feedback_list, aggregator_prompt, agent_prompt, review, pdf_text, model)
478
+ # else:
479
+ # best_feedback = create_feedback(review, pdf_text, agent_prompt, model)
480
 
481
+ # revised_feedback = critic(review, best_feedback, pdf_text, critic_prompt, model)
482
 
483
+ # count, match_count = parse_quotes(revised_feedback, pdf_text)
484
 
485
+ # revised_feedback = revised_feedback.replace("<quote>", "'").replace("</quote>", "'")
486
 
487
+ # st.title(f'Review feedback')
488
 
489
+ # if not upload_file and annotations['submission_id'].str.contains(str(paper_id)).any():
490
+ # st.write(f'We have a human annotation for {paper_id}')
491
+ # # Create four columns
492
+ # col1, col2, col3, col4 = st.columns(4)
493
 
494
+ # # Column 1: Display review fields
495
+ # with col1:
496
+ # st.subheader("Review")
497
+ # st.write(json.dumps(review))
498
 
499
+ # if not upload_file:
500
+ # pdf_url = f"https://openreview.net/pdf?id={paper_id}"
501
+ # st.markdown(f"[Click here to view PDF]({pdf_url})")
502
 
503
+ # # Column 2: Display human annotations
504
+ # with col2:
505
+ # st.subheader('Human annotations')
506
+ # if annotations.loc[(annotations['submission_id'] == paper_id), 'annotation_label'].item() == 1:
507
+ # sentences = annotations.loc[(annotations['submission_id'] == paper_id), 'annotation_sentences'].item()
508
+ # sentences = ast.literal_eval(sentences)
509
+ # st.write(sentences)
510
+ # # for s in sentences:
511
+ # # st.write(f"- {s}")
512
+ # else:
513
+ # st.write("No human feedback on this review")
514
 
515
+ # # Column 3: Display feedback
516
+ # with col3:
517
+ # st.subheader('Best Feedback')
518
+ # st.write(best_feedback)
519
 
520
+ # # Column 4: Display revised feedback (from critic)
521
+ # with col4:
522
+ # st.subheader('Revised Feedback')
523
+ # if count > 0: st.write(f"Quotes found verbatim in pdf text: {match_count}/{count}")
524
+ # st.write(revised_feedback)
525
+ # else:
526
+
527
+ # # Create three columns
528
+ # col1, col2, col3 = st.columns(3)
529
 
530
+ # # Column 1: Display review fields
531
+ # with col1:
532
+ # st.subheader("Review")
533
+ # st.write(json.dumps(review))
534
 
535
+ # if not upload_file:
536
+ # pdf_url = f"https://openreview.net/pdf?id={paper_id}"
537
+ # st.markdown(f"[Click here to view PDF]({pdf_url})")
538
 
539
+ # # Column 2: Display feedback
540
+ # with col2:
541
+ # st.subheader('Best Feedback')
542
+ # st.write(best_feedback)
543
 
544
+ # # Column 3: Display revised feedback (from critic)
545
+ # with col3:
546
+ # st.subheader('Revised Feedback')
547
+ # if count > 0: st.write(f"Quotes found verbatim in pdf text: {match_count}/{count}")
548
+ # st.write(revised_feedback)
549
+
550
+ # else:
551
+ # st.title('Please enter OpenReview ID or upload PDF with review to generate feedback')