Spaces:
Runtime error
Runtime error
Create app.py
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 |
+
import torch
|
8 |
+
print(f"Is CUDA available: {torch.cuda.is_available()}")
|
9 |
+
print(f"CUDA device: {torch.cuda.get_device_name(torch.cuda.current_device())}")
|
10 |
+
|
11 |
+
pipe_flan = pipeline("text2text-generation", model="ybelkada/flan-ul2", model_kwargs={"load_in_8bit":True, "device_map": "auto"})
|
12 |
+
pipe_vanilla = pipeline("text2text-generation", model="t5-large", device="cuda:0", model_kwargs={"torch_dtype":torch.bfloat16})
|
13 |
+
|
14 |
+
examples = [
|
15 |
+
["Please answer to the following question. Who is going to be the next Ballon d'or?"],
|
16 |
+
["Q: Can Barack Obama have a conversation with George Washington? Give the rationale before answering."],
|
17 |
+
["Summarize the following text: Peter and Elizabeth took a taxi to attend the night party in the city. While in the party, Elizabeth collapsed and was rushed to the hospital. Since she was diagnosed with a brain injury, the doctor told Peter to stay besides her until she gets well. Therefore, Peter stayed with her at the hospital for 3 days without leaving."],
|
18 |
+
["Please answer the following question: What is the boiling point of water?"],
|
19 |
+
["Answer the following question by detailing your reasoning: Are Pokemons alive?"],
|
20 |
+
["Translate to German: How old are you?"],
|
21 |
+
["Generate a cooking recipe to make bolognese pasta:"],
|
22 |
+
["Answer the following yes/no question by reasoning step-by-step. Can you write a whole Haiku in a single tweet?"],
|
23 |
+
["Premise: At my age you will probably have learnt one lesson. Hypothesis: It's not certain how many lessons you'll learn by your thirties. Does the premise entail the hypothesis?"],
|
24 |
+
["Answer the following question by reasoning step by step. The cafeteria had 23 apples. If they used 20 for lunch and bought 6 more, how many apples do they have?"],
|
25 |
+
["""Q: Roger has 5 tennis balls. He buys 2 more cans of tennis balls. Each can has 3 tennis balls. How many tennis balls does he have now?
|
26 |
+
A: Roger started with 5 balls. 2 cans of 3 tennis balls each is 6 tennis balls. 5 + 6 = 11. The answer is 11.
|
27 |
+
Q: A juggler can juggle 16 balls. Half of the balls are golf balls, and half of the golf balls are blue. How many blue golf balls are there?"""]
|
28 |
+
]
|
29 |
+
|
30 |
+
title = "Flan UL2 and Vanilla T5"
|
31 |
+
description = "This demo compares [T5-large](https://huggingface.co/t5-large) and [Flan-UL2](https://huggingface.co/google/flan-ul2). Note that T5 expects a very specific format of the prompts, so the examples below are not necessarily the best prompts to compare."
|
32 |
+
|
33 |
+
def inference(text):
|
34 |
+
output_flan = pipe_flan(text, max_length=100)[0]["generated_text"]
|
35 |
+
output_vanilla = pipe_vanilla(text, max_length=100)[0]["generated_text"]
|
36 |
+
return [output_flan, output_vanilla]
|
37 |
+
|
38 |
+
io = gr.Interface(
|
39 |
+
inference,
|
40 |
+
gr.Textbox(lines=3),
|
41 |
+
outputs=[
|
42 |
+
gr.Textbox(lines=3, label="Flan T5"),
|
43 |
+
gr.Textbox(lines=3, label="T5")
|
44 |
+
],
|
45 |
+
title=title,
|
46 |
+
description=description,
|
47 |
+
examples=examples
|
48 |
+
)
|
49 |
+
io.launch()
|