felixz commited on
Commit
e0a0f30
·
1 Parent(s): 6120c47

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -4
app.py CHANGED
@@ -4,15 +4,28 @@ from transformers import T5Tokenizer, T5ForConditionalGeneration
4
  tokenizer = T5Tokenizer.from_pretrained("google/flan-t5-base")
5
  model = T5ForConditionalGeneration.from_pretrained("google/flan-t5-base")
6
 
7
- input_text = "translate English to German: How old are you?"
8
 
9
-
10
- def greet(input_text):
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  input_ids = tokenizer(input_text, return_tensors="pt").input_ids
12
 
13
  outputs = model.generate(input_ids, max_length=40)
14
  return tokenizer.decode(outputs[0])
15
 
 
16
 
17
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
18
  iface.launch()
 
4
  tokenizer = T5Tokenizer.from_pretrained("google/flan-t5-base")
5
  model = T5ForConditionalGeneration.from_pretrained("google/flan-t5-base")
6
 
 
7
 
8
+ def get_examples ():
9
+ return [
10
+ ["Peter goes to the store to buy a soda. The soda costs $.25 an ounce. \
11
+ He brought $2 with him and leaves with $.50. How many ounces of soda did he buy?",
12
+ "How much did Peter spend on soda? ** He spend $1.5 on soda because 2 - .5 = <<2-.5=1.5>>1.5 \
13
+ How many ounces of soda did Peter buy? ** He bought 6 ounces of soda because 1.5 / .25 = <<6=6>>6 #### 6"
14
+ ],
15
+ ["Krystian works in the library. He borrows an average of 40 books every day. \
16
+ 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?"
17
+ ,"How many books does Krystian borrow on Friday? ** The number of books borrowed \
18
+ 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."]
19
+ ]
20
+
21
+
22
+ def text2text(input_text):
23
  input_ids = tokenizer(input_text, return_tensors="pt").input_ids
24
 
25
  outputs = model.generate(input_ids, max_length=40)
26
  return tokenizer.decode(outputs[0])
27
 
28
+ textin = gr.Textbox()
29
 
30
+ iface = gr.Interface(fn=text2text, inputs=[textin], outputs="text", examples=gr.Examples(examples=get_examples(), inputs=[textin]))
31
  iface.launch()