jedick commited on
Commit
ba11bb4
Β·
1 Parent(s): 956820f

Remove judge mode dropdown and update layout

Browse files
Files changed (3) hide show
  1. app.py +70 -63
  2. app_functions.py +1 -7
  3. feedback.py +1 -2
app.py CHANGED
@@ -67,7 +67,6 @@ def run_judge(
67
  fewshot_noteworthy: bool,
68
  heuristic_rationale: str,
69
  fewshot_rationale: str,
70
- judge_mode: str,
71
  context=None,
72
  ):
73
  with logfire.attach_context(context) if context else nullcontext():
@@ -78,7 +77,6 @@ def run_judge(
78
  heuristic_noteworthy,
79
  heuristic_rationale,
80
  fewshot_rationale,
81
- judge_mode,
82
  )
83
 
84
 
@@ -113,6 +111,26 @@ with gr.Blocks(title="Noteworthy Differences") as demo:
113
  )
114
 
115
  with gr.Row():
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
  title_input = gr.Textbox(
117
  label="Wikipedia Page Title", placeholder="e.g., Albert Einstein", value=""
118
  )
@@ -120,75 +138,64 @@ with gr.Blocks(title="Noteworthy Differences") as demo:
120
  units_dropdown = gr.Dropdown(
121
  choices=["revisions", "days"], value="revisions", label="Units"
122
  )
123
- judge_mode = gr.Dropdown(
124
- choices=["unaligned", "aligned-fewshot", "aligned-heuristic"],
125
- value="aligned-heuristic",
126
- label="Judge Mode",
127
- )
128
  with gr.Column():
129
- random_btn = gr.Button("Get Random Page Title")
130
- submit_btn = gr.Button("Fetch Revisions and Run Model", variant="primary")
 
 
131
 
132
  with gr.Row():
133
- with gr.Column():
134
  gr.Markdown("### Old Revision")
135
  old_timestamp = gr.Markdown("")
136
  old_revision = gr.Textbox(label="", lines=15, max_lines=30, container=False)
137
- gr.Markdown(
138
- """#### Query Instructions
139
- - Page title is case sensitive; use underscores or spaces
140
- - Specify any number of days or up to 499 revisions behind
141
- - The closest available revision is retrieved
142
- - Only article introductions are downloaded
143
- """
144
- )
145
 
146
- with gr.Column():
147
  gr.Markdown("### Current Revision")
148
  new_timestamp = gr.Markdown("")
149
  new_revision = gr.Textbox(label="", lines=15, max_lines=30, container=False)
150
- gr.Markdown(
151
- """#### Confidence Key
152
- - **High:** heuristic = few-shot, judge agrees
153
- - **Moderate:** heuristic β‰  few-shot, judge decides
154
- - **Questionable:** heuristic = few-shot, judge vetoes
155
- """
156
- )
157
 
158
- with gr.Column():
159
  gr.Markdown("### Model Output")
160
- heuristic_rationale = gr.Textbox(
161
- label="β—‡ Heuristic Model's Rationale",
162
- lines=2,
163
- max_lines=7,
164
- )
165
- fewshot_rationale = gr.Textbox(
166
- label="∴ Few-shot Model's Rationale",
167
- lines=2,
168
- max_lines=7,
169
- )
170
- judge_reasoning = gr.Textbox(
171
- label="βš– Judge's Reasoning",
172
- lines=2,
173
- max_lines=7,
174
- )
175
- with gr.Row(variant="default"):
176
- noteworthy_text = gr.Textbox(
177
- label="Noteworthy Differences",
178
- lines=1,
179
- interactive=False,
180
- )
181
- confidence = gr.Textbox(
182
- label="Confidence",
183
- lines=1,
184
- interactive=False,
185
- )
186
- rerun_btn = gr.Button("Rerun Model")
187
-
188
- gr.Markdown("### πŸ‘₯ Your feedback")
189
  with gr.Row():
190
- thumbs_up_btn = gr.Button("πŸ‘ Agree", variant="primary")
191
- thumbs_down_btn = gr.Button("πŸ‘Ž Disagree", variant="primary")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
192
 
193
  # States to store boolean values
194
  heuristic_noteworthy = gr.State()
@@ -246,7 +253,6 @@ with gr.Blocks(title="Noteworthy Differences") as demo:
246
  fewshot_noteworthy,
247
  heuristic_rationale,
248
  fewshot_rationale,
249
- judge_mode,
250
  context,
251
  ],
252
  outputs=[judge_noteworthy, noteworthy_text, judge_reasoning, confidence],
@@ -274,7 +280,6 @@ with gr.Blocks(title="Noteworthy Differences") as demo:
274
  fewshot_noteworthy,
275
  heuristic_rationale,
276
  fewshot_rationale,
277
- judge_mode,
278
  context,
279
  ],
280
  outputs=[judge_noteworthy, noteworthy_text, judge_reasoning, confidence],
