micole66 commited on
Commit
e0bc5de
1 Parent(s): 89878c1

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
2
+
3
+ def get_pipe(name):
4
+ tokenizer = AutoTokenizer.from_pretrained(name)
5
+ model = AutoModelForSeq2SeqLM.from_pretrained(name)
6
+ pipe = pipeline(
7
+ "summarization", model=model, tokenizer=tokenizer, framework="pt"
8
+ )
9
+ return pipe
10
+ model_names = ['bigscience/T0_3B'] #, 'bigscience/T0p', 'bigscience/T0pp']
11
+ #model_names = ['bigscience/T0_3B','bigscience/T0'] #, 'bigscience/T0p', 'bigscience/T0pp']
12
+ pipes = [get_pipe(name) for name in model_names]
13
+ def _fn(text, do_sample, min_length, max_length, temperature, top_p, pipe):
14
+ out = pipe(
15
+ text,
16
+ do_sample=do_sample,
17
+ min_length=min_length,
18
+ max_length=max_length,
19
+ temperature=temperature,
20
+ top_p=top_p,
21
+ truncation=True,
22
+ )
23
+ return out[0]["summary_text"]
24
+ def fn(*args):
25
+ return [_fn(*args, pipe=pipe) for pipe in pipes]
26
+ import gradio as gr
27
+ interface = gr.Interface(
28
+ fn,
29
+ inputs=[
30
+ gr.inputs.Textbox(lines=10, label="input text"),
31
+ gr.inputs.Checkbox(label="do_sample", default=True),
32
+ gr.inputs.Slider(1, 128, step=1, default=64, label="min_length"),
33
+ gr.inputs.Slider(1, 128, step=1, default=64, label="max_length"),
34
+ gr.inputs.Slider(0.0, 1.0, step=0.1, default=1, label="temperature"),
35
+ gr.inputs.Slider(0.0, 1.0, step=0.1, default=1, label="top_p"),
36
+ ],
37
+ outputs=[
38
+ gr.outputs.Textbox(label=f"output by {name}") for name in model_names
39
+ ],
40
+ #examples=[[ex] for ex in examples],
41
+ title="T0 playground",
42
+ description="""
43
+ This is a playground for playing around with T0 models.
44
+ See https://huggingface.co/bigscience/T0 for more details
45
+ """,
46
+ )
47
+ interface.launch()