Spaces:
Runtime error
Runtime error
Add application file
Browse files
app.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import torch
|
| 4 |
+
import numpy as np
|
| 5 |
+
from transformers import pipeline
|
| 6 |
+
|
| 7 |
+
examples = [['Q: Can Geoffrey Hinton have a conversation with George Washington? Give the rationale before answering.'],['Translate to German: My name is Arthur'], ['Please answer the following question. What is the boiling point of Nitrogen?']]
|
| 8 |
+
|
| 9 |
+
print(f"Is CUDA available: {torch.cuda.is_available()}")
|
| 10 |
+
print(f"CUDA device: {torch.cuda.get_device_name(torch.cuda.current_device())}")
|
| 11 |
+
|
| 12 |
+
#pipe_biogpt = pipeline("text-generation", model="microsoft/BioGPT-Large", device="cuda:0", model_kwargs={"torch_dtype":torch.bfloat16})
|
| 13 |
+
pipe_flan_t5 = pipeline("text-generation", model="google/flan-t5-xxl", device="cuda:0", model_kwargs={"torch_dtype":torch.bfloat16})
|
| 14 |
+
#pipe_gpt2 = pipeline("text-generation", model="gpt2", device="cuda:0", model_kwargs={"torch_dtype":torch.bfloat16})
|
| 15 |
+
pipe_flan_ul2 = pipeline("text-generation", model="google/flan-ul2", device="cuda:0", model_kwargs={"torch_dtype":torch.bfloat16})
|
| 16 |
+
#pipe_galactica = pipeline("text-generation", model="facebook/galactica-1.3b", device="cuda:0", model_kwargs={"torch_dtype":torch.bfloat16})
|
| 17 |
+
|
| 18 |
+
title = "LLM vs LLM"
|
| 19 |
+
description = "**Disclaimer:** this demo was made for research purposes."
|
| 20 |
+
|
| 21 |
+
def inference(text):
|
| 22 |
+
#output_biogpt = pipe_biogpt(text, max_length=100)[0]["generated_text"]
|
| 23 |
+
output_flan_t5 = pipe_flan_t5(text, max_length=100)[0]["generated_text"]
|
| 24 |
+
#output_gpt2 = pipe_gpt2(text, max_length=100)[0]["generated_text"]
|
| 25 |
+
pipe_flan_ul2 = pipe_flan_t5(text, max_length=100)[0]["generated_text"]
|
| 26 |
+
#output_galactica = pipe_galactica(text, max_length=100)[0]["generated_text"]
|
| 27 |
+
return [
|
| 28 |
+
#output_biogpt,
|
| 29 |
+
output_flan_t5,
|
| 30 |
+
#output_gpt2,
|
| 31 |
+
pipe_flan_ul2,
|
| 32 |
+
#output_galactica
|
| 33 |
+
]
|
| 34 |
+
|
| 35 |
+
io = gr.Interface(
|
| 36 |
+
inference,
|
| 37 |
+
gr.Textbox(lines=3),
|
| 38 |
+
outputs=[
|
| 39 |
+
#gr.Textbox(lines=3, label="Microsoft: BioGPT-Large"),
|
| 40 |
+
gr.Textbox(lines=3, label="Google: FLAN-T5-XXL"),
|
| 41 |
+
#gr.Textbox(lines=3, label="GPT-2"),
|
| 42 |
+
gr.Textbox(lines=3, label="Google: FLAN-UL2"),
|
| 43 |
+
#gr.Textbox(lines=3, label="Facebook: Galactica 1.3B"),
|
| 44 |
+
],
|
| 45 |
+
title=title,
|
| 46 |
+
description=description,
|
| 47 |
+
examples=examples
|
| 48 |
+
)
|
| 49 |
+
io.launch()
|