Spaces:
Runtime error
Runtime error
File size: 3,531 Bytes
614d543 dfbce2c 6d4a32a dfbce2c 7fe9bd6 a88f931 614d543 7eee83c 614d543 dfbce2c 7fe9bd6 dfbce2c 614d543 7fe9bd6 614d543 7fe9bd6 614d543 dfbce2c 7fe9bd6 dfbce2c 7eee83c dfbce2c 7fe9bd6 dfbce2c a88f931 614d543 7fe9bd6 614d543 7eee83c 7fe9bd6 1532c35 7fe9bd6 7eee83c 614d543 1532c35 dfbce2c 1532c35 0e7f280 1532c35 dfbce2c 614d543 0e7f280 614d543 0e7f280 7eee83c 1532c35 614d543 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
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()
|