@@ -288,7 +293,6 @@ with gr.Blocks(title="Noteworthy Differences") as demo:
288
  title_input,
289
  number_input,
290
  units_dropdown,
291
- judge_mode,
292
  old_revision,
293
  new_revision,
294
  old_timestamp,
@@ -311,7 +315,6 @@ with gr.Blocks(title="Noteworthy Differences") as demo:
311
  title_input,
312
  number_input,
313
  units_dropdown,
314
- judge_mode,
315
  old_revision,
316
  new_revision,
317
  old_timestamp,
@@ -337,11 +340,15 @@ if __name__ == "__main__":
337
  head = '<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" rel="stylesheet">'
338
  # Use CSS to style table
339
  css = """
340
- #intro_table {background-color: #ecfdf5}
341
  table, tr, td {
342
  border: none; /* Removes all borders */
343
  border-collapse: collapse; /* Ensures no gaps between cells */
344
  }
 
 
 
 
345
  """
346
 
347
  demo.launch(theme=theme, head=head, css=css)
 
67
  fewshot_noteworthy: bool,
68
  heuristic_rationale: str,
69
  fewshot_rationale: str,
 
70
  context=None,
71
  ):
72
  with logfire.attach_context(context) if context else nullcontext():
 
77
  heuristic_noteworthy,
78
  heuristic_rationale,
79
  fewshot_rationale,
 
80
  )
81
 
82
 
 
111
  )
112
 
113
  with gr.Row():
114
+ with gr.Column():
115
+ with gr.Accordion("More Info", open=False) as accordion:
116
+ gr.Markdown(
117
+ """#### Query Instructions
118
+ - Page title is case sensitive; use underscores or spaces
119
+ - Specify any number of days or up to 499 revisions behind
120
+ - The closest available revision is retrieved
121
+ - Only article introductions are downloaded
122
+ """
123
+ )
124
+ gr.Markdown(
125
+ """#### Confidence Key
126
+ - **High:** heuristic = few-shot, judge agrees
127
+ - **Moderate:** heuristic β‰  few-shot, judge decides
128
+ - **Questionable:** heuristic = few-shot, judge vetoes
129
+ """
130
+ )
131
+ random_btn = gr.Button(
132
+ "Get Random Page Title", size="md", elem_id="random-button"
133
+ )
134
  title_input = gr.Textbox(
135
  label="Wikipedia Page Title", placeholder="e.g., Albert Einstein", value=""
136
  )
 
138
  units_dropdown = gr.Dropdown(
139
  choices=["revisions", "days"], value="revisions", label="Units"
140
  )
 
 
 
 
 
141
  with gr.Column():
142
+ submit_btn = gr.Button(
143
+ "Fetch Revisions and Run Model", size="md", variant="primary"
144
+ )
145
+ rerun_btn = gr.Button("Rerun Model", size="md")
146
 
147
  with gr.Row():
148
+ with gr.Column(scale=1):
149
  gr.Markdown("### Old Revision")
150
  old_timestamp = gr.Markdown("")
151
  old_revision = gr.Textbox(label="", lines=15, max_lines=30, container=False)
 
 
 
 
 
 
 
 
152
 
153
+ with gr.Column(scale=1):
154
  gr.Markdown("### Current Revision")
155
  new_timestamp = gr.Markdown("")
156
  new_revision = gr.Textbox(label="", lines=15, max_lines=30, container=False)
 
 
 
 
 
 
 
157
 
158
+ with gr.Column(scale=2):
159
  gr.Markdown("### Model Output")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
  with gr.Row():
161
+ with gr.Column():
162
+ heuristic_rationale = gr.Textbox(
163
+ label="β—‡ Heuristic Model's Rationale",
164
+ lines=2,
165
+ max_lines=7,
166
+ )
167
+ fewshot_rationale = gr.Textbox(
168
+ label="∴ Few-shot Model's Rationale",
169
+ lines=2,
170
+ max_lines=7,
171
+ )
172
+ judge_reasoning = gr.Textbox(
173
+ label="βš– Judge's Reasoning",
174
+ lines=2,
175
+ max_lines=7,
176
+ )
177
+
178
+ with gr.Column():
179
+ with gr.Row(variant="default"):
180
+ noteworthy_text = gr.Textbox(
181
+ label="Noteworthy Differences",
182
+ lines=1,
183
+ interactive=False,
184
+ )
185
+ confidence = gr.Textbox(
186
+ label="Confidence",
187
+ lines=1,
188
+ interactive=False,
189
+ )
190
+
191
+ gr.Markdown("### πŸ‘₯ Your feedback")
192
+ with gr.Row():
193
+ thumbs_up_btn = gr.Button(
194
+ "πŸ‘ Agree", size="md", variant="primary"
195
+ )
196
+ thumbs_down_btn = gr.Button(
197
+ "πŸ‘Ž Disagree", size="md", variant="primary"
198
+ )
199
 
200
  # States to store boolean values
