nityathakkar commited on
Commit
fc51ead
·
verified ·
1 Parent(s): 3baa766

Added critic

Browse files
Files changed (1) hide show
  1. app.py +82 -13
app.py CHANGED
@@ -128,6 +128,61 @@ def create_feedback(review, pdf_text, agent_prompt):
128
 
129
  return feedback
130
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131
  agent_prompt = """
132
  You are given a peer review of a machine learning paper submitted to a top-tier ML conference on OpenReview.
133
  First, you will read the text of the review and then the paper about which it was written.
@@ -220,6 +275,20 @@ and send a list of comments and feedbacks. If you do not identify issues for a c
220
  If you cannot identify any issues, respond with "Thanks for your hard work!"
221
  """
222
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
223
  # Set page to wide mode
224
  st.set_page_config(layout="wide")
225
 
@@ -262,31 +331,31 @@ if user_input:
262
  # Run your pipeline to generate the dataframe based on user input
263
  feedback = create_feedback(review, pdf_text, agent_prompt)
264
 
265
- st.title(f'Review feedback')
266
 
267
- if not upload_file:
268
- # Create three columns
269
- col1, col2, col3 = st.columns(3)
270
 
271
- with col3:
272
- st.subheader('PDF Link')
273
- pdf_url = f"https://openreview.net/pdf?id={paper_id}"
274
- st.markdown(f"[Click here to view PDF]({pdf_url})")
275
-
276
- else:
277
- # Create two columns
278
- col1, col2 = st.columns(2)
279
-
280
 
281
  # Column 1: Display review fields
282
  with col1:
283
  st.subheader("Review")
284
  st.write(json.dumps(review))
285
 
 
 
 
 
286
  # Column 2: Display feedback
287
  with col2:
288
  st.subheader('Feedback')
289
  st.write(feedback)
290
 
 
 
 
 
 
291
  else:
292
  st.title('Please enter OpenReview ID or upload PDF with review to generate feedback')
 
128
 
129
  return feedback
130
 
131
+
132
+ def critic(review, feedback, pdf_text, critic_prompt):
133
+
134
+ messages = [{
135
+ "role": "user",
136
+ "content": [
137
+ {
138
+ "type": "text",
139
+ "text": critic_prompt
140
+ },
141
+ {
142
+ "type": "text",
143
+ "text": "Here is the ML conference review"
144
+ },
145
+ {
146
+ "type": "text",
147
+ "text": json.dumps(review) #json.dumps(review)
148
+ },
149
+ {
150
+ "type": "text",
151
+ "text": "Here is the feedback about the review"
152
+ },
153
+ {
154
+ "type": "text",
155
+ "text": feedback
156
+ },
157
+ {
158
+ "type": "text",
159
+ "text": "Finally, read the paper this review was written about"
160
+ },
161
+ {
162
+ "type": "text",
163
+ "text": pdf_text
164
+ }
165
+ ]}]
166
+
167
+ headers = {
168
+ "Content-Type": "application/json",
169
+ "Authorization": f"Bearer {my_api_key}"
170
+ }
171
+ payload = {
172
+ "model": "gpt-4o",
173
+ "messages": messages,
174
+ "max_tokens": 1000
175
+ }
176
+
177
+ try:
178
+ response = requests.post("https://api.openai.com/v1/chat/completions", headers=headers, json=payload)
179
+ revised_feedback = response.json()["choices"][0]["message"]["content"]
180
+ except Exception as e:
181
+ print(f"An unexpected error occurred: {e}")
182
+ revised_feedback = "an error occured"
183
+
184
+ return revised_feedback
185
+
186
  agent_prompt = """
187
  You are given a peer review of a machine learning paper submitted to a top-tier ML conference on OpenReview.
188
  First, you will read the text of the review and then the paper about which it was written.
 
275
  If you cannot identify any issues, respond with "Thanks for your hard work!"
276
  """
277
 
278
+ critic_prompt = """
279
+ You are given 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 make the review high-quality.
280
+ First, you will read the original review, then you will read the feedback, and then you will read the paper the review was written about.
281
+ You need to edit the feedback for correctness, removing anything that is incorrect and revising anything that needs to be fixed.
282
+ You should also edit the feedback for clarity, removing anything that may frustrate or confuse a reviewer.
283
+
284
+ Your instructions: do not change the format of the feedback, only edit for content clarity and correctness.
285
+ Your feedback will be sent directly to reviewers. Follow the below format when sending your review:
286
+ - Comment: {{the comment of interest}}
287
+ - Feedback: {{write your short feedback}}
288
+ and send a list of comments and feedbacks. If you do not identify issues for a comment, do not add it to the list or send feedback. DO NOT mention that there is a checklist or guidelines, and do NOT mention that this is the edited feedback.
289
+ If you cannot identify any issues, respond with "Thanks for your hard work!"
290
+ """
291
+
292
  # Set page to wide mode
293
  st.set_page_config(layout="wide")
294
 
 
331
  # Run your pipeline to generate the dataframe based on user input
332
  feedback = create_feedback(review, pdf_text, agent_prompt)
333
 
334
+ revised_feedback = critic(review, feedback, pdf_text, critic_prompt)
335
 
336
+ st.title(f'Review feedback')
 
 
337
 
338
+ # Create three columns
339
+ col1, col2, col3 = st.columns(3)
 
 
 
 
 
 
 
340
 
341
  # Column 1: Display review fields
342
  with col1:
343
  st.subheader("Review")
344
  st.write(json.dumps(review))
345
 
346
+ if not upload_file:
347
+ pdf_url = f"https://openreview.net/pdf?id={paper_id}"
348
+ st.markdown(f"[Click here to view PDF]({pdf_url})")
349
+
350
  # Column 2: Display feedback
351
  with col2:
352
  st.subheader('Feedback')
353
  st.write(feedback)
354
 
355
+ # Column 3: Display revised feedback (from critic)
356
+ with col3:
357
+ st.subheader('Revised Feedback')
358
+ st.write(revised_feedback)
359
+
360
  else:
361
  st.title('Please enter OpenReview ID or upload PDF with review to generate feedback')