TongkunGuan commited on
Commit
17cc18a
·
verified ·
1 Parent(s): 31aa5f0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -122,8 +122,10 @@ def format_bpe_display(bpe):
122
  # 使用HTML标签来设置字体大小、颜色,加粗,并居中
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,12 +209,10 @@ with gr.Blocks(title="BPE Visualization Demo") as demo:
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
 
 
122
  # 使用HTML标签来设置字体大小、颜色,加粗,并居中
123
  return f"<div style='text-align:center; font-size:20px;'><strong>Current BPE: <span style='color:red;'>{bpe}</span></strong></div>"
124
 
125
+ @spaces.GPU
126
+ def update_slider_index(x):
127
+ global current_vis, current_bpe, current_index
128
+ print(f"x: {x}, current_vis length: {len(current_vis)}, current_bpe length: {len(current_bpe)}")
129
  if 0 <= x < len(current_vis) and 0 <= x < len(current_bpe):
130
  return current_vis[x], format_bpe_display(current_bpe[x])
131
  else:
 
209
  # inputs=index_slider,
210
  # outputs=[heatmap, bpe_display]
211
  # )
212
+
 
 
213
  index_slider.change(
214
  update_slider_index,
215
+ inputs=index_slider,
216
  outputs=[heatmap, bpe_display]
217
  )
218