Spaces:
Running on Zero
Running on Zero
Upload app.py
Browse files
app.py
CHANGED
|
@@ -39,8 +39,9 @@ def predict(prompt, dark_mode):
|
|
| 39 |
normal_color = "white" if dark_mode else "black"
|
| 40 |
|
| 41 |
for token, score in zip(first_beam_tokens, first_beam_scores):
|
| 42 |
-
#
|
| 43 |
-
|
|
|
|
| 44 |
|
| 45 |
if score < 0.6:
|
| 46 |
color = "red"
|
|
@@ -61,7 +62,9 @@ def predict(prompt, dark_mode):
|
|
| 61 |
|
| 62 |
detail_output = f'<table style="{detail_table_style}"><thead><tr><th style="{th_style}">Token</th><th style="{th_style}">Score</th></tr></thead><tbody>'
|
| 63 |
for token, score in zip(first_beam_tokens, first_beam_scores):
|
| 64 |
-
|
|
|
|
|
|
|
| 65 |
|
| 66 |
if score < 0.6:
|
| 67 |
color = "red"
|
|
@@ -78,8 +81,12 @@ def predict(prompt, dark_mode):
|
|
| 78 |
|
| 79 |
# Gradio Interface
|
| 80 |
with gr.Blocks() as demo:
|
| 81 |
-
gr.Markdown("#
|
| 82 |
-
gr.Markdown(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
with gr.Column():
|
| 85 |
prompt_input = gr.Textbox(label="Prompt", placeholder="Enter your prompt here...", lines=3)
|
|
|
|
| 39 |
normal_color = "white" if dark_mode else "black"
|
| 40 |
|
| 41 |
for token, score in zip(first_beam_tokens, first_beam_scores):
|
| 42 |
+
# Robustly replace SentencePiece space characters, literal underscores,
|
| 43 |
+
# and non-breaking spaces with regular spaces.
|
| 44 |
+
display_token = token.replace('▁', ' ').replace('_', ' ').replace(' ', ' ')
|
| 45 |
|
| 46 |
if score < 0.6:
|
| 47 |
color = "red"
|
|
|
|
| 62 |
|
| 63 |
detail_output = f'<table style="{detail_table_style}"><thead><tr><th style="{th_style}">Token</th><th style="{th_style}">Score</th></tr></thead><tbody>'
|
| 64 |
for token, score in zip(first_beam_tokens, first_beam_scores):
|
| 65 |
+
# Robustly replace SentencePiece space characters, literal underscores,
|
| 66 |
+
# and non-breaking spaces with regular spaces.
|
| 67 |
+
display_token = token.replace(' ', ' ').replace('_', ' ').replace(' ', ' ')
|
| 68 |
|
| 69 |
if score < 0.6:
|
| 70 |
color = "red"
|
|
|
|
| 81 |
|
| 82 |
# Gradio Interface
|
| 83 |
with gr.Blocks() as demo:
|
| 84 |
+
gr.Markdown("# InflectionLM: Beam Token Visualization")
|
| 85 |
+
gr.Markdown('''Input a prompt. The model will:
|
| 86 |
+
- Generate multiple beams (a beam is a possible output generated by the model).
|
| 87 |
+
- Display the first output beam, highlighting any word or parts of words (tokens) with a probability score < 0.6 in red.
|
| 88 |
+
- Provide a toggle button to view detailed word/token probabilities for the beam.
|
| 89 |
+
''')
|
| 90 |
|
| 91 |
with gr.Column():
|
| 92 |
prompt_input = gr.Textbox(label="Prompt", placeholder="Enter your prompt here...", lines=3)
|