emvecchi commited on
Commit
58b9079
·
verified ·
1 Parent(s): 31fc038

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -182
app.py CHANGED
@@ -119,19 +119,19 @@ Please indicate, in the box below, that you are at least 18 years old, have read
119
  '''
120
 
121
  fields: List[Field] = [
122
- Field(name="patient", type="input_col", title=""),
123
  Field(type="expander", title="**Session Transcription:** *(expand)*", children=[
124
  Field(name="dialogue_name", type="input_col", title=""),
125
  ]),
126
 
127
- Field(type="container", title="#### Session-/Patient-Specific Properties", children=[
128
  Field(name="diagnosis_mention", type="likert_radio",
129
  title="Explicit mention of clinical diagnosis?", other_params={'labels': mentioned_y_n}, mandatory=True),
130
  Field(name="priority_level", type="likert_radio",
131
  title="Level of priority", other_params={'labels': priority_labels}, mandatory=True),
132
  ]),
133
 
134
- Field(type="container", title="#### Rupture Markers", children=[
135
  Field(type="expander", title="**Overview of rupture markers** *(expand)*", children=[
136
  Field(type="markdown", title="", other_params={"path": "rupture_marker_overview.md"}),
137
  ]),
@@ -139,22 +139,22 @@ fields: List[Field] = [
139
  title="Select rupture markers noted in the session, include line numbers where rupture is found.", mandatory=False),
140
  ]),
141
 
142
- Field(type="container", title="#### True-To-Patient-Prompt Features", children=[
143
  Field(type="expander", title="**Patient Role Description:** *(expand)*", children=[
144
  Field(name="role_name", type="input_col", title=""),
145
  ]),
146
- Field(name="true_to_roll", type="y_n_radio",
147
  title="Did the patient remain true to the provided patient description?", mandatory=True,
148
  following_mandatory_values=[1]),
149
  ]),
150
 
151
- Field(type="container", title="#### Rate the therapist", children=[
152
  Field(name="empathy", type="y_n_radio",
153
  title="Was the therapist empathetic?", mandatory=True,
154
  following_mandatory_values=[1]),
155
  ]),
156
 
157
- Field(type="container", title="#### Additional Comments *(optional)*", children=[
158
  Field(name="other_comments", type="text", title="Please provide any additional details or information:", mandatory=False),
159
  ]),
160
  ]
@@ -481,171 +481,10 @@ def navigate(index_change):
481
  )
482
  st.rerun()
483
 
484
-
485
- #def show_field(f: Field, index: int, data_collected):
486
- # if f.type not in INPUT_FIELD_DEFAULT_VALUES.keys():
487
- # st.session_state.following_mandatory = False
488
- # match f.type:
489
- # case 'input_col':
490
- # #if f.name and f.name in st.session_state.data.columns:
491
- # # value = st.session_state.data.iloc[index][f.name]
492
- # #else:
493
- # # value = None
494
- # value = st.session_state.data.iloc[index][f.name]
495
- # if value and value is not np.nan:
496
- # st.write(f.title)
497
- # if f.name == 'image_name':
498
- # display_image(os.path.join(input_repo_path, 'images', value))
499
- # elif f.name == 'dialogue_name':
500
- # render_dialogue(os.path.join(input_repo_path, 'dialogues', value), width_chars=115, height_px=520, show_border=False)
501
- # #elif f.name == 'rupture_marker_overview':
502
- # # display_dialogue(os.path.join(input_repo_path, 'rupture_marker_overview.md'))
503
- # elif f.name == 'patient':
504
- # st.markdown(f"## Patient:  {value}")
505
- # else:
506
- # st.write(value)
507
- # case 'markdown':
508
- # path = f.other_params.get("path") if f.other_params else None
509
- # if path:
510
- # content = load_text(os.path.join(input_repo_path, path))
511
- # st.markdown(content, unsafe_allow_html=True)
512
- # else:
513
- # st.markdown(f.title)
514
- # case 'expander' | 'container':
515
- # with (st.expander(f.title) if f.type == 'expander' else st.container(border=True)):
516
- # if f.type == 'container':
517
- # st.markdown(f.title)
518
- # for child in f.children:
519
- # show_field(child, index, data_collected)
520
- # case 'skip_checkbox':
521
- # st.checkbox(f.title, key=f.name, value=False)
522
- # case 'rupture_markers':
523
- # render_rupture_markers_widget(index, rupture_choices)
524
- # else:
525
- # key = f.name + str(index)
526
- # st.session_state.data_inputs_keys.append(f.name)
527
- # value = st.session_state[key] if key in st.session_state else \
528
- # (data_collected[f.name] if data_collected else INPUT_FIELD_DEFAULT_VALUES[f.type])
529
- # if not SHOW_HELP_ICON:
530
- # f.title = f'**{f.title}**\n\n{f.help}' if f.help else f.title
531
- #
532
- # validation_error = False
533
- #
534
- # # form is not displayed for first time
535
- # if st.session_state.form_displayed == st.session_state.current_index:
536
- # if st.session_state.following_mandatory and f.skip_mandatory:
537
- # st.session_state.following_mandatory = False
538
- # if f.following_mandatory_values and st.session_state[key] in f.following_mandatory_values:
539
- # st.session_state.following_mandatory = True
540
- # if f.mandatory or st.session_state.following_mandatory:
541
- # if st.session_state[key] == INPUT_FIELD_DEFAULT_VALUES[f.type]:
542
- # st.session_state.valid = False
543
- # validation_error = True
544
- # elif f.following_mandatory_values and st.session_state[key] in f.following_mandatory_values:
545
- # st.session_state.following_mandatory = True
546
- #
547
- # # check for any unaccepted values
548
- # if (
549
- # (f.other_params.get('accepted_values') and
550
- # value not in f.other_params.get('accepted_values')) or
551
- # (f.other_params.get('accepted_values_per_sample') and
552
- # index in f.other_params.get('accepted_values_per_sample') and
553
- # value not in f.other_params.get('accepted_values_per_sample').get(index))
554
- # ):
555
- # st.session_state.unacceptable_response = True
556
- #
557
- # if f.mandatory or st.session_state.following_mandatory:
558
- # f.title += " :red[* required!]" if (validation_error and not SHOW_VALIDATION_ERROR_MESSAGE) else' :red[*]'
559
- # f.help = None
560
- #
561
- # match f.type:
562
- # case 'checkbox':
563
- # st.checkbox(f.title,
564
- # key=key,
565
- # value=value, help=f.help)
566
- # case 'radio':
567
- # labels = default_labels if not f.other_params.get('labels') else f.other_params.get('labels')
568
- # st.radio(f.title,
569
- # options=range(len(labels)),
570
- # format_func=lambda x: labels[x],
571
- # key=key,
572
- # index=value, help=f.help, horizontal=False)
573
- # case 'slider':
574
- # st.slider(f.title,
575
- # min_value=0, max_value=6, step=1,
576
- # key=key,
577
- # value=value, help=f.help)
578
- # case 'select_slider':
579
- # labels = default_labels if not f.other_params.get('labels') else f.other_params.get('labels')
580
- # st.select_slider(f.title,
581
- # options=[0, 20, 40, 60, 80, 100],
582
- # format_func=lambda x: labels[x // 20],
583
- # key=key,
584
- # value=value, help=f.help)
585
- # case 'multiselect':
586
- # choices = default_choices if not f.other_params.get('choices') else f.other_params.get('choices')
587
- # st.multiselect(f.title,
588
- # options = choices,
589
- # format_func=lambda x: x,
590
- # key=key, max_selections=3,
591
- # default=value, help=f.help)
592
- # case 'likert_radio':
593
- # labels = default_labels if not f.other_params.get('labels') else f.other_params.get('labels')
594
- # st.radio(f.title,
595
- # options=[0, 1, 2, 3, 4],
596
- # format_func=lambda x: labels[x],
597
- # key=key,
598
- # index=value, help=f.help, horizontal=True)
599
- # case 'y_n_radio':
600
- # labels = yes_no_labels if not f.other_params.get('labels') else f.other_params.get('labels')
601
- # st.radio(f.title,
602
- # options=[0, 1],
603
- # format_func=lambda x: labels[x],
604
- # key=key,
605
- # index=value, help=f.help, horizontal=True)
606
- # case 'text':
607
- # st.text_input(f.title, key=key, value=value, max_chars=None)
608
- # case 'textarea':
609
- # st.text_area(f.title, key=key, value=value, max_chars=None)
610
- #
611
- # if validation_error:
612
- # st.session_state.unacceptable_response = False
613
- # st.error(f"Mandatory field")
614
-
615
-
616
- #def show_fields(fields: List[Field]):
617
- # st.session_state.valid = True
618
- # index = st.session_state.current_index
619
- # data_collected = read_saved_data()
620
- # st.session_state.data_inputs_keys = []
621
- # st.session_state.following_mandatory = False
622
- #
623
- # for field in fields:
624
- # show_field(field, index, data_collected)
625
- #
626
- # submitted = st.form_submit_button("Submit")
627
- # if submitted:
628
- # if 'unacceptable_response' in st.session_state and st.session_state.unacceptable_response:
629
- # prep_and_save_data(index, ('skip' in st.session_state and st.session_state['skip']))
630
- # st.rerun()
631
- # skip_sample = ('skip' in st.session_state and st.session_state['skip'])
632
- # if not skip_sample and not st.session_state.valid:
633
- # st.error("Please fill in all mandatory fields")
634
- # # st.rerun() # filed-out values are not shown otherwise
635
- # else:
636
- # with st.spinner(text="saving"):
637
- # prep_and_save_data(index, skip_sample)
638
- # st.success("Feedback submitted successfully!")
639
- # navigate(1)
640
- #
641
- # st.session_state.form_displayed = st.session_state.current_index
642
- #
643
-
644
  def show_field(f: Field, index: int, data_collected):
645
  if f.type not in INPUT_FIELD_DEFAULT_VALUES.keys():
646
  match f.type:
647
  case 'input_col':
648
- # Safely read CSV value if the column exists
649
  value = (
650
  st.session_state.data.iloc[index][f.name]
651
  if f.name and f.name in st.session_state.data.columns
@@ -671,13 +510,11 @@ def show_field(f: Field, index: int, data_collected):
671
  st.markdown(f"### Patient:  {value}")
672
 
673
  elif value not in (None, np.nan, ""):
674
- # generic fallback
675
  if f.title:
676
  st.write(f.title)
677
  st.write(value)
678
 
679
  case 'markdown':
680
- # Either render file contents, or the literal title as markdown
681
  path = f.other_params.get("path") if f.other_params else None
682
  if path:
683
  content = load_text(os.path.join(input_repo_path, path))
@@ -697,16 +534,13 @@ def show_field(f: Field, index: int, data_collected):
697
  show_field(child, index, data_collected)
698
 
699
  case 'skip_checkbox':
700
- # Lives fine outside forms
701
  st.checkbox(f.title, key=f.name, value=False)
702
 
703
  case 'rupture_markers':
704
- # Dynamic add/remove rows (outside forms so buttons rerun)
705
  render_rupture_markers_widget(index, rupture_choices)
706
 
707
- return # done with structural types
708
 
709
- # ---------- Input types (saved to session & later to JSON) ----------
710
  else:
711
  key = f.name + str(index)
712
  # track the logical field name once per page; prep_and_save_data relies on this
@@ -716,14 +550,6 @@ def show_field(f: Field, index: int, data_collected):
716
  if not SHOW_HELP_ICON:
717
  f.title = f'**{f.title}**\n\n{f.help}' if f.help else f.title
718
 
719
- # Resolve initial value: session_state > saved JSON > default
720
- # if key in st.session_state:
721
- # value = st.session_state[key]
722
- # elif data_collected and f.name in data_collected:
723
- # value = data_collected[f.name]
724
- # else:
725
- # value = INPUT_FIELD_DEFAULT_VALUES[f.type]
726
-
727
  if st.session_state.form_displayed == st.session_state.current_index:
728
  if st.session_state.following_mandatory and f.skip_mandatory:
729
  st.session_state.following_mandatory = False
 
119
  '''
