versae commited on
Commit
c968df1
·
verified ·
1 Parent(s): 1187d60

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -122
app.py CHANGED
@@ -106,9 +106,9 @@ def save_choice(text_id, original_text, summary_a, summary_b, choice, notes=""):
106
  success, message = push_to_hf_dataset(new_row)
107
 
108
  if success:
109
- return f"Selected {chosen_summary} for text {text_id}. Pushed to HuggingFace."
110
  else:
111
- return f"Selected {chosen_summary} for text {text_id}. Local save only: {message}"
112
 
113
  class SummaryChooser:
114
  def __init__(self):
@@ -159,119 +159,38 @@ class SummaryChooser:
159
  def get_hf_status(self):
160
  """Get the status of HuggingFace integration"""
161
  success, message = self.hf_status
162
- return f"HF: {'' if success else ''} {message.split(':')[-1].strip()}"
163
-
164
- def select_summary_a(self):
165
- """Helper function to select Summary A"""
166
- return "Summary A"
167
-
168
- def select_summary_b(self):
169
- """Helper function to select Summary B"""
170
- return "Summary B"
171
 
172
  # Create the application
173
  app = SummaryChooser()
174
 
175
- # Custom CSS for clickable summaries
176
- css = """
177
- .clickable-summary {
178
- border: 1px solid #ddd;
179
- border-radius: 8px;
180
- padding: 16px;
181
- cursor: pointer;
182
- transition: all 0.3s;
183
- height: 100%;
184
- }
185
- .clickable-summary:hover {
186
- border-color: #2196F3;
187
- box-shadow: 0 0 10px rgba(33, 150, 243, 0.3);
188
- }
189
- .clickable-summary.selected {
190
- border-color: #2196F3;
191
- background-color: rgba(33, 150, 243, 0.1);
192
- box-shadow: 0 0 10px rgba(33, 150, 243, 0.5);
193
- }
194
- .info-box {
195
- padding: 8px 12px;
196
- border-radius: 4px;
197
- background-color: #f5f5f5;
198
- border: 1px solid #ddd;
199
- font-size: 14px;
200
- flex: 1;
201
- margin: 0 4px;
202
- }
203
- .status-container {
204
- display: flex;
205
- justify-content: space-between;
206
- align-items: center;
207
- margin-bottom: 12px;
208
- }
209
- """
210
-
211
  # Define the Gradio interface
212
- with gr.Blocks(title="Summary Chooser", css=css) as interface:
213
  gr.Markdown("# Summary Comparison Tool")
214
- gr.Markdown("Choose the better summary for each text by clicking on it")
215
-
216
- # Hidden variable to track the selection
217
- selected_summary = gr.Radio(
218
- choices=["Summary A", "Summary B"],
219
- label="Selected Summary",
220
- visible=False
221
- )
222
 
223
- # Status row with equal-sized elements
224
- with gr.Row(equal_height=True):
225
- with gr.Column(scale=1):
226
- text_id_box = gr.Textbox(label="Text ID", interactive=False, elem_classes=["info-box"])
227
- with gr.Column(scale=1):
228
- progress_label = gr.Textbox(label="Progress", interactive=False, elem_classes=["info-box"])
229
- with gr.Column(scale=1):
230
- hf_status = gr.Textbox(label="Status", value=app.get_hf_status(), interactive=False, elem_classes=["info-box"])
231
 
232
  with gr.Row():
233
  text_box = gr.TextArea(label="Original Text", lines=8)
234
 
235
- # Clickable summary boxes
236
- with gr.Row(equal_height=True):
237
  with gr.Column():
238
- with gr.Group(elem_classes=["clickable-summary"]) as summary_a_box:
239
- summary_a_title = gr.Markdown("### Summary A")
240
- summary_a = gr.TextArea(label="", lines=5, interactive=False)
241
-
242
  with gr.Column():
243
- with gr.Group(elem_classes=["clickable-summary"]) as summary_b_box:
244
- summary_b_title = gr.Markdown("### Summary B")
245
- summary_b = gr.TextArea(label="", lines=5, interactive=False)
246
-
247
- # Client-side JavaScript for clickable behavior
248
- summary_a_box.click(
249
- fn=app.select_summary_a,
250
- inputs=[],
251
- outputs=[selected_summary],
252
- _js="""
253
- () => {
254
- // Add selected class to summary A and remove from summary B
255
- document.querySelectorAll('.clickable-summary')[0].classList.add('selected');
256
- document.querySelectorAll('.clickable-summary')[1].classList.remove('selected');
257
- return "Summary A";
258
- }
259
- """
260
- )
261
 
