Spaces:
Sleeping
Sleeping
Update app.py
Browse files357 unmodified lines35835936036136236336436536636736836912 unmodified lines382383384385386387388357 unmodified lines# Slice by the tokenized input length, never by fragile string removal.new_token_ids = generated[0, input_length:]completion = TOKENIZER.decode(new_token_ids,skip_special_tokens=True,clean_up_tokenization_spaces=False,)was_stopped = stop_event.is_set()if not completion:completion = ("(Generation stopped before visible text was produced.)"12 unmodified linesif was_stopped:notes.append("stop signal received")note_text = " 路 " + " 路 ".join(notes) if notes else ""state_word = "STOPPED" if was_stopped else "COMPLETE"progress(1.0, desc="Completion ready")return (chat_history,357 unmodified lines35835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939012 unmodified lines403404405406407408409410411412413414415416417418419420421422423424357 unmodified lines# Slice by the tokenized input length, never by fragile string removal.new_token_ids = generated[0, input_length:]generated_token_count = int(new_token_ids.numel())completion = TOKENIZER.decode(new_token_ids,skip_special_tokens=True,clean_up_tokenization_spaces=False,)was_stopped = stop_event.is_set()# Determine whether generation ended on EOS or reached its token ceiling.eos_ids = ({int(x) for x in eos_id}if isinstance(eos_id, (list, tuple, set))else ({int(eos_id)} if eos_id is not None else set()))ended_with_eos = (generated_token_count > 0and int(new_token_ids[-1]) in eos_ids)hit_token_limit = (generated_token_count >= actual_new_tokensand not ended_with_eosand not was_stopped)if not completion:completion = ("(Generation stopped before visible text was produced.)"12 unmodified linesif was_stopped:notes.append("stop signal received")note_text = " 路 " + " 路 ".join(notes) if notes else ""#state_word = "STOPPED" if was_stopped else "COMPLETE"if was_stopped:state_word = "STOPPED"elif hit_token_limit:state_word = "TOKEN LIMIT REACHED"else:state_word = "COMPLETE"notes.append(f"generated {generated_token_count} tokens")if hit_token_limit:notes.append("generation reached its token ceiling; output may be truncated")elif ended_with_eos:notes.append("model emitted EOS")else:notes.append("ended before the token ceiling")progress(1.0, desc="Completion ready")return (chat_history,
app.py+37-1