shreyansjain commited on
Commit
af33aa5
·
1 Parent(s): ae41f1f

Add application file

Browse files
Files changed (1) hide show
  1. app.py +27 -40
app.py CHANGED
@@ -86,11 +86,11 @@ def load_file(file_name):
86
  return show_entry()
87
 
88
 
89
- def save_annotation(p_hash, *scores_and_comments):
90
  """Save annotations to persistent storage as JSONL (with file name)"""
91
  ann = {
92
  "file_name": current_file,
93
- "hash_id": p_hash,
94
  "annotations": {}
95
  }
96
 
@@ -106,7 +106,7 @@ def save_annotation(p_hash, *scores_and_comments):
106
  with open(ANNOTATION_FILE, "a", encoding="utf-8") as f:
107
  f.write(json.dumps(ann, ensure_ascii=False) + "\n")
108
 
109
- return f"✅ Saved annotation for {p_hash} (from {current_file}) → {ANNOTATION_FILE}"
110
 
111
  def export_annotations():
112
  """Return path to annotations file for download"""
@@ -259,7 +259,7 @@ def show_entry(step=None):
259
  """Navigate entries and show persona entry"""
260
  global index, data
261
  if not data:
262
- return "", ""
263
 
264
  if step == "Next":
265
  index = (index + 1) % len(data)
@@ -269,15 +269,15 @@ def show_entry(step=None):
269
  index = random.randint(0, len(data) - 1) % len(data)
270
 
271
  entry = data[index]
272
- p_hash = entry.get("uuid", f"persona_{index}")
273
 
274
  if not entry:
275
  empty = "_No data_"
276
  # diagram HTML, then the sections
277
  return ["", empty, empty, empty, empty, empty, empty, empty, empty, empty]
278
 
279
- return [
280
- p_hash,
281
  md_header(entry),
282
  md_categories(entry),
283
  md_presenting(entry),
@@ -289,6 +289,10 @@ def show_entry(step=None):
289
  md_metadata(entry),
290
  md_other_fields(entry),
291
  ]
 
 
 
 
292
 
293
  # persona_str = entry.get("persona_string", "").replace("\n", "<br>")
294
  # archetype = entry.get("archetype", "N/A")
@@ -324,6 +328,8 @@ with gr.Blocks() as demo:
324
  md_context_out = gr.Markdown()
325
  md_meta_out = gr.Markdown()
326
  md_other_out = gr.Markdown()
 
 
327
 
328
  gr.Markdown("### Evaluation Rubric (0 = Worst, 5 = Best)")
329
 
@@ -343,39 +349,25 @@ with gr.Blocks() as demo:
343
 
344
  save_btn = gr.Button("Save Annotation")
345
  save_status = gr.Textbox(label="Status", interactive=False)
 
 
 
 
 
 
 
 
 
346
 
347
  with gr.Row():
348
  export_btn = gr.Button("Download All Annotations")
349
  export_file = gr.File(label="Exported Annotations", type="filepath")
350
 
351
  # Wiring
352
- file_dropdown.change(
353
- load_file,
354
- inputs=file_dropdown,
355
- outputs=[phash_out, md_header_out, md_cats_out, md_present_out, md_clinical_out,
356
- md_history_out, md_function_out, md_summary_out, md_context_out, md_meta_out, md_other_out]
357
- )
358
-
359
- prev_btn.click(
360
- show_entry,
361
- inputs=gr.State("Previous"),
362
- outputs=[phash_out, md_header_out, md_cats_out, md_present_out, md_clinical_out,
363
- md_history_out, md_function_out, md_summary_out, md_context_out, md_meta_out, md_other_out]
364
- )
365
-
366
- next_btn.click(
367
- show_entry,
368
- inputs=gr.State("Next"),
369
- outputs=[phash_out, md_header_out, md_cats_out, md_present_out, md_clinical_out,
370
- md_history_out, md_function_out, md_summary_out, md_context_out, md_meta_out, md_other_out]
371
- )
372
-
373
- shuffle_btn.click(
374
- show_entry,
375
- inputs=gr.State("Random Shuffle"),
376
- outputs=[phash_out, md_header_out, md_cats_out, md_present_out, md_clinical_out,
377
- md_history_out, md_function_out, md_summary_out, md_context_out, md_meta_out, md_other_out]
378
- )
379
 