120
 
121
  fields: List[Field] = [
122
+ Field(name="patient", type="input_col", title=" "),
123
  Field(type="expander", title="**Session Transcription:** *(expand)*", children=[
124
  Field(name="dialogue_name", type="input_col", title=""),
125
  ]),
126
 
127
+ Field(type="expander", title="**Annotation 1: Session-/Patient-Specific Properties**", children=[
128
  Field(name="diagnosis_mention", type="likert_radio",
129
  title="Explicit mention of clinical diagnosis?", other_params={'labels': mentioned_y_n}, mandatory=True),
130
  Field(name="priority_level", type="likert_radio",
131
  title="Level of priority", other_params={'labels': priority_labels}, mandatory=True),
132
  ]),
133
 
134
+ Field(type="expander", title="**Annotation 2: Rupture Markers**", children=[
135
  Field(type="expander", title="**Overview of rupture markers** *(expand)*", children=[
136
  Field(type="markdown", title="", other_params={"path": "rupture_marker_overview.md"}),
137
  ]),
 
139
  title="Select rupture markers noted in the session, include line numbers where rupture is found.", mandatory=False),
140
  ]),
141
 
142
+ Field(type="expander", title="**Annotation 3: True-To-Patient-Prompt Features**", children=[
143
  Field(type="expander", title="**Patient Role Description:** *(expand)*", children=[
144
  Field(name="role_name", type="input_col", title=""),
145
  ]),
146
+ Field(name="true_to_role", type="y_n_radio",
147
  title="Did the patient remain true to the provided patient description?", mandatory=True,
148
  following_mandatory_values=[1]),
149
  ]),