201
  heuristic_noteworthy = gr.State()
 
253
  fewshot_noteworthy,
254
  heuristic_rationale,
255
  fewshot_rationale,
 
256
  context,
257
  ],
258
  outputs=[judge_noteworthy, noteworthy_text, judge_reasoning, confidence],
 
280
  fewshot_noteworthy,
281
  heuristic_rationale,
282
  fewshot_rationale,
 
283
  context,
284
  ],
285
  outputs=[judge_noteworthy, noteworthy_text, judge_reasoning, confidence],
 
293
  title_input,
294
  number_input,
295
  units_dropdown,
 
296
  old_revision,
297
  new_revision,
298
  old_timestamp,
 
315
  title_input,
316
  number_input,
317
  units_dropdown,
 
318
  old_revision,
319
  new_revision,
320
  old_timestamp,
 
340
  head = '<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" rel="stylesheet">'
341
  # Use CSS to style table
342
  css = """
343
+ #intro_table {background-color: #eff6ff}
344
  table, tr, td {
345
  border: none; /* Removes all borders */
346
  border-collapse: collapse; /* Ensures no gaps between cells */
347
  }
348
+
349
+ #random-button {
350
+ margin-top: auto; /* Pushes the button to the bottom */
351
+ }
352
  """
353
 
354
  demo.launch(theme=theme, head=head, css=css)
app_functions.py CHANGED
@@ -201,7 +201,6 @@ def _run_judge(
201
  fewshot_noteworthy: bool,
202
  heuristic_rationale: str,
203
  fewshot_rationale: str,
204
- judge_mode: str,
205
  ):
206
  """
207
  Run judge on the revisions and classifiers' rationales.
@@ -213,16 +212,11 @@ def _run_judge(
213
  fewshot_noteworthy: Few-shot model's noteworthiness prediction
214
  heuristic_rationale: Heuristic model's rationale
215
  fewshot_rationale: Few-shot model's rationale
216
- judge_mode: Mode for judge function ("unaligned", "aligned-fewshot", "aligned-heuristic")
217
 
218
  Returns:
219
  Tuple of (noteworthy, noteworthy_text, reasoning, confidence) (bool, str, str, str)
220
  """
221
 
222
- print(f"old_revision: {old_revision}")
223
- print(f"new_revision: {new_revision}")
224
- print(f"judge_mode: {judge_mode}")
225
-
226
  # Values to return if there is an error
227
  noteworthy, noteworthy_text, reasoning, confidence = None, None, None, None
228
  if (
@@ -240,7 +234,7 @@ def _run_judge(
240
  new_revision,
241
  heuristic_rationale,
242
  fewshot_rationale,
243
- mode=judge_mode,
244
  )
245
  if result:
246
  noteworthy = result.get("noteworthy", "")
 
201
  fewshot_noteworthy: bool,
202
  heuristic_rationale: str,
203
  fewshot_rationale: str,
 
204
  ):
205
  """
206
  Run judge on the revisions and classifiers' rationales.
 
212
  fewshot_noteworthy: Few-shot model's noteworthiness prediction
213
  heuristic_rationale: Heuristic model's rationale
214
  fewshot_rationale: Few-shot model's rationale
 
215
 
216
  Returns:
217
  Tuple of (noteworthy, noteworthy_text, reasoning, confidence) (bool, str, str, str)
218
  """
219
 
 
 
 
 
220
  # Values to return if there is an error
221
  noteworthy, noteworthy_text, reasoning, confidence = None, None, None, None
222
  if (
 
234
  new_revision,
235
  heuristic_rationale,
236
  fewshot_rationale,
237
+ mode="aligned-heuristic",
238
  )
239
  if result:
240
  noteworthy = result.get("noteworthy", "")
feedback.py CHANGED
@@ -45,7 +45,6 @@ def save_feedback(*args, feedback_value: str) -> None:
45
  "title_input",
46
  "number_input",
47
  "units_dropdown",
48
- "judge_mode_dropdown",
49
  "old_revision",
50
  "new_revision",
51
  "old_timestamp",
@@ -68,7 +67,7 @@ def save_feedback(*args, feedback_value: str) -> None:
68
  with feedback_path.open("a") as f:
69
  f.write(json.dumps(feedback_dict))
70
  f.write("\n")
71
- gr.Success(f"Saved feedback: <strong>{feedback_value}</strong>")
72
 
73
 
74
  @logfire.instrument("Save feedback: agree")
 
45
  "title_input",
46
  "number_input",
47
  "units_dropdown",
 
48
  "old_revision",
49
  "new_revision",
50
  "old_timestamp",
 
67
  with feedback_path.open("a") as f:
68
  f.write(json.dumps(feedback_dict))
69
  f.write("\n")
70
+ gr.Success(f"Saved feedback: <strong>{feedback_value}</strong>", duration=5)
71
 
72
 
73
  @logfire.instrument("Save feedback: agree")