youngtsai commited on
Commit
2efd672
1 Parent(s): b5201dc

current_index = 0

Browse files
Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -479,18 +479,18 @@ def respond(user_message, df_string_output, chat_history):
479
  return "", chat_history
480
 
481
  def update_slide(direction):
482
- current_index[0] += direction
483
- if current_index[0] < 0:
484
- current_index[0] = 0 # 防止索引小于0
485
- elif current_index[0] >= len(TRASCRIPTS):
486
- current_index[0] = len(TRASCRIPTS) - 1 # 防止索引超出范围
487
 
488
  # 获取当前条目的文本和截图 URL
489
- current_transcript = TRASCRIPTS[current_index[0]]
490
  return current_transcript["screenshot_url"], current_transcript["text"]
491
 
492
 
493
- current_index = [0]
494
 
495
  with gr.Blocks() as demo:
496
  with gr.Row():
@@ -515,6 +515,7 @@ with gr.Blocks() as demo:
515
  prev_button.click(fn=update_slide, inputs=-1, outputs=[image, text])
516
  next_button.click(fn=update_slide, inputs=1, outputs=[image, text])
517
  update_slide(0)
 
518
  with gr.Tab("YouTube Transcript and Video"):
519
  transcript_html = gr.HTML(label="YouTube Transcript and Video")
520
  with gr.Tab("資料本文"):
 
479
  return "", chat_history
480
 
481
  def update_slide(direction):
482
+ current_index += direction
483
+ if current_index < 0:
484
+ current_index = 0 # 防止索引小于0
485
+ elif current_index >= len(TRASCRIPTS):
486
+ current_index = len(TRASCRIPTS) - 1 # 防止索引超出范围
487
 
488
  # 获取当前条目的文本和截图 URL
489
+ current_transcript = TRASCRIPTS[current_index]
490
  return current_transcript["screenshot_url"], current_transcript["text"]
491
 
492
 
493
+ current_index = 0
494
 
495
  with gr.Blocks() as demo:
496
  with gr.Row():
 
515
  prev_button.click(fn=update_slide, inputs=-1, outputs=[image, text])
516
  next_button.click(fn=update_slide, inputs=1, outputs=[image, text])
517
  update_slide(0)
518
+
519
  with gr.Tab("YouTube Transcript and Video"):
520
  transcript_html = gr.HTML(label="YouTube Transcript and Video")
521
  with gr.Tab("資料本文"):