150
 
151
+ Field(type="expander", title="**Annotation 4: Rate the therapist**", children=[
152
  Field(name="empathy", type="y_n_radio",
153
  title="Was the therapist empathetic?", mandatory=True,
154
  following_mandatory_values=[1]),
155
  ]),
156
 
157
+ Field(type="container", title="**Additional Comments** *(optional)*", children=[
158
  Field(name="other_comments", type="text", title="Please provide any additional details or information:", mandatory=False),
159
  ]),
160
  ]
 
481
  )
482
  st.rerun()
483
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
484
  def show_field(f: Field, index: int, data_collected):
485
  if f.type not in INPUT_FIELD_DEFAULT_VALUES.keys():
486
  match f.type:
487
  case 'input_col':
 
488
  value = (
489
  st.session_state.data.iloc[index][f.name]
490
  if f.name and f.name in st.session_state.data.columns
 
510
  st.markdown(f"### Patient:  {value}")
511
 
512
  elif value not in (None, np.nan, ""):
 
513
  if f.title:
514
  st.write(f.title)
515
  st.write(value)
516
 
517
  case 'markdown':
 
518
  path = f.other_params.get("path") if f.other_params else None
519
  if path:
520
  content = load_text(os.path.join(input_repo_path, path))
 
534
  show_field(child, index, data_collected)
535
 
536
  case 'skip_checkbox':
 
537
  st.checkbox(f.title, key=f.name, value=False)
538
 
539
  case 'rupture_markers':
 
540
  render_rupture_markers_widget(index, rupture_choices)
541
 
542
+ return
543
 
 
544
  else:
545
  key = f.name + str(index)
546
  # track the logical field name once per page; prep_and_save_data relies on this
 
550
  if not SHOW_HELP_ICON:
551
  f.title = f'**{f.title}**\n\n{f.help}' if f.help else f.title
552
 
 
 
 
 
 
 
 
 
553
  if st.session_state.form_displayed == st.session_state.current_index:
554
  if st.session_state.following_mandatory and f.skip_mandatory:
555
  st.session_state.following_mandatory = False