Spaces:
Runtime error
Runtime error
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 | |