marksverdhei
Make game replayable
7fe9bd6
import gradio as gr
from src import reducer
from src.constants import MAX_ATTEMPTS
from src.shared import INITIAL_STATE
from src.utils import get_current_lm_guess_str
def build_demo():
"""
Builds and returns the gradio app interface
"""
with gr.Blocks() as demo:
with gr.Row():
gr.Markdown("<h1><center>Can you beat a language model?</center></h1>")
with gr.Row():
gr.Markdown(
"Can you beat language models at their own game?\n"
"In this game you're pitted against a language model in the task of, you guessed it, laungage modelling.\n"
"Your task is to predict the next word given the previous sequence. You will get 3 attempts to guess.\n"
"The one with the fewest guesses for a given word gets a point."
)
with gr.Row():
prompt_text = gr.Textbox(
value=INITIAL_STATE.prompt_text,
label="Context",
interactive=False,
)
with gr.Row():
with gr.Column():
player_points = gr.Number(label="your points", interactive=False, value=INITIAL_STATE.player_points)
with gr.Column():
lm_points = gr.Number(label="LM points", interactive=False, value=INITIAL_STATE.lm_points)
with gr.Row():
with gr.Column():
remaining_attempts = gr.Number(
value=INITIAL_STATE.remaining_attempts,
label="Remaining attempts",
precision=0,
interactive=False,
)
current_guesses = gr.Textbox(label="Your guesses", value=INITIAL_STATE.current_guesses)
with gr.Column():
lm_guesses = gr.Textbox(
label="LM guesses", value=get_current_lm_guess_str(0, remaining_attempts=MAX_ATTEMPTS)
)
with gr.Row():
with gr.Column():
guess_field = gr.Textbox(label="", value=INITIAL_STATE.guess_field)
guess_button = gr.Button(value=INITIAL_STATE.button_label)
with gr.Row():
bottom_html = gr.HTML(value=INITIAL_STATE.bottom_html)
with gr.Row():
word_number = gr.Number(label="Word no.", interactive=False, precision=0, value=INITIAL_STATE.word_number)
guess_button.click(
reducer.handle_guess,
inputs=[
prompt_text,
player_points,
lm_points,
current_guesses,
lm_guesses,
remaining_attempts,
guess_field,
guess_button,
bottom_html,
word_number,
],
outputs=[
prompt_text,
player_points,
lm_points,
current_guesses,
lm_guesses,
remaining_attempts,
guess_field,
guess_button,
bottom_html,
word_number,
],
)
return demo
def wip_sign():
with gr.Blocks() as demo:
gr.Markdown("<h1><center>Can you beat a language model?</center></h1>")
with gr.Row():
gr.Markdown("<h1><center>β›”πŸ‘·β€β™‚οΈ Work in progress, come back later </center></h1>")
return demo
def get_demo(wip=False):
if wip:
return wip_sign()
else:
return build_demo()