File size: 2,336 Bytes
ae1dc47
281af70
ae1dc47
 
 
281af70
edda5b8
281af70
f9db121
281af70
ae1dc47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
281af70
 
 
 
 
 
 
 
 
 
 
 
 
 
34c89ca
281af70
 
 
 
 
 
 
f9db121
dbba0b3
ae1dc47
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import os
import gradio as gr
import torch
import numpy as np
from transformers import pipeline

name_list = ['microsoft/biogpt', 'stanford-crfm/BioMedLM']

examples = [['COVID-19 is'],['A 65-year-old female patient with a past medical history of']] 

#import torch
#print(f"Is CUDA available: {torch.cuda.is_available()}")
#print(f"CUDA device: {torch.cuda.get_device_name(torch.cuda.current_device())}")

pipe_biogpt = pipeline("text2text-generation", model="microsoft/biogpt")
pipe_biomedlm = pipeline("text2text-generation", model="stanford-crfm/BioMedLM")

title = "Compare generative biomedical LLMs!"
description = "This demo compares [BioGPT](https://huggingface.co/microsoft/biogpt) and [BioMedLM](https://huggingface.co/stanford-crfm/BioMedLM)."

def inference(text):
  output_biogpt = pipe_biogpt(text, max_length=100)[0]["generated_text"]
  output_biomedlm = pipe_biomedlm(text, max_length=100)[0]["generated_text"]
  return [output_biogpt, output_biomedlm]

io = gr.Interface(
  inference,
  gr.Textbox(lines=3),
  outputs=[
    gr.Textbox(lines=3, label="BioGPT"),
    gr.Textbox(lines=3, label="BioMedLM")
  ],
  title=title,
  description=description,
  examples=examples
)
io.launch()

"""
def generate_biomedical(text):
    interfaces = [gr.Interface.load(name) for name in name_list]
    return [interface(text) for interface in interfaces]

def set_example(example: list) -> dict:
    return gr.Textbox.update(value=example[0]) 
    
with gr.Blocks() as demo:
    gr.Markdown("# Compare generative biomedical LLMs")
    with gr.Box():
        with gr.Row():
            with gr.Column():
                input_text = gr.Textbox(label = "Write your text here", lines=4)
                with gr.Row():
                    btn = gr.Button("Generate ✨")
                
                example_text = gr.Dataset(components=[input_text], samples=examples)
                example_text.click(fn=set_example,
                                inputs = example_text,
                                outputs= example_text.components)    
            with gr.Column():   
                gr.Markdown("Let’s compare!")      
                btn.click(generate_biomedical, inputs = input_text, outputs = [gr.Textbox(label=name_list[_], lines=4) for _ in range(len(name_list))])

demo.launch(enable_queue=True, debug=True)
"""