Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -123,7 +123,7 @@ def format_bpe_display(bpe):
|
|
| 123 |
return f"<div style='text-align:center; font-size:20px;'><strong>Current BPE: <span style='color:red;'>{bpe}</span></strong></div>"
|
| 124 |
|
| 125 |
def update_slider_index(x, current_vis, current_bpe):
|
| 126 |
-
print(f"x: {x}, current_vis length: {
|
| 127 |
if 0 <= x < len(current_vis) and 0 <= x < len(current_bpe):
|
| 128 |
return current_vis[x], format_bpe_display(current_bpe[x])
|
| 129 |
else:
|
|
@@ -207,12 +207,12 @@ with gr.Blocks(title="BPE Visualization Demo") as demo:
|
|
| 207 |
# inputs=index_slider,
|
| 208 |
# outputs=[heatmap, bpe_display]
|
| 209 |
# )
|
| 210 |
-
|
| 211 |
-
|
| 212 |
|
| 213 |
index_slider.change(
|
| 214 |
update_slider_index,
|
| 215 |
-
inputs=[index_slider,
|
| 216 |
outputs=[heatmap, bpe_display]
|
| 217 |
)
|
| 218 |
|
|
|
|
| 123 |
return f"<div style='text-align:center; font-size:20px;'><strong>Current BPE: <span style='color:red;'>{bpe}</span></strong></div>"
|
| 124 |
|
| 125 |
def update_slider_index(x, current_vis, current_bpe):
|
| 126 |
+
print(f"x: {x}, current_vis length: {current_vis}, current_bpe length: {current_bpe}")
|
| 127 |
if 0 <= x < len(current_vis) and 0 <= x < len(current_bpe):
|
| 128 |
return current_vis[x], format_bpe_display(current_bpe[x])
|
| 129 |
else:
|
|
|
|
| 207 |
# inputs=index_slider,
|
| 208 |
# outputs=[heatmap, bpe_display]
|
| 209 |
# )
|
| 210 |
+
vis = gr.State(value=current_vis) # 初始化状态
|
| 211 |
+
bpe = gr.State(value=current_bpe) # 初始化状态
|
| 212 |
|
| 213 |
index_slider.change(
|
| 214 |
update_slider_index,
|
| 215 |
+
inputs=[index_slider,vis,bpe],
|
| 216 |
outputs=[heatmap, bpe_display]
|
| 217 |
)
|
| 218 |
|