Spaces:
Runtime error
Runtime error
File size: 2,037 Bytes
1532c35 a88f931 7fe9bd6 6d4a32a 7fe9bd6 09c334f 1532c35 7fe9bd6 1532c35 a88f931 1532c35 09c334f a88f931 1532c35 |
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 |
import logging
from transformers import PreTrainedTokenizer
from src.constants import MAX_ATTEMPTS
from src.constants import STARTING_INDEX
from src.params import ReducerParams
from src.shared import all_tokens
from src.shared import tokenizer
from src.utils import get_current_prompt_text
logger = logging.getLogger(__name__)
def get_current_text(params: ReducerParams, tokenizer: PreTrainedTokenizer):
return tokenizer.decode(all_tokens[: params.word_number])
def handle_player_win(params: ReducerParams) -> ReducerParams:
# TODO: point system
points = 1
params.player_points += points
params.button_label = "Next word"
params.bottom_html = f"Player gets {points} point!"
return params
def handle_lm_win(params: ReducerParams) -> ReducerParams:
points = 1
params.lm_points += points
params.button_label = "Next word"
params.bottom_html = f"GPT2 gets {points} point!"
return params
def handle_out_of_attempts(params: ReducerParams) -> ReducerParams:
params.button_label = "Next word"
params.bottom_html = f"Out of attempts. No one gets points! The correct word was: {tokenizer.decode(all_tokens[STARTING_INDEX + params.word_number])}"
return params
def handle_tie(params: ReducerParams) -> ReducerParams:
params.button_label = "Next word"
params.bottom_html = "TIE! No one gets points!"
return params
def handle_both_wrong(params: ReducerParams) -> ReducerParams:
params.bottom_html = f"That was not it... {params.remaining_attempts} attempts left"
return params
def handle_no_input(params: ReducerParams) -> ReducerParams:
params.bottom_html = "Please write something"
return params
def handle_next_word(params: ReducerParams) -> ReducerParams:
params.word_number += 1
params.button_label = "Guess!"
params.bottom_html = ""
params.prompt_text = get_current_prompt_text(params.word_number)
params.current_guesses = ""
params.remaining_attempts = MAX_ATTEMPTS
params.guess_field = ""
return params
|