shripadbhat commited on
Commit
d4fb40d
·
1 Parent(s): 37b8d56

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -1,5 +1,4 @@
1
  import gradio as gr
2
- import pandas as pd
3
  from transformers import pipeline
4
  from sentence_transformers import CrossEncoder
5
 
@@ -15,12 +14,16 @@ def fetch_answers(question, clincal_note ):
15
  top_5_query_paragraph_list = [query_paragraph_list[i] for i in top_5_indices ]
16
  top_5_query_paragraph_list.reverse()
17
 
18
- top_5_query_paragraph_answer_list = []
 
19
  for query, passage in top_5_query_paragraph_list:
20
  answer = qa_model(question = query, context = passage)['answer']
21
- top_5_query_paragraph_answer_list.append([passage, answer])
 
 
 
22
 
23
- return pd.DataFrame(data = top_5_query_paragraph_answer_list, columns=['Relevant Paragraph', 'Extracted Answer'])
24
 
25
  demo = gr.Interface(
26
  fn=fetch_answers,
@@ -28,7 +31,7 @@ demo = gr.Interface(
28
  #clinical note upload as file (.This is an example of simple text. or doc/docx file)
29
  inputs=[gr.Textbox(lines=2, label='Question', show_label=True, placeholder="What is age of patient ?"),
30
  gr.Textbox(lines=10, label='Clinical Note', show_label=True, placeholder="The patient is a 71 year old male...")],
31
- outputs="dataframe",
32
  examples='.',
33
  title='Question Answering System from Clinical Notes for Physicians',
34
  description="""Physicians frequently seek answers to questions from a patient’s EHR to support clinical decision-making.​ It is not too hard to imagine a future where a physician interacts with an EHR system and asks it complex questions and expects precise answers with adequate context from a patient’s past clinical notes. ​Central to such a world is a medical question answering system that processes natural language questions asked by physicians and finds answers to the questions from all sources in a patient’s record."""
 
1
  import gradio as gr
 
2
  from transformers import pipeline
3
  from sentence_transformers import CrossEncoder
4
 
 
14
  top_5_query_paragraph_list = [query_paragraph_list[i] for i in top_5_indices ]
15
  top_5_query_paragraph_list.reverse()
16
 
17
+ top_5_query_paragraph_answer_list = ""
18
+ count = 1
19
  for query, passage in top_5_query_paragraph_list:
20
  answer = qa_model(question = query, context = passage)['answer']
21
+ result_str = "#RESULT "+str(count)+":\n"
22
+ result_str = result_str + passage.replace(answer,"**"+answer+"**") + "\n\n"
23
+ top_5_query_paragraph_answer_list += result_str
24
+ count+=1
25
 
26
+ return top_5_query_paragraph_answer_list
27
 
28
  demo = gr.Interface(
29
  fn=fetch_answers,
 
31
  #clinical note upload as file (.This is an example of simple text. or doc/docx file)
32
  inputs=[gr.Textbox(lines=2, label='Question', show_label=True, placeholder="What is age of patient ?"),
33
  gr.Textbox(lines=10, label='Clinical Note', show_label=True, placeholder="The patient is a 71 year old male...")],
34
+ outputs="markdown",
35
  examples='.',
36
  title='Question Answering System from Clinical Notes for Physicians',
37
  description="""Physicians frequently seek answers to questions from a patient’s EHR to support clinical decision-making.​ It is not too hard to imagine a future where a physician interacts with an EHR system and asks it complex questions and expects precise answers with adequate context from a patient’s past clinical notes. ​Central to such a world is a medical question answering system that processes natural language questions asked by physicians and finds answers to the questions from all sources in a patient’s record."""