Spaces:
Sleeping
Sleeping
Ali Abid
commited on
Commit
·
d5968d4
1
Parent(s):
507fcd2
first commit
Browse files- README.md +13 -6
- requirements.txt +1 -0
- run.py +114 -0
- wordlist.json +152 -0
README.md
CHANGED
|
@@ -1,13 +1,20 @@
|
|
| 1 |
---
|
| 2 |
title: GPT Golf
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version: 3.0.
|
| 8 |
-
app_file:
|
| 9 |
pinned: false
|
| 10 |
license: gpl-3.0
|
| 11 |
---
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
title: GPT Golf
|
| 3 |
+
emoji: ⛳
|
| 4 |
+
colorFrom: red
|
| 5 |
+
colorTo: yellow
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 3.0.18b
|
| 8 |
+
app_file: run.py
|
| 9 |
pinned: false
|
| 10 |
license: gpl-3.0
|
| 11 |
---
|
| 12 |
|
| 13 |
+
# GPT Golf
|
| 14 |
+
|
| 15 |
+
How many turns will it take you to get GPT to say the target word?
|
| 16 |
+
Here are the rules of the game:
|
| 17 |
+
- Your goal is to get GPT to say a target word in as few turns as possible.
|
| 18 |
+
- Each turn, you add up to 5 words to its dialogue.
|
| 19 |
+
- When you click submit, your prompt will be added to the dialogue. Then GPT will also add to the dialogue.
|
| 20 |
+
- You can't say the target word, but as soon as GPT does, you win!
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
transformers
|
run.py
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import json
|
| 3 |
+
import random
|
| 4 |
+
from transformers import pipeline
|
| 5 |
+
|
| 6 |
+
generator = pipeline("text-generation", model="gpt2", max_length=60)
|
| 7 |
+
|
| 8 |
+
with open("wordlist.json") as wordlist_json:
|
| 9 |
+
wordlist = json.load(wordlist_json)
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def autocomplete(text):
|
| 13 |
+
end_text = " ".join(text.split(" ")[-30:-1])
|
| 14 |
+
generated_text = generator(
|
| 15 |
+
end_text, return_full_text=False, clean_up_tokenization_spaces=True
|
| 16 |
+
)[0]["generated_text"]
|
| 17 |
+
generated_text = generated_text.replace("\n", "")
|
| 18 |
+
return generated_text
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
with gr.Blocks() as demo:
|
| 22 |
+
gr.Markdown(
|
| 23 |
+
"""
|
| 24 |
+
# GPT Golf
|
| 25 |
+
|
| 26 |
+
How many turns will it take you to get GPT to say the target word?
|
| 27 |
+
Here are the rules of the game:
|
| 28 |
+
- Your goal is to get GPT to say a target word in as few turns as possible.
|
| 29 |
+
- Each turn, you add up to 5 words to its dialogue.
|
| 30 |
+
- When you click submit, your prompt will be added to the dialogue. Then GPT will also add to the dialogue.
|
| 31 |
+
- You can't say the target word, but as soon as GPT does, you win!
|
| 32 |
+
"""
|
| 33 |
+
)
|
| 34 |
+
error_box = gr.Textbox(label="Error", elem_id="error", visible=False)
|
| 35 |
+
dialogue_var = gr.Variable(value=[])
|
| 36 |
+
|
| 37 |
+
start_btn = gr.Button("Start", variant="primary")
|
| 38 |
+
with gr.Column(visible=False) as game:
|
| 39 |
+
with gr.Row() as stats:
|
| 40 |
+
target_word_box = gr.Textbox(
|
| 41 |
+
label="Target Word", elem_id="target", interactive=False
|
| 42 |
+
)
|
| 43 |
+
num_turns_box = gr.Number(0, label="# of Turns so Far", elem_id="num_turns")
|
| 44 |
+
dialogue_box = gr.HighlightedText(label="Dialogue")
|
| 45 |
+
with gr.Column() as prompt_set:
|
| 46 |
+
prompt_box = gr.Textbox(label="Prompt", placeholder="Enter Next 5 Words...")
|
| 47 |
+
submit_btn = gr.Button("Submit").style(full_width=True)
|
| 48 |
+
win = gr.HTML(
|
| 49 |
+
"<div style='width: 100%; padding: 3rem; font-size: 4rem; color: green; text-align: center; font-weight: bold'>You Won!</div>",
|
| 50 |
+
visible=False,
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
def start_game():
|
| 54 |
+
return {
|
| 55 |
+
start_btn: gr.update(visible=False),
|
| 56 |
+
game: gr.update(visible=True),
|
| 57 |
+
target_word_box: random.choice(wordlist),
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
start_btn.click(start_game, inputs=None, outputs=[start_btn, game, target_word_box])
|
| 61 |
+
|
| 62 |
+
def submit(prompt, target_word, dialogue, num_turns):
|
| 63 |
+
if len(prompt.split(" ")) > 5:
|
| 64 |
+
return {
|
| 65 |
+
error_box: gr.update(
|
| 66 |
+
visible=True, value="Prompt must be a maximum of 5 words!"
|
| 67 |
+
)
|
| 68 |
+
}
|
| 69 |
+
if target_word in prompt:
|
| 70 |
+
return {
|
| 71 |
+
error_box: gr.update(
|
| 72 |
+
visible=True, value="You can't use the target word in the prompt!"
|
| 73 |
+
)
|
| 74 |
+
}
|
| 75 |
+
dialogue.append(prompt)
|
| 76 |
+
response = autocomplete(" ".join(dialogue))
|
| 77 |
+
dialogue.append(response)
|
| 78 |
+
labeled_dialogue = [
|
| 79 |
+
(text, None if i % 2 == 0 else "gpt") for i, text in enumerate(dialogue)
|
| 80 |
+
]
|
| 81 |
+
if target_word in response:
|
| 82 |
+
return {
|
| 83 |
+
dialogue_box: labeled_dialogue,
|
| 84 |
+
prompt_set: gr.update(visible=False),
|
| 85 |
+
win: gr.update(visible=True),
|
| 86 |
+
num_turns_box: num_turns + 1,
|
| 87 |
+
dialogue_var: dialogue,
|
| 88 |
+
error_box: gr.update(visible=False),
|
| 89 |
+
}
|
| 90 |
+
else:
|
| 91 |
+
return {
|
| 92 |
+
dialogue_box: labeled_dialogue,
|
| 93 |
+
prompt_box: "",
|
| 94 |
+
num_turns_box: num_turns + 1,
|
| 95 |
+
dialogue_var: dialogue,
|
| 96 |
+
error_box: gr.update(visible=False),
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
submit_btn.click(
|
| 100 |
+
submit,
|
| 101 |
+
inputs=[prompt_box, target_word_box, dialogue_var, num_turns_box],
|
| 102 |
+
outputs=[
|
| 103 |
+
dialogue_var,
|
| 104 |
+
dialogue_box,
|
| 105 |
+
prompt_box,
|
| 106 |
+
num_turns_box,
|
| 107 |
+
error_box,
|
| 108 |
+
prompt_set,
|
| 109 |
+
win,
|
| 110 |
+
],
|
| 111 |
+
)
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
demo.launch()
|
wordlist.json
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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10 |
+
"north",
|
| 11 |
+
"business",
|
| 12 |
+
"queen",
|
| 13 |
+
"rain",
|
| 14 |
+
"basket",
|
| 15 |
+
"plant",
|
| 16 |
+
"stocking",
|
| 17 |
+
"hope",
|
| 18 |
+
"horse",
|
| 19 |
+
"stranger",
|
| 20 |
+
"mistake",
|
| 21 |
+
"picture",
|
| 22 |
+
"insurance",
|
| 23 |
+
"question",
|
| 24 |
+
"song",
|
| 25 |
+
"cart",
|
| 26 |
+
"month",
|
| 27 |
+
"sun",
|
| 28 |
+
"tiger",
|
| 29 |
+
"walk",
|
| 30 |
+
"tin",
|
| 31 |
+
"regret",
|
| 32 |
+
"system",
|
| 33 |
+
"person",
|
| 34 |
+
"pancake",
|
| 35 |
+
"mom",
|
| 36 |
+
"branch",
|
| 37 |
+
"wound",
|
| 38 |
+
"committee",
|
| 39 |
+
"line",
|
| 40 |
+
"yak",
|
| 41 |
+
"kettle",
|
| 42 |
+
"veil",
|
| 43 |
+
"jail",
|
| 44 |
+
"scene",
|
| 45 |
+
"orange",
|
| 46 |
+
"cactus",
|
| 47 |
+
"trip",
|
| 48 |
+
"blow",
|
| 49 |
+
"sister",
|
| 50 |
+
"activity",
|
| 51 |
+
"books",
|
| 52 |
+
"umbrella",
|
| 53 |
+
"invention",
|
| 54 |
+
"apparel",
|
| 55 |
+
"pocket",
|
| 56 |
+
"temper",
|
| 57 |
+
"power",
|
| 58 |
+
"corn",
|
| 59 |
+
"wrist",
|
| 60 |
+
"sink",
|
| 61 |
+
"rock",
|
| 62 |
+
"balance",
|
| 63 |
+
"quiver",
|
| 64 |
+
"sense",
|
| 65 |
+
"payment",
|
| 66 |
+
"bait",
|
| 67 |
+
"meeting",
|
| 68 |
+
"fang",
|
| 69 |
+
"play",
|
| 70 |
+
"furniture",
|
| 71 |
+
"playground",
|
| 72 |
+
"pollution",
|
| 73 |
+
"bubble",
|
| 74 |
+
"sort",
|
| 75 |
+
"pear",
|
| 76 |
+
"straw",
|
| 77 |
+
"class",
|
| 78 |
+
"friends",
|
| 79 |
+
"memory",
|
| 80 |
+
"governor",
|
| 81 |
+
"rice",
|
| 82 |
+
"waste",
|
| 83 |
+
"alarm",
|
| 84 |
+
"man",
|
| 85 |
+
"sidewalk",
|
| 86 |
+
"powder",
|
| 87 |
+
"theory",
|
| 88 |
+
"zephyr",
|
| 89 |
+
"sugar",
|
| 90 |
+
"quince",
|
| 91 |
+
"plane",
|
| 92 |
+
"friend",
|
| 93 |
+
"tramp",
|
| 94 |
+
"eye",
|
| 95 |
+
"exchange",
|
| 96 |
+
"force",
|
| 97 |
+
"hate",
|
| 98 |
+
"cows",
|
| 99 |
+
"field",
|
| 100 |
+
"oatmeal",
|
| 101 |
+
"degree",
|
| 102 |
+
"duck",
|
| 103 |
+
"creator",
|
| 104 |
+
"weight",
|
| 105 |
+
"tongue",
|
| 106 |
+
"note",
|
| 107 |
+
"stove",
|
| 108 |
+
"downtown",
|
| 109 |
+
"trade",
|
| 110 |
+
"stem",
|
| 111 |
+
"magic",
|
| 112 |
+
"fireman",
|
| 113 |
+
"thing",
|
| 114 |
+
"anger",
|
| 115 |
+
"lunchroom",
|
| 116 |
+
"scarecrow",
|
| 117 |
+
"jellyfish",
|
| 118 |
+
"mind",
|
| 119 |
+
"soup",
|
| 120 |
+
"structure",
|
| 121 |
+
"cattle",
|
| 122 |
+
"form",
|
| 123 |
+
"slope",
|
| 124 |
+
"airport",
|
| 125 |
+
"talk",
|
| 126 |
+
"camp",
|
| 127 |
+
"acoustics",
|
| 128 |
+
"crime",
|
| 129 |
+
"tail",
|
| 130 |
+
"order",
|
| 131 |
+
"brick",
|
| 132 |
+
"level",
|
| 133 |
+
"quill",
|
| 134 |
+
"cow",
|
| 135 |
+
"leg",
|
| 136 |
+
"language",
|
| 137 |
+
"bomb",
|
| 138 |
+
"land",
|
| 139 |
+
"recess",
|
| 140 |
+
"swim",
|
| 141 |
+
"limit",
|
| 142 |
+
"quiet",
|
| 143 |
+
"partner",
|
| 144 |
+
"store",
|
| 145 |
+
"fear",
|
| 146 |
+
"cover",
|
| 147 |
+
"sticks",
|
| 148 |
+
"scent",
|
| 149 |
+
"thread",
|
| 150 |
+
"teaching",
|
| 151 |
+
"transport"
|
| 152 |
+
]
|