|
import gradio as gr |
|
import tensorflow as tf |
|
from tensorflow.keras.models import load_model |
|
|
|
def split_char(text): |
|
return " ".join(list(text)) |
|
|
|
|
|
import zipfile |
|
zip_ref = zipfile.ZipFile("Universal_sentence_encoder_Tribrid_embedding_model.zip", "r") |
|
zip_ref.extractall() |
|
zip_ref.close() |
|
|
|
|
|
from spacy.lang.en import English |
|
|
|
def make_predictions(Input): |
|
class_names=['BACKGROUND','CONCLUSIONS','METHODS','OBJECTIVE','RESULTS'] |
|
|
|
nlp = English() |
|
|
|
|
|
nlp.add_pipe('sentencizer') |
|
|
|
|
|
doc=nlp(Input) |
|
|
|
|
|
sents_list = [] |
|
for sent in doc.sents: |
|
sents_list.append(sent.text) |
|
|
|
abstract_sentences=sents_list |
|
|
|
|
|
sample_line=[] |
|
for i,line in enumerate(abstract_sentences): |
|
sample_dict={} |
|
sample_dict["text"]=str(line) |
|
sample_dict["line_number"]=i |
|
sample_dict["total_lines"]=len(abstract_sentences)-1 |
|
sample_line.append(sample_dict) |
|
|
|
|
|
abstract_line_number=[line["line_number"] for line in sample_line] |
|
|
|
abstract_line_number_one_hot=tf.one_hot(abstract_line_number,depth=15) |
|
|
|
|
|
abstract_total_lines=[line["total_lines"] for line in sample_line] |
|
|
|
abstract_total_lines_one_hot=tf.one_hot(abstract_total_lines,depth=20) |
|
|
|
|
|
abstract_char=[split_char(sentence) for sentence in abstract_sentences] |
|
|
|
|
|
|
|
|
|
skimlit_model=load_model("Universal_sentence_encoder_Tribrid_embedding_model") |
|
|
|
|
|
abstract_pred_probs=skimlit_model.predict(x=(abstract_line_number_one_hot, |
|
abstract_total_lines_one_hot, |
|
tf.constant(abstract_sentences), |
|
tf.constant(abstract_char))) |
|
|
|
|
|
abstract_preds=tf.argmax(abstract_pred_probs,axis=1) |
|
|
|
|
|
predicted_classes=[class_names[i] for i in abstract_preds] |
|
|
|
|
|
summary="" |
|
for i,line in enumerate(abstract_sentences): |
|
summary=summary+f"{predicted_classes[i]}: {line}\n" |
|
|
|
return summary |
|
|
|
demo = gr.Interface(fn=make_predictions, |
|
inputs=gr.Textbox(lines=2, placeholder="Enter Abstract Here..."), |
|
outputs="text", |
|
live=True, |
|
title="Sequential sentence classifier for Medical Abstracts", |
|
examples=[["Hepatitis C virus (HCV) and alcoholic liver disease (ALD), either alone or in combination, count for more than two thirds of all liver diseases in the Western world. There is no safe level of drinking in HCV-infected patients and the most effective goal for these patients is total abstinence. Baclofen, a GABA(B) receptor agonist, represents a promising pharmacotherapy for alcohol dependence (AD). Previously, we performed a randomized clinical trial (RCT), which demonstrated the safety and efficacy of baclofen in patients affected by AD and cirrhosis. The goal of this post-hoc analysis was to explore baclofen's effect in a subgroup of alcohol-dependent HCV-infected cirrhotic patients. Any patient with HCV infection was selected for this analysis. Among the 84 subjects randomized in the main trial, 24 alcohol-dependent cirrhotic patients had a HCV infection; 12 received baclofen 10mg t.i.d. and 12 received placebo for 12-weeks. With respect to the placebo group (3/12, 25.0%), a significantly higher number of patients who achieved and maintained total alcohol abstinence was found in the baclofen group (10/12, 83.3%; p=0.0123). Furthermore, in the baclofen group, compared to placebo, there was a significantly higher increase in albumin values from baseline (p=0.0132) and a trend toward a significant reduction in INR levels from baseline (p=0.0716). In conclusion, baclofen was safe and significantly more effective than placebo in promoting alcohol abstinence, and improving some Liver Function Tests (LFTs) (i.e. albumin, INR) in alcohol-dependent HCV-infected cirrhotic patients. Baclofen may represent a clinically relevant alcohol pharmacotherapy for these patients."]], |
|
description="An NLP model that classifies each sentence of a medical abstract to an appropriate heading in order to significantly reduce time to locate the desired information.") |
|
|
|
demo.launch(debug=True, inline=True) |