262
- summary_b_box.click(
263
- fn=app.select_summary_b,
264
- inputs=[],
265
- outputs=[selected_summary],
266
- _js="""
267
- () => {
268
- // Add selected class to summary B and remove from summary A
269
- document.querySelectorAll('.clickable-summary')[1].classList.add('selected');
270
- document.querySelectorAll('.clickable-summary')[0].classList.remove('selected');
271
- return "Summary B";
272
- }
273
- """
274
- )
275
 
276
  with gr.Row():
277
  notes_box = gr.TextArea(label="Notes (optional)", lines=2)
@@ -294,32 +213,14 @@ with gr.Blocks(title="Summary Chooser", css=css) as interface:
294
  # Set up event handlers
295
  submit_button.click(
296
  fn=app.next_item,
297
- inputs=[selected_summary, notes_box],
298
- outputs=[text_id_box, text_box, summary_a, summary_b, progress_label, result_box],
299
- _js="""
300
- function(choice, notes) {
301
- // Reset selection highlight
302
- document.querySelectorAll('.clickable-summary').forEach(el => {
303
- el.classList.remove('selected');
304
- });
305
- return [choice, notes];
306
- }
307
- """
308
  )
309
 
310
  prev_button.click(
311
  fn=app.prev_item,
312
  inputs=[],
313
- outputs=[text_id_box, text_box, summary_a, summary_b, progress_label, result_box],
314
- _js="""
315
- function() {
316
- // Reset selection highlight
317
- document.querySelectorAll('.clickable-summary').forEach(el => {
318
- el.classList.remove('selected');
319
- });
320
- return [];
321
- }
322
- """
323
  )
324
 
325
  # Launch the application
 
106
  success, message = push_to_hf_dataset(new_row)
107
 
108
  if success:
109
+ return f"Selection saved for text ID: {text_id}! You chose {'Summary A' if choice == 'Summary A' else 'Summary B'}. Pushed to HuggingFace."
110
  else:
111
+ return f"Selection saved locally for text ID: {text_id}. HuggingFace push failed: {message}"
112
 
113
  class SummaryChooser:
114
  def __init__(self):
 
159
  def get_hf_status(self):
160
  """Get the status of HuggingFace integration"""
161
  success, message = self.hf_status
162
+ return f"HuggingFace Status: {'Connected' if success else 'Not Connected'} - {message}"
 
 
 
 
 
 
 
 
163
 
164
  # Create the application
165
  app = SummaryChooser()
166
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
167
  # Define the Gradio interface
168
+ with gr.Blocks(title="Summary Chooser") as interface:
169
  gr.Markdown("# Summary Comparison Tool")
170
+ gr.Markdown("Choose the better summary for each text")
 
 
 
 
 
 
 
171
 
172
+ with gr.Row():
173
+ with gr.Column():
174
+ progress_label = gr.Label(label="Progress")
175
+ with gr.Column():
176
+ hf_status = gr.Label(label="HuggingFace Status", value=app.get_hf_status())
177
+ with gr.Column():
178
+ text_id_box = gr.Textbox(label="Text ID", interactive=False)
 
179
 
180
  with gr.Row():
181
  text_box = gr.TextArea(label="Original Text", lines=8)
182
 
183
+ with gr.Row():
 
184
  with gr.Column():
185
+ summary_a = gr.TextArea(label="Summary A", lines=5)
 
 
 
186
  with gr.Column():
187
+ summary_b = gr.TextArea(label="Summary B", lines=5)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
188
 
189
+ with gr.Row():
190
+ choice_radio = gr.Radio(
191
+ choices=["Summary A", "Summary B"],
192
+ label="Select the better summary"
193
+ )
 
 
 
 
 
 
 
 
194
 
195
  with gr.Row():
196
  notes_box = gr.TextArea(label="Notes (optional)", lines=2)
 
213
  # Set up event handlers
214
  submit_button.click(
215
  fn=app.next_item,
216
+ inputs=[choice_radio, notes_box],
217
+ outputs=[text_id_box, text_box, summary_a, summary_b, progress_label, result_box]
 
 
 
 
 
 
 
 
 
218
  )
219
 
220
  prev_button.click(
221
  fn=app.prev_item,
222
  inputs=[],
223
+ outputs=[text_id_box, text_box, summary_a, summary_b, progress_label, result_box]
 
 
 
 
 
 
 
 
 
224
  )
225
 
226
  # Launch the application