shripadbhat's picture
Update app.py
e4cf30a
raw
history blame
2.09 kB
import gradio as gr
from transformers import pipeline
from sentence_transformers import CrossEncoder
import numpy as np
passage_retreival_model = CrossEncoder('cross-encoder/ms-marco-MiniLM-L-6-v2')
qa_model = pipeline("question-answering",'a-ware/bart-squadv2')
def fetch_answers(question, clincal_note ):
clincal_note_paragraphs = clincal_note.splitlines()
query_paragraph_list = [(question, para) for para in clincal_note_paragraphs ]
scores = passage_retreival_model.predict(query_paragraph_list)
top_5_indices = scores.argsort()[:5]
query_paragraph_list = np.array(query_paragraph_list)
top_5_query_paragraph_list = query_paragraph_list[top_5_indices]
top_5_query_paragraph_answer_list = []
for query, passage in top_5_query_paragraph_list:
answer = qa_model(question = query, context = passage)['answer']
top_5_query_paragraph_answer_list.append([query, passage, answer])
return top_5_query_paragraph_answer_list
demo = gr.Interface(
fn=fetch_answers,
#take input as real time audio and use OPENAPI whisper for S2T
#clinical note upload as file (.This is an example of simple text. or doc/docx file)
inputs=[gr.Textbox(lines=2, label='Question', show_label=True, placeholder="What is age of patient ?"),
gr.Textbox(lines=10, label='Clinical Note', show_label=True, placeholder="The patient is a 71 year old male...")],
outputs="text",
examples='.',
title='Question Answering System from Clinical Notes for Physicians',
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."""
)
demo.launch()