Spaces:
Runtime error
Runtime error
kaiserpister
commited on
Commit
•
de101e1
1
Parent(s):
a0f569f
Upload folder using huggingface_hub
Browse files- .cache/chat.json +1 -1
- __pycache__/app.cpython-311.pyc +0 -0
- app.py +51 -25
- venv/lib/python3.11/site-packages/gradio/launches.json +1 -1
.cache/chat.json
CHANGED
@@ -1 +1 @@
|
|
1 |
-
{"([{'role': 'system', 'content': 'You are an expert mathematician. You will be given a list of input and outputs to a function and your job is to guess the output of the function on an unknown input.\\n For example:\\n f(2) = 6\\n f(7) = 11\\n What is f(3)?\\n Answer: 7'}, {'role': 'user', 'content': 'f(76) = 5776\\nWhat is f(50)?\\nAnswer:'}], ('model', 'gpt-3.5-turbo'))": "2500"}
|
|
|
1 |
+
{"([{'role': 'system', 'content': 'You are an expert mathematician. You will be given a list of input and outputs to a function and your job is to guess the output of the function on an unknown input.\\n For example:\\n f(2) = 6\\n f(7) = 11\\n What is f(3)?\\n Answer: 7'}, {'role': 'user', 'content': 'f(76) = 5776\\nWhat is f(50)?\\nAnswer:'}], ('model', 'gpt-3.5-turbo'))": "2500", "([{'role': 'system', 'content': 'You are an expert mathematician. You will be given a list of input and outputs to a function and your job is to guess the output of the function on an unknown input. If you cannot determine the answer, respond with 0.\\n For example:\\n f(2) = 6\\n f(7) = 11\\n What is f(3)?\\n Answer: 7\\n \\n For example:\\n f(1) = 17\\n What is f(6)?\\n Answer: 0'}, {'role': 'user', 'content': 'f(18) = 324\\nWhat is f(20)?\\nAnswer:'}], ('model', 'gpt-3.5-turbo'))": "0", "([{'role': 'system', 'content': 'You are an expert mathematician. You will be given a list of input and outputs to a function and your job is to guess the output of the function on an unknown input. If you cannot determine the answer, respond with 0.\\n For example:\\n f(2) = 6\\n f(7) = 11\\n What is f(3)?\\n Answer: 7\\n \\n For example:\\n f(1) = 17\\n What is f(6)?\\n Answer: 0'}, {'role': 'user', 'content': 'f(2) = 8\\nWhat is f(16)?\\nAnswer:'}], ('model', 'gpt-3.5-turbo'))": "0", "([{'role': 'system', 'content': 'You are an expert mathematician. You will be given a list of input and outputs to a function and your job is to guess the output of the function on an unknown input. If you cannot determine the answer, respond with 0.\\n For example:\\n f(2) = 6\\n f(7) = 11\\n What is f(3)?\\n Answer: 7\\n \\n For example:\\n f(1) = 17\\n What is f(6)?\\n Answer: 0'}, {'role': 'user', 'content': 'f(27) = 19683\\nWhat is f(5)?\\nAnswer:'}], ('model', 'gpt-3.5-turbo'))": "0", "([{'role': 'system', 'content': 'You are an expert mathematician. You will be given a list of input and outputs to a function and your job is to guess the output of the function on an unknown input. If you cannot determine the answer, respond with 0.\\n For example:\\n f(2) = 6\\n f(7) = 11\\n What is f(3)?\\n Answer: 7\\n \\n For example:\\n f(1) = 17\\n What is f(6)?\\n Answer: 0'}, {'role': 'user', 'content': 'f(27) = 19683\\nf(3) = 27\\nWhat is f(5)?\\nAnswer:'}], ('model', 'gpt-3.5-turbo'))": "125"}
|
__pycache__/app.cpython-311.pyc
CHANGED
Binary files a/__pycache__/app.cpython-311.pyc and b/__pycache__/app.cpython-311.pyc differ
|
|
app.py
CHANGED
@@ -22,22 +22,15 @@ def sum_of_digits(n):
|
|
22 |
functions = [fib, square, cube, sum_of_digits]
|
23 |
|
24 |
|
25 |
-
MAX_INPUT_ANSWER_VALUE =
|
26 |
-
MAX_CLUE_VALUE =
|
27 |
-
available_numbers = set(range(MAX_CLUE_VALUE))
|
28 |
|
29 |
-
# SESSION VALUES
|
30 |
-
challenge = random.choice(functions)
|
31 |
-
ask = random.randint(1, MAX_INPUT_ANSWER_VALUE)
|
32 |
-
available_numbers.remove(ask)
|
33 |
-
clue = random.choice(list(available_numbers))
|
34 |
-
available_numbers.remove(clue)
|
35 |
|
36 |
-
def fn_to_str(x):
|
37 |
-
return f"f({x}) = {
|
38 |
|
39 |
|
40 |
-
def get_gpt_guess(clues, ask):
|
41 |
system_message = """You are an expert mathematician. You will be given a list of input and outputs to a function and your job is to guess the output of the function on an unknown input. If you cannot determine the answer, respond with 0.
|
42 |
For example:
|
43 |
f(2) = 6
|
@@ -51,7 +44,7 @@ def get_gpt_guess(clues, ask):
|
|
51 |
Answer: 0"""
|
52 |
|
53 |
|
54 |
-
user_message = "\n".join(map(fn_to_str, clues)) + f"\nWhat is f({ask})?\nAnswer:"
|
55 |
return chat([{"role": "system", "content": system_message}, {"role": "user", "content": user_message}], model=model)
|
56 |
|
57 |
def check_winner(gpt, human, answer):
|
@@ -65,14 +58,21 @@ def check_winner(gpt, human, answer):
|
|
65 |
|
66 |
|
67 |
with gr.Blocks() as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
guesses = gr.State([])
|
69 |
-
clues = gr.State([clue])
|
70 |
with gr.Row():
|
71 |
with gr.Column():
|
72 |
-
title_text = gr.Markdown(f"# Guess the function (faster than GPT)\n## What is f({ask})?")
|
73 |
|
74 |
with gr.Column():
|
75 |
-
clues_box = gr.Markdown(f"# Clues\n```\n{fn_to_str(clue)}\n```")
|
76 |
|
77 |
with gr.Row():
|
78 |
with gr.Column():
|
@@ -81,22 +81,23 @@ with gr.Blocks() as demo:
|
|
81 |
with gr.Column():
|
82 |
gpt_guess = gr.Textbox(label="GPT Guess", value="...")
|
83 |
btn = gr.Button("Submit")
|
|
|
84 |
|
85 |
-
def submit_guess(value, history, clue_values):
|
86 |
history.append(value)
|
87 |
|
88 |
try:
|
89 |
-
gpt_guess_value = int(get_gpt_guess(clue_values,
|
90 |
except Exception:
|
91 |
gpt_guess_value = 0
|
92 |
|
93 |
-
result = check_winner(gpt_guess_value, int(value),
|
94 |
|
95 |
-
|
96 |
-
|
97 |
|
98 |
-
clue_values.append(
|
99 |
-
clue_str = "\n".join(map(fn_to_str, clue_values))
|
100 |
return {
|
101 |
guesses: history,
|
102 |
history_box: ", ".join(history),
|
@@ -104,11 +105,36 @@ with gr.Blocks() as demo:
|
|
104 |
clues: clue_values,
|
105 |
title_text: title_text.value + result,
|
106 |
clues_box: f"# Clues\n```\n{clue_str}\n```",
|
|
|
|
|
|
|
107 |
}
|
108 |
|
109 |
btn.click(
|
110 |
submit_guess,
|
111 |
-
[guess, guesses, clues],
|
112 |
-
[guesses, history_box, gpt_guess, clues, title_text, clues_box],
|
113 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
demo.launch()
|
|
|
22 |
functions = [fib, square, cube, sum_of_digits]
|
23 |
|
24 |
|
25 |
+
MAX_INPUT_ANSWER_VALUE = 10
|
26 |
+
MAX_CLUE_VALUE = 20
|
|
|
27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
+
def fn_to_str(challenge_idx, x):
|
30 |
+
return f"f({x}) = {functions[challenge_idx](x)}"
|
31 |
|
32 |
|
33 |
+
def get_gpt_guess(fidx, clues, ask):
|
34 |
system_message = """You are an expert mathematician. You will be given a list of input and outputs to a function and your job is to guess the output of the function on an unknown input. If you cannot determine the answer, respond with 0.
|
35 |
For example:
|
36 |
f(2) = 6
|
|
|
44 |
Answer: 0"""
|
45 |
|
46 |
|
47 |
+
user_message = "\n".join(map(lambda x: fn_to_str(fidx, x), clues)) + f"\nWhat is f({ask})?\nAnswer:"
|
48 |
return chat([{"role": "system", "content": system_message}, {"role": "user", "content": user_message}], model=model)
|
49 |
|
50 |
def check_winner(gpt, human, answer):
|
|
|
58 |
|
59 |
|
60 |
with gr.Blocks() as demo:
|
61 |
+
# SESSION VALUES
|
62 |
+
ask = gr.State(lambda: random.randint(1, MAX_INPUT_ANSWER_VALUE))
|
63 |
+
clue = gr.State(random.choice(list(set(range(MAX_CLUE_VALUE)) - set([ask.value]))))
|
64 |
+
|
65 |
+
available_numbers = gr.State(set(range(MAX_CLUE_VALUE)) - set([ask.value, clue.value]))
|
66 |
+
challenge_idx = gr.State(random.randint(0, len(functions) - 1))
|
67 |
+
|
68 |
guesses = gr.State([])
|
69 |
+
clues = gr.State([clue.value])
|
70 |
with gr.Row():
|
71 |
with gr.Column():
|
72 |
+
title_text = gr.Markdown(f"# Guess the function (faster than GPT)\n## What is f({ask.value})?")
|
73 |
|
74 |
with gr.Column():
|
75 |
+
clues_box = gr.Markdown(f"# Clues\n```\n{fn_to_str(challenge_idx.value, clue.value)}\n```")
|
76 |
|
77 |
with gr.Row():
|
78 |
with gr.Column():
|
|
|
81 |
with gr.Column():
|
82 |
gpt_guess = gr.Textbox(label="GPT Guess", value="...")
|
83 |
btn = gr.Button("Submit")
|
84 |
+
rstbtn = gr.Button("Reset")
|
85 |
|
86 |
+
def submit_guess(value, history, clue_values, fidx, avail, _ask ):
|
87 |
history.append(value)
|
88 |
|
89 |
try:
|
90 |
+
gpt_guess_value = int(get_gpt_guess(fidx, clue_values, _ask))
|
91 |
except Exception:
|
92 |
gpt_guess_value = 0
|
93 |
|
94 |
+
result = check_winner(gpt_guess_value, int(value), functions[fidx](_ask))
|
95 |
|
96 |
+
_clue = random.choice(list(avail))
|
97 |
+
avail.remove(_clue)
|
98 |
|
99 |
+
clue_values.append(_clue)
|
100 |
+
clue_str = "\n".join(map(lambda x: fn_to_str(fidx, x), clue_values))
|
101 |
return {
|
102 |
guesses: history,
|
103 |
history_box: ", ".join(history),
|
|
|
105 |
clues: clue_values,
|
106 |
title_text: title_text.value + result,
|
107 |
clues_box: f"# Clues\n```\n{clue_str}\n```",
|
108 |
+
available_numbers: avail,
|
109 |
+
challenge_idx: fidx,
|
110 |
+
ask: _ask,
|
111 |
}
|
112 |
|
113 |
btn.click(
|
114 |
submit_guess,
|
115 |
+
[guess, guesses, clues, challenge_idx, available_numbers, ask],
|
116 |
+
[guesses, history_box, gpt_guess, clues, title_text, clues_box, available_numbers, challenge_idx, ask],
|
117 |
)
|
118 |
+
|
119 |
+
def reset():
|
120 |
+
_ask = random.randint(1, MAX_INPUT_ANSWER_VALUE)
|
121 |
+
_clue = random.choice(list(set(range(2, MAX_CLUE_VALUE)) - set([_ask])))
|
122 |
+
fidx = random.randint(0, len(functions) - 1)
|
123 |
+
clue_str = "\n".join(map(lambda x: fn_to_str(fidx, x), [_clue]))
|
124 |
+
return {
|
125 |
+
guesses: [],
|
126 |
+
history_box: "",
|
127 |
+
clues: [_clue],
|
128 |
+
title_text: f"# Guess the function (faster than GPT)\n## What is f({_ask})?",
|
129 |
+
clues_box: f"# Clues\n```\n{clue_str}\n```",
|
130 |
+
gpt_guess: "...",
|
131 |
+
ask: _ask,
|
132 |
+
clue: _clue,
|
133 |
+
available_numbers: set(range(MAX_CLUE_VALUE)) - set([_ask, _clue]),
|
134 |
+
challenge_idx: fidx,
|
135 |
+
}
|
136 |
+
|
137 |
+
rstbtn.click(reset, [], [ask, clue, available_numbers, challenge_idx, guesses, history_box, gpt_guess, clues, title_text, clues_box])
|
138 |
+
|
139 |
+
|
140 |
demo.launch()
|
venv/lib/python3.11/site-packages/gradio/launches.json
CHANGED
@@ -1 +1 @@
|
|
1 |
-
{"launches":
|
|
|
1 |
+
{"launches": 75}
|