380
  save_btn.click(
381
  save_annotation,
@@ -387,11 +379,6 @@ with gr.Blocks() as demo:
387
 
388
  export_btn.click(export_annotations, inputs=None, outputs=export_file)
389
 
390
- demo.load(
391
- load_file,
392
- inputs=gr.State(available_files[0]),
393
- outputs=[phash_out, md_header_out, md_cats_out, md_present_out, md_clinical_out,
394
- md_history_out, md_function_out, md_summary_out, md_context_out, md_meta_out, md_other_out]
395
- )
396
 
397
  demo.launch()
 
86
  return show_entry()
87
 
88
 
89
+ def save_annotation(p_uuid, *scores_and_comments):
90
  """Save annotations to persistent storage as JSONL (with file name)"""
91
  ann = {
92
  "file_name": current_file,
93
+ "persona_uuid": p_uuid,
94
  "annotations": {}
95
  }
96
 
 
106
  with open(ANNOTATION_FILE, "a", encoding="utf-8") as f:
107
  f.write(json.dumps(ann, ensure_ascii=False) + "\n")
108
 
109
+ return f"✅ Saved annotation for {p_uuid} (from {current_file}) → {ANNOTATION_FILE}"
110
 
111
  def export_annotations():
112
  """Return path to annotations file for download"""
 
259
  """Navigate entries and show persona entry"""
260
  global index, data
261
  if not data:
262
+ return [""] * (11 + 11)
263
 
264
  if step == "Next":
265
  index = (index + 1) % len(data)
 
269
  index = random.randint(0, len(data) - 1) % len(data)
270
 
271
  entry = data[index]
272
+ p_uuid = entry.get("uuid", f"persona_{index}")
273
 
274
  if not entry:
275
  empty = "_No data_"
276
  # diagram HTML, then the sections
277
  return ["", empty, empty, empty, empty, empty, empty, empty, empty, empty]
278
 
279
+ persona_out = [
280
+ p_uuid,
281
  md_header(entry),
282
  md_categories(entry),
283
  md_presenting(entry),
 
289
  md_metadata(entry),
290
  md_other_fields(entry),
291
  ]
292
+
293
+ # Reset rubric dropdowns to None
294
+ resets = [None] * 11
295
+ return persona_out + resets
296
 
297
  # persona_str = entry.get("persona_string", "").replace("\n", "<br>")
298
  # archetype = entry.get("archetype", "N/A")
 
328
  md_context_out = gr.Markdown()
329
  md_meta_out = gr.Markdown()
330
  md_other_out = gr.Markdown()
331
+
332
+
333
 
334
  gr.Markdown("### Evaluation Rubric (0 = Worst, 5 = Best)")
335
 
 
349
 
350
  save_btn = gr.Button("Save Annotation")
351
  save_status = gr.Textbox(label="Status", interactive=False)
352
+
353
+ all_outputs = [
354
+ phash_out, md_header_out, md_cats_out, md_present_out, md_clinical_out,
355
+ md_history_out, md_function_out, md_summary_out, md_context_out,
356
+ md_meta_out, md_other_out,
357
+ clarity, originality, coherence, diversity, realism,
358
+ psychological_depth, consistency, informativeness,
359
+ ethical_considerations, demographic_fidelity, overall_score
360
+ ]
361
 
362
  with gr.Row():
363
  export_btn = gr.Button("Download All Annotations")
364
  export_file = gr.File(label="Exported Annotations", type="filepath")
365
 
366
  # Wiring
367
+ file_dropdown.change(load_file, inputs=file_dropdown, outputs=all_outputs)
368
+ prev_btn.click(show_entry, inputs=gr.State("Previous"), outputs=all_outputs)
369
+ next_btn.click(show_entry, inputs=gr.State("Next"), outputs=all_outputs)
370
+ shuffle_btn.click(show_entry, inputs=gr.State("Random Shuffle"), outputs=all_outputs)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
371
 
372
  save_btn.click(
373
  save_annotation,
 
379
 
380
  export_btn.click(export_annotations, inputs=None, outputs=export_file)
381
 
382
+ demo.load(load_file, inputs=gr.State(available_files[0]), outputs=all_outputs)
 
 
 
 
 
383
 
384
  demo.launch()