llm-vs-llm / app.py
davila7's picture
flan t5 vs gpt2
3c355ba
raw
history blame
1.52 kB
import os
import gradio as gr
import torch
import numpy as np
from transformers import pipeline
name_list = ['microsoft/biogpt', 'google/flan-ul2', 'facebook/galactica-1.3b']
examples = [['COVID-19 is'],['A 65-year-old female patient with a past medical history of']]
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("text-generation", model="microsoft/BioGPT-Large", device="cuda:0", model_kwargs={"torch_dtype":torch.bfloat16})
pipe_flan_t5_xxl = pipeline("text-generation", model="google/flan-t5-xxl", device="cuda:0", model_kwargs={"torch_dtype":torch.bfloat16})
pipe_gpt_2 = pipeline("text-generation", model="gpt2", device="cuda:0", model_kwargs={"torch_dtype":torch.bfloat16})
title = "LLM vs LLM!"
description = "**Disclaimer:** this demo was made for research purposes only."
def inference(text):
output_biogpt = pipe_biogpt(text, max_length=100)[0]["generated_text"]
output_flan_t5_xxl = pipe_flan_t5_xxl(text, max_length=100)[0]["generated_text"]
output_gpt_2 = pipe_gpt_2(text, max_length=100)[0]["generated_text"]
return [
output_biogpt,
output_flan_t5_xxl,
output_gpt_2
]
io = gr.Interface(
inference,
gr.Textbox(lines=3),
outputs=[
gr.Textbox(lines=3, label="BioGPT-Large"),
gr.Textbox(lines=3, label="Flan T5 XXL"),
gr.Textbox(lines=3, label="GPT-2"),
],
title=title,
description=description,
examples=examples
)
io.launch()