Spaces:
Runtime error
Runtime error
import gradio as gr | |
from transformers import T5Tokenizer, T5ForConditionalGeneration | |
tokenizer = T5Tokenizer.from_pretrained("google/flan-t5-base") | |
model = T5ForConditionalGeneration.from_pretrained("google/flan-t5-base") | |
def get_examples (): | |
return [ | |
["Peter goes to the store to buy a soda. The soda costs $.25 an ounce. \ | |
He brought $2 with him and leaves with $.50. How many ounces of soda did he buy?", | |
"How much did Peter spend on soda? ** He spend $1.5 on soda because 2 - .5 = <<2-.5=1.5>>1.5 \ | |
How many ounces of soda did Peter buy? ** He bought 6 ounces of soda because 1.5 / .25 = <<6=6>>6 #### 6" | |
], | |
["Krystian works in the library. He borrows an average of 40 books every day. \ | |
Every Friday, his number of borrowed books is about 40% higher than the daily average. How many books does he borrow in a week if the library is open from Monday to Friday?" | |
,"How many books does Krystian borrow on Friday? ** The number of books borrowed \ | |
on Friday is higher by 40 * 40/100 = <<40*40/100=16>>16 books. How many books does Krystian borrow in a week? ** There are 5 days from Monday to Friday inclusive, so Krystian borrows an average of 5 * 40 = <<5*40=200>>200 books during that time. How many books does Krystian borrow in a week? ** With Friday's increase in borrowings, during one week Krystian borrows 200 + 16 = <<200+16=216>>216 books."] | |
] | |
def text2text(input_text): | |
input_ids = tokenizer(input_text, return_tensors="pt").input_ids | |
outputs = model.generate(input_ids, max_length=40) | |
return tokenizer.decode(outputs[0]) | |
textin = gr.Textbox() | |
examples = gr.Examples(examples=get_examples(), inputs=[textin]) | |
iface = gr.Interface(fn=text2text, inputs=[textin, examples], outputs="text") | |
iface.launch() |