Spaces:
Runtime error
Runtime error
shripadbhat
commited on
Commit
•
e4cf30a
1
Parent(s):
67b3ac5
Update app.py
Browse files
app.py
CHANGED
@@ -1,13 +1,29 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
|
|
|
|
3 |
|
|
|
4 |
qa_model = pipeline("question-answering",'a-ware/bart-squadv2')
|
5 |
|
6 |
-
def
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
demo = gr.Interface(
|
10 |
-
fn=
|
11 |
#take input as real time audio and use OPENAPI whisper for S2T
|
12 |
#clinical note upload as file (.This is an example of simple text. or doc/docx file)
|
13 |
inputs=[gr.Textbox(lines=2, label='Question', show_label=True, placeholder="What is age of patient ?"),
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
+
from sentence_transformers import CrossEncoder
|
4 |
+
import numpy as np
|
5 |
|
6 |
+
passage_retreival_model = CrossEncoder('cross-encoder/ms-marco-MiniLM-L-6-v2')
|
7 |
qa_model = pipeline("question-answering",'a-ware/bart-squadv2')
|
8 |
|
9 |
+
def fetch_answers(question, clincal_note ):
|
10 |
+
clincal_note_paragraphs = clincal_note.splitlines()
|
11 |
+
query_paragraph_list = [(question, para) for para in clincal_note_paragraphs ]
|
12 |
+
|
13 |
+
scores = passage_retreival_model.predict(query_paragraph_list)
|
14 |
+
top_5_indices = scores.argsort()[:5]
|
15 |
+
query_paragraph_list = np.array(query_paragraph_list)
|
16 |
+
top_5_query_paragraph_list = query_paragraph_list[top_5_indices]
|
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([query, passage, answer])
|
22 |
+
|
23 |
+
return top_5_query_paragraph_answer_list
|
24 |
|
25 |
demo = gr.Interface(
|
26 |
+
fn=fetch_answers,
|
27 |
#take input as real time audio and use OPENAPI whisper for S2T
|
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 ?"),
|