muhtasham commited on
Commit
3f53aa9
1 Parent(s): f2d8fd3

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +74 -0
app.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ demo = gr.Blocks()
4
+
5
+ #'huggingface/EleutherAI/gpt-neox-20b'
6
+
7
+ name_list = ['huggingface/facebook/opt-13b', 'huggingface/bigscience/T0pp', 'huggingface/EleutherAI/gpt-j-6B', 'huggingface/gpt2-xl', 'huggingface/EleutherAI/gpt-neo-2.7B']
8
+
9
+ examples = [#zero-shot
10
+ ["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?\nA: The answer (arabic numerals) is "],
11
+ #zero-shot-CoT
12
+ ["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?\nA: Let’s think step by step."],
13
+ #few-shot
14
+ ["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?\nA: The answer is 11.\nQ: 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?\nA:"],
15
+ #few-shot-CoT
16
+ ["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?\nA: Roger started with 5 balls. 2 cans of 3 tennis balls each is 6 tennis balls. 5 + 6 = 11. The answer is 11.\nQ: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?\nA:"],
17
+ ]
18
+
19
+ #examples from Figure 1 of the paper
20
+
21
+ def calculator(num1, operation, num2):
22
+ if operation == "add":
23
+ return num1 + num2
24
+ elif operation == "subtract":
25
+ return num1 - num2
26
+ elif operation == "multiply":
27
+ return num1 * num2
28
+ elif operation == "divide":
29
+ return num1 / num2
30
+
31
+ def complete_with_gpt(text):
32
+ interfaces = [gr.Interface.load(name) for name in name_list]
33
+ return [interface(text) for interface in interfaces]
34
+
35
+ def set_example(example: list) -> dict:
36
+ return gr.Textbox.update(value=example[0])
37
+
38
+ with gr.Blocks() as demo:
39
+ gr.Markdown(
40
+ """
41
+ # Let’s think step by step Is all you need ?
42
+ """
43
+ )
44
+ with gr.Box():
45
+ with gr.Row():
46
+ with gr.Column():
47
+ input_text = gr.Textbox(label = "Write your riddle here", placeholder="Type here the riddles to see if LM can solve the questions", lines=4)
48
+ with gr.Row():
49
+ btn = gr.Button("Laguage model think brrr")
50
+
51
+ example_text = gr.Dataset(components=[input_text], samples=examples)
52
+ example_text.click(fn=set_example,
53
+ inputs = example_text,
54
+ outputs= example_text.components)
55
+
56
+ btn.click(complete_with_gpt, inputs = input_text, outputs = [gr.Textbox(label=name_list[_], lines=4) for _ in range(len(name_list))])
57
+
58
+ with gr.Column():
59
+ num1 = gr.Number(placeholder="Type here the first number", lines=1)
60
+ num2 = gr.Number(placeholder="Type here the second number", lines=1)
61
+ operation = gr.Dropdown(["add", "subtract", "multiply", "divide"], placeholder="Type here the operation", lines=1)
62
+ with gr.Row():
63
+ calculate = gr.Button("Calculate")
64
+ with gr.Column():
65
+ calculate.click(calculator, inputs = [num1, operation, num2], outputs = gr.Textbox(label="Result", lines=1))
66
+
67
+
68
+ gr.Markdown(
69
+ """
70
+ <p style='text-align: center'><a href='https://arxiv.org/abs/2205.11916' target='_blank'>Large Language Models are Zero-Shot Reasoners</a> | <a href='https://github.com/kojima-takeshi188/zero_shot_cot target='_blank'>Github Repo</a></p>
71
+ """
72
+ )
73
+
74
+ demo.launch()