tepsils / app.py
epsil's picture
Update app.py
432993e
import os
import gradio as gr
import torch
from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("microsoft/BioGPT-Large-PubMedQA")
model = AutoModelForCausalLM.from_pretrained("microsoft/BioGPT-Large-PubMedQA")
pipe = pipeline("text-generation",
model=model,
tokenizer = tokenizer,
device="cpu:0")
examples = [['question: Do two decades of British newspaper coverage regarding attempt cardiopulmonary resuscitation decisions : Lessons for clinicians?','context:To review UK newspaper reports relating to Do Not Attempt Cardiopulmonary Resuscitation (DNACPR) decisions in order to identify common themes and encourage dialogue., An online media database (LexisNexis(®)) was searched for UK Newspaper articles between 1993 and 2013 that referenced DNACPR decisions. Legal cases, concerning resuscitation decisions, were identified using two case law databases (Lexis Law(®) and Westlaw(®)), and referenced back to newspaper publications. All articles were fully reviewed., Three hundred and thirty one articles were identified, resulting from 77 identifiable incidents. The periods 2000-01 and 2011-13 encompassed the majority of articles. There were 16 high-profile legal cases, nine of which resulted in newspaper articles. Approximately 35 percent of newspaper reports referred to DNACPR decisions apparently made without adequate patient and/or family consultation. \Ageism\ was referred to in 9 percent of articles (mostly printed 2000-02); and \discrimination against the disabled\ in 8 percent (mostly from 2010-12).'],
['question:Are low serum levels of vitamin D associated with post-stroke depression?','context:Low serum levels of vitamin D have been associated with depression in non-stroke subjects. Our aim was to examine the possible association between serum vitamin D levels and the development of post-stroke depression (PSD)., In total, 189 patients with acute ischaemic stroke were consecutively recruited. Serum levels of 25-hydroxyvitamin D 25(OH)D were measured by competitive protein-binding assay within 24 h after admission. The 17-item Hamilton Depression Scale was used for screening for the existence of depressive symptoms at 1 month after stroke. Patients with a Hamilton Depression Scale score of ≥7 were given the Structured Clinical Interview of the Diagnostic and Statistical Manual of Mental Disorders, 4th edition, for diagnosis of PSD. Meanwhile, 100 healthy control subjects were also recruited and underwent measurement of 25(OH)D., Fifty-five patients (29.1%) were diagnosed as having PSD at 1 month. Serum vitamin D levels within 24 h after admission were significantly lower in both non-PSD patients and PSD patients than in normal controls. PSD patients had significantly lower vitamin D than non-PSD patients. Serum vitamin D levels (≤37.1 and ≥64.1 nmol/l) were independently associated with the development of PSD (odds ratio 8.824, 95% confidence interval 2.011-38.720, P = 0.004, and odds ratio 0.127, 95% confidence interval 0.022-0.718, P = 0.020, respectively)']]
title = "BioGPT Q&A with context Demo"
description = """
NOTE: This model requires the inputs in the following format: `question and context and the answers to the questions from the context`.
Check out the [BioGPT-Large-PubMedQA model card](https://huggingface.co/microsoft/biogpt-large-pubmedqa) for more info.
**Disclaimer:** this demo was made for research purposes only and should not be used for medical purposes.
"""
def inference(text):
output_biogpt = pipe_biogpt(text, max_length=100)[0]["generated_text"]
return [
output_biogpt.split(' ')[-1],
]
io = gr.Interface(
inference,
gr.Textbox(lines=3),
outputs=[
gr.Textbox(lines=3, label="BioGPT Model"),
],
title=title,
description=description,
examples=examples
)
io.launch()