Spaces:
Running
Running
Improved feedback for bad user input
Browse files
app.py
CHANGED
@@ -665,10 +665,10 @@ with gr.Blocks(
|
|
665 |
def token_selected(
|
666 |
meta: MetadataState,
|
667 |
key: str,
|
668 |
-
choice: int,
|
669 |
indices: list[int],
|
670 |
):
|
671 |
-
if choice < 0 or choice >= len(indices) or (token := indices[choice]) < 0:
|
672 |
raise gr.Error('Token not found')
|
673 |
|
674 |
tokens = meta.key.get('tokenizer.ggml.tokens', (-1, []))[1]
|
@@ -748,14 +748,16 @@ with gr.Blocks(
|
|
748 |
|
749 |
match key:
|
750 |
case 'tokenizer.ggml.scores' | 'tokenizer.ggml.token_type':
|
751 |
-
if choice
|
752 |
-
|
753 |
-
|
754 |
-
|
755 |
-
|
756 |
-
|
757 |
-
|
758 |
-
|
|
|
|
|
759 |
case _:
|
760 |
meta.key[key] = meta.add[key] = (typ, val)
|
761 |
|
|
|
665 |
def token_selected(
|
666 |
meta: MetadataState,
|
667 |
key: str,
|
668 |
+
choice: int | None,
|
669 |
indices: list[int],
|
670 |
):
|
671 |
+
if choice is None or choice < 0 or choice >= len(indices) or (token := indices[choice]) < 0:
|
672 |
raise gr.Error('Token not found')
|
673 |
|
674 |
tokens = meta.key.get('tokenizer.ggml.tokens', (-1, []))[1]
|
|
|
748 |
|
749 |
match key:
|
750 |
case 'tokenizer.ggml.scores' | 'tokenizer.ggml.token_type':
|
751 |
+
if choice is None or choice < 0 or choice >= len(indices) or (token := indices[choice]) < 0:
|
752 |
+
raise gr.Error('Token not found')
|
753 |
+
|
754 |
+
tok = meta.add.setdefault(key, (typ, {}))[1]
|
755 |
+
tok[str(token)] = val + 1 if key == 'tokenizer.ggml.token_type' else val
|
756 |
+
|
757 |
+
data = meta.key.setdefault(key, (typ, [0.0 if key == 'tokenizer.ggml.scores' else int(TokenType.NORMAL)] * len(meta.key.get('tokenizer.ggml.tokens', (-1, []))[1])))[1]
|
758 |
+
if data:
|
759 |
+
for k, v in tok.items():
|
760 |
+
data[int(k)] = v
|
761 |
case _:
|
762 |
meta.key[key] = meta.add[key] = (typ, val)
|
763 |
|