akoksal commited on
Commit
ee9feac
·
1 Parent(s): 2c3dc94

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +73 -10
app.py CHANGED
@@ -1,16 +1,26 @@
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  from transformers import AutoTokenizer, pipeline
3
- import torch
4
 
5
 
6
 
7
- tokenizer = AutoTokenizer.from_pretrained("akoksal/LongForm-OPT-2.7B")
8
- generate = pipeline('text-generation', model='akoksal/LongForm-OPT-2.7B', tokenizer=tokenizer)
9
 
10
 
11
  def predict(instruction, topp, max_length, temperature):
12
  if "[EOI]" not in instruction:
13
  instruction = instruction + " [EOI]"
 
14
  x = generate(instruction,
15
  do_sample=True,
16
  top_p=topp,
@@ -21,10 +31,63 @@ def predict(instruction, topp, max_length, temperature):
21
 
22
  return x[len(instruction):]
23
 
24
- iface = gr.Interface(fn=predict, inputs=["text",
25
- gr.inputs.Slider(0, 2, default=0.90, label="top_p"),
26
- gr.inputs.Slider(0, 512, default=64, label="max_length"),
27
- gr.inputs.Slider(0, 1, default=1, label="temperature")
28
- ],
29
- outputs="text")
30
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ examples = [
2
+ "Write an essay about meditation.",
3
+ "Give me 5 steps to clean my room.",
4
+ "How are the continents formed?",
5
+ "Prompt: A man draws a gun in a dark alley and asks for your wallet. You begrudgingly obey. He throws it on the ground, shoots it till it screeches, and turns to you; 'you are safe now'. Write a story about given prompt.",
6
+ "Write directions of a cooking recipe with these ingredients: chicken breast, carrots, green peas, celery, butter, onion, flour, salt, black pepper, celery seed, chicken broth, milk, unbaked pie crusts?",
7
+ "Schreiben Sie einen Blogbeitrag über die Vorteile des Lesens von Büchern.",
8
+ ]
9
+
10
+
11
  import gradio as gr
12
  from transformers import AutoTokenizer, pipeline
 
13
 
14
 
15
 
16
+ # tokenizer = AutoTokenizer.from_pretrained("akoksal/LongForm-OPT-2.7B")
17
+ # generate = pipeline('text-generation', model='akoksal/LongForm-OPT-2.7B', tokenizer=tokenizer)
18
 
19
 
20
  def predict(instruction, topp, max_length, temperature):
21
  if "[EOI]" not in instruction:
22
  instruction = instruction + " [EOI]"
23
+ return instruction
24
  x = generate(instruction,
25
  do_sample=True,
26
  top_p=topp,
 
31
 
32
  return x[len(instruction):]
33
 
34
+ def process_example(args):
35
+ for x in predict(args):
36
+ pass
37
+ return x
38
+
39
+
40
+ with gr.Blocks() as demo:
41
+ with gr.Column():
42
+ gr.Markdown(
43
+ """Hello"""
44
+ )
45
+ with gr.Row():
46
+ with gr.Column(scale=3):
47
+ instruction = gr.Textbox(placeholder="Enter your question here", label="Question", elem_id="q-input")
48
+ with gr.Box():
49
+ gr.Markdown("**Answer**")
50
+ output = gr.Markdown(elem_id="q-output")
51
+ submit = gr.Button("Generate", variant="primary")
52
+ gr.Examples(
53
+ examples=examples,
54
+ inputs=[instruction],
55
+ cache_examples=False,
56
+ fn=process_example,
57
+ outputs=[output],
58
+ )
59
+
60
+ with gr.Column(scale=1):
61
+ top_p = gr.Slider(
62
+ label="Top-p (nucleus sampling)",
63
+ value=0.90,
64
+ minimum=0.0,
65
+ maximum=1,
66
+ step=0.05,
67
+ interactive=True,
68
+ info="Higher values sample low-probability tokens",
69
+ )
70
+ max_length = gr.Slider(
71
+ label="Max length",
72
+ value=64,
73
+ minimum=1,
74
+ maximum=512,
75
+ step=4,
76
+ interactive=True,
77
+ info="The maximum length of the output",
78
+ )
79
+ temperature = gr.Slider(
80
+ label="Temperature",
81
+ value=1.0,
82
+ minimum=0.0,
83
+ maximum=2.0,
84
+ step=0.1,
85
+ interactive=True,
86
+ info="Higher values sample more diverse outputs",
87
+ )
88
+
89
+ submit.click(predict, inputs=[instruction, top_p, max_length, temperature], outputs=[output])
90
+
91
+
92
+ demo.queue(concurrency_count=4)
93
+ demo.launch()