Spaces:
Running
Running
danielhajialigol
commited on
Commit
•
173edcf
1
Parent(s):
adc6c07
functionality for user feedback
Browse files
app.py
CHANGED
@@ -38,6 +38,8 @@ related_summaries = [[ex1]]
|
|
38 |
related_chosen = []
|
39 |
related_attn = []
|
40 |
related_clr_bts = []
|
|
|
|
|
41 |
|
42 |
rule_df, drg2idx, i2d, d2mdc, d2w = load_rule('MSDRG_RULE13.csv')
|
43 |
|
@@ -116,7 +118,9 @@ def run(text, related_discharges=False):
|
|
116 |
gr.ClearButton.update(visible=True),
|
117 |
gr.TextArea.update(visible=True),
|
118 |
gr.Button.update(visible=True),
|
119 |
-
gr.Button.update(visible=True)
|
|
|
|
|
120 |
)
|
121 |
|
122 |
|
@@ -125,18 +129,24 @@ def run_related():
|
|
125 |
global related_chosen
|
126 |
attn_list = []
|
127 |
clr_bts = []
|
|
|
|
|
128 |
for related in related_chosen:
|
129 |
text = related[0]
|
130 |
attn_html = run(text=text, related_discharges=True)
|
131 |
attn_list.append(gr.HTML.update(value=attn_html))
|
132 |
clr_bts.append(gr.ClearButton.update(visible=True))
|
|
|
|
|
133 |
if len(attn_list) != 3:
|
134 |
# find difference
|
135 |
diff = 3 - len(attn_list)
|
136 |
for i in range(diff):
|
137 |
attn_list.append(gr.HTML.update(value=''))
|
138 |
clr_bts.append(gr.ClearButton.update(visible=False))
|
139 |
-
|
|
|
|
|
140 |
|
141 |
|
142 |
|
@@ -155,6 +165,9 @@ def load_df_example(df, event: gr.SelectData):
|
|
155 |
related_chosen.append([discharge_summary])
|
156 |
return prettify_text(related_chosen)
|
157 |
|
|
|
|
|
|
|
158 |
def prettify_text(nested_list):
|
159 |
string = ''
|
160 |
for li in nested_list:
|
@@ -171,7 +184,7 @@ def remove_most_recent():
|
|
171 |
return prettify_text(related_chosen)
|
172 |
|
173 |
def clr_btn():
|
174 |
-
return gr.ClearButton.update(visible=False)
|
175 |
|
176 |
def main():
|
177 |
with gr.Blocks() as demo:
|
@@ -191,35 +204,67 @@ def main():
|
|
191 |
with gr.Row() as row:
|
192 |
attn_viz = gr.HTML()
|
193 |
with gr.Row() as row:
|
194 |
-
|
195 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
196 |
|
197 |
# related row 1
|
198 |
with gr.Row() as row:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
199 |
with gr.Column() as col:
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
|
|
205 |
|
206 |
# related row 2
|
207 |
with gr.Row() as row:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
208 |
with gr.Column() as col:
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
|
|
|
|
214 |
|
215 |
# related row 3
|
216 |
with gr.Row() as row:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
217 |
with gr.Column() as col:
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
|
|
|
|
223 |
|
224 |
# input to related summaries
|
225 |
with gr.Row() as row:
|
@@ -229,13 +274,15 @@ def main():
|
|
229 |
sbm_btn = gr.Button(value="Submit Related Summaries", components=[input_related], visible=False)
|
230 |
|
231 |
with gr.Row() as row:
|
232 |
-
# related = gr.Dataset(samples=[], components=[input_related], visible=False, type='index', headers=['AAAAA', 'BBBB', 'CCCCC', 'DDDDD', 'RRRRR'])
|
233 |
related = gr.DataFrame(
|
234 |
value=None, headers=['Similarity Score', 'Related Discharge Summary'], max_rows=5,
|
235 |
datatype=['number', 'str'], col_count=(2, 'fixed'), visible=False
|
236 |
)
|
237 |
# initial run
|
238 |
-
btn.click(run, inputs=[input], outputs=[
|
|
|
|
|
|
|
239 |
# find related summaries
|
240 |
# related.click(load_example, inputs=[related], outputs=[input_related])
|
241 |
related.select(load_df_example, inputs=[related], outputs=[input_related])
|
@@ -243,7 +290,7 @@ def main():
|
|
243 |
rmv_related_btn.click(remove_most_recent, outputs=[input_related])
|
244 |
|
245 |
# perform attribution on related summaries
|
246 |
-
sbm_btn.click(run_related, outputs=related_attn + related_clr_bts)
|
247 |
|
248 |
|
249 |
demo.launch()
|
|
|
38 |
related_chosen = []
|
39 |
related_attn = []
|
40 |
related_clr_bts = []
|
41 |
+
correct_drg_text_list = []
|
42 |
+
correct_salient_words_list = []
|
43 |
|
44 |
rule_df, drg2idx, i2d, d2mdc, d2w = load_rule('MSDRG_RULE13.csv')
|
45 |
|
|
|
118 |
gr.ClearButton.update(visible=True),
|
119 |
gr.TextArea.update(visible=True),
|
120 |
gr.Button.update(visible=True),
|
121 |
+
gr.Button.update(visible=True),
|
122 |
+
gr.TextArea.update(visible=True),
|
123 |
+
gr.TextArea.update(visible=True)
|
124 |
)
|
125 |
|
126 |
|
|
|
129 |
global related_chosen
|
130 |
attn_list = []
|
131 |
clr_bts = []
|
132 |
+
correct_drg_list = []
|
133 |
+
correct_salient_list = []
|
134 |
for related in related_chosen:
|
135 |
text = related[0]
|
136 |
attn_html = run(text=text, related_discharges=True)
|
137 |
attn_list.append(gr.HTML.update(value=attn_html))
|
138 |
clr_bts.append(gr.ClearButton.update(visible=True))
|
139 |
+
correct_drg_list.append(gr.Textbox.update(visible=True))
|
140 |
+
correct_salient_list.append(gr.Textbox.update(visible=True))
|
141 |
if len(attn_list) != 3:
|
142 |
# find difference
|
143 |
diff = 3 - len(attn_list)
|
144 |
for i in range(diff):
|
145 |
attn_list.append(gr.HTML.update(value=''))
|
146 |
clr_bts.append(gr.ClearButton.update(visible=False))
|
147 |
+
correct_drg_list.append(gr.Textbox.update(visible=False))
|
148 |
+
correct_salient_list.append(gr.Textbox.update(visible=False))
|
149 |
+
return attn_list + clr_bts + correct_drg_list + correct_salient_list
|
150 |
|
151 |
|
152 |
|
|
|
165 |
related_chosen.append([discharge_summary])
|
166 |
return prettify_text(related_chosen)
|
167 |
|
168 |
+
def save_results(text):
|
169 |
+
return
|
170 |
+
|
171 |
def prettify_text(nested_list):
|
172 |
string = ''
|
173 |
for li in nested_list:
|
|
|
184 |
return prettify_text(related_chosen)
|
185 |
|
186 |
def clr_btn():
|
187 |
+
return gr.ClearButton.update(visible=False), gr.Textbox.update(visible=False), gr.Textbox.update(visible=False)
|
188 |
|
189 |
def main():
|
190 |
with gr.Blocks() as demo:
|
|
|
204 |
with gr.Row() as row:
|
205 |
attn_viz = gr.HTML()
|
206 |
with gr.Row() as row:
|
207 |
+
with gr.Column() as col:
|
208 |
+
correct_drg_text = gr.Textbox(visible=False, label="Input Correct DRG", interactive=True)
|
209 |
+
correct_drg_text.submit(save_results, inputs=correct_drg_text)
|
210 |
+
with gr.Column() as col:
|
211 |
+
salient_words_box = gr.Textbox(visible=False, label="Input Salient Words (comma separated)", interactive=True)
|
212 |
+
salient_words_box.submit(save_results, inputs=salient_words_box)
|
213 |
+
attn_clr_btn = gr.ClearButton(value='Remove DRG Results', visible=False, components=[attn_viz])
|
214 |
+
attn_clr_btn.click(clr_btn, outputs=[attn_clr_btn, correct_drg_text, salient_words_box])
|
215 |
|
216 |
# related row 1
|
217 |
with gr.Row() as row:
|
218 |
+
attn_1 = gr.HTML()
|
219 |
+
related_attn.append(attn_1)
|
220 |
+
with gr.Row() as row:
|
221 |
+
with gr.Column() as col:
|
222 |
+
correct_drg_text_1 = gr.Textbox(visible=False, label="Input Correct DRG", interactive=True)
|
223 |
+
correct_drg_text_1.submit(save_results, inputs=correct_drg_text_1)
|
224 |
+
correct_drg_text_list.append(correct_drg_text_1)
|
225 |
with gr.Column() as col:
|
226 |
+
salient_words_box_1 = gr.Textbox(visible=False, label="Input Salient Words (comma separated)", interactive=True)
|
227 |
+
salient_words_box_1.submit(save_results, inputs=salient_words_box_1)
|
228 |
+
correct_salient_words_list.append(salient_words_box_1)
|
229 |
+
attn_clr_1 = gr.ClearButton(value='Remove DRG Results', visible=False, components=[attn_1])
|
230 |
+
related_clr_bts.append(attn_clr_1)
|
231 |
+
attn_clr_1.click(clr_btn, outputs=[attn_clr_1, correct_drg_text_1, salient_words_box_1])
|
232 |
|
233 |
# related row 2
|
234 |
with gr.Row() as row:
|
235 |
+
attn_2 = gr.HTML()
|
236 |
+
related_attn.append(attn_2)
|
237 |
+
with gr.Row() as row:
|
238 |
+
with gr.Column() as col:
|
239 |
+
correct_drg_text_2 = gr.Textbox(visible=False, label="Input Correct DRG", interactive=True)
|
240 |
+
correct_drg_text_2.submit(save_results, inputs=correct_drg_text_2)
|
241 |
+
correct_drg_text_list.append(correct_drg_text_2)
|
242 |
with gr.Column() as col:
|
243 |
+
salient_words_box_2 = gr.Textbox(visible=False, label="Input Salient Words (comma separated)", interactive=True)
|
244 |
+
salient_words_box_2.submit(save_results, inputs=salient_words_box_2)
|
245 |
+
correct_salient_words_list.append(salient_words_box_2)
|
246 |
+
attn_clr_2 = gr.ClearButton(value='Remove DRG Results', visible=False, components=[attn_2])
|
247 |
+
related_clr_bts.append(attn_clr_2)
|
248 |
+
attn_clr_2.click(clr_btn, outputs=[attn_clr_2, correct_drg_text_2, salient_words_box_2])
|
249 |
+
|
250 |
|
251 |
# related row 3
|
252 |
with gr.Row() as row:
|
253 |
+
attn_3 = gr.HTML()
|
254 |
+
related_attn.append(attn_3)
|
255 |
+
with gr.Row() as row:
|
256 |
+
with gr.Column() as col:
|
257 |
+
correct_drg_text_3 = gr.Textbox(visible=False, label="Input Correct DRG", interactive=True)
|
258 |
+
correct_drg_text_3.submit(save_results, inputs=correct_drg_text_3)
|
259 |
+
correct_drg_text_list.append(correct_drg_text_3)
|
260 |
with gr.Column() as col:
|
261 |
+
salient_words_box_3 = gr.Textbox(visible=False, label="Input Salient Words (comma separated)", interactive=True)
|
262 |
+
salient_words_box_3.submit(save_results, inputs=salient_words_box_3)
|
263 |
+
correct_salient_words_list.append(salient_words_box_3)
|
264 |
+
attn_clr_3 = gr.ClearButton(value='Remove DRG Results', visible=False, components=[attn_3])
|
265 |
+
related_clr_bts.append(attn_clr_3)
|
266 |
+
attn_clr_3.click(clr_btn, outputs=[attn_clr_3, correct_drg_text_3, salient_words_box_3])
|
267 |
+
|
268 |
|
269 |
# input to related summaries
|
270 |
with gr.Row() as row:
|
|
|
274 |
sbm_btn = gr.Button(value="Submit Related Summaries", components=[input_related], visible=False)
|
275 |
|
276 |
with gr.Row() as row:
|
|
|
277 |
related = gr.DataFrame(
|
278 |
value=None, headers=['Similarity Score', 'Related Discharge Summary'], max_rows=5,
|
279 |
datatype=['number', 'str'], col_count=(2, 'fixed'), visible=False
|
280 |
)
|
281 |
# initial run
|
282 |
+
btn.click(run, inputs=[input], outputs=[
|
283 |
+
attn_viz, related, attn_clr_btn, input_related,
|
284 |
+
sbm_btn, rmv_related_btn, correct_drg_text, salient_words_box
|
285 |
+
])
|
286 |
# find related summaries
|
287 |
# related.click(load_example, inputs=[related], outputs=[input_related])
|
288 |
related.select(load_df_example, inputs=[related], outputs=[input_related])
|
|
|
290 |
rmv_related_btn.click(remove_most_recent, outputs=[input_related])
|
291 |
|
292 |
# perform attribution on related summaries
|
293 |
+
sbm_btn.click(run_related, outputs=related_attn + related_clr_bts + correct_drg_text_list + correct_salient_words_list)
|
294 |
|
295 |
|
296 |
demo.launch()
|