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

prev_button.click(fn=prev_slide, inputs=[], outputs=[image, text])

Browse files
Files changed (1) hide show
  1. app.py +20 -9
app.py CHANGED
@@ -49,7 +49,7 @@ from urllib.parse import urlparse, parse_qs
49
 
50
 
51
  OUTPUT_PATH = 'videos'
52
- TRASCRIPTS = []
53
 
54
  OPEN_AI_KEY = os.getenv("OPEN_AI_KEY")
55
  client = OpenAI(api_key=OPEN_AI_KEY)
@@ -309,8 +309,8 @@ def process_youtube_link(link):
309
  df_string_output = json.dumps(transcript, ensure_ascii=False, indent=2)
310
  df_summarise = generate_df_summarise(transcript)
311
 
312
- global TRASCRIPTS
313
- TRASCRIPTS = formatted_transcript
314
 
315
  # 确保返回与 UI 组件预期匹配的输出
316
  return questions[0] if len(questions) > 0 else "", \
@@ -482,13 +482,19 @@ 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
 
@@ -512,9 +518,8 @@ with gr.Blocks() as demo:
512
  next_button = gr.Button("下一个")
513
 
514
  # 设置按钮的动作
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")
@@ -549,4 +554,10 @@ with gr.Blocks() as demo:
549
  # 当输入网页链接时触发
550
  web_link.change(process_web_link, inputs=web_link, outputs=[btn_1, btn_2, btn_3, df_summarise, df_string_output])
551
 
 
 
 
 
 
 
552
  demo.launch(allowed_paths=["videos"])
 
49
 
50
 
51
  OUTPUT_PATH = 'videos'
52
+ TRANSCRIPTS = []
53
 
54
  OPEN_AI_KEY = os.getenv("OPEN_AI_KEY")
55
  client = OpenAI(api_key=OPEN_AI_KEY)
 
309
  df_string_output = json.dumps(transcript, ensure_ascii=False, indent=2)
310
  df_summarise = generate_df_summarise(transcript)
311
 
312
+ global TRANSCRIPTS
313
+ TRANSCRIPTS = formatted_transcript
314
 
315
  # 确保返回与 UI 组件预期匹配的输出
316
  return questions[0] if len(questions) > 0 else "", \
 
482
  current_index += direction
483
  if current_index < 0:
484
  current_index = 0 # 防止索引小于0
485
+ elif current_index >= len(TRANSCRIPTS):
486
+ current_index = len(TRANSCRIPTS) - 1 # 防止索引超出范围
487
 
488
  # 获取当前条目的文本和截图 URL
489
+ current_transcript = TRANSCRIPTS[current_index]
490
  return current_transcript["screenshot_url"], current_transcript["text"]
491
 
492
+ def prev_slide():
493
+ return update_slide(-1)
494
+
495
+ # 包装函数来处理 "下一个" 按钮点击事件
496
+ def next_slide():
497
+ return update_slide(1)
498
 
499
  current_index = 0
500
 
 
518
  next_button = gr.Button("下一个")
519
 
520
  # 设置按钮的动作
521
+ prev_button.click(fn=prev_slide, inputs=[], outputs=[image, text])
522
+ next_button.click(fn=next_slide, inputs=[], outputs=[image, text])
 
523
 
524
  with gr.Tab("YouTube Transcript and Video"):
525
  transcript_html = gr.HTML(label="YouTube Transcript and Video")
 
554
  # 当输入网页链接时触发
555
  web_link.change(process_web_link, inputs=web_link, outputs=[btn_1, btn_2, btn_3, df_summarise, df_string_output])
556
 
557
+
558
+ if TRANSCRIPTS: # 确保列表不为空
559
+ first_screenshot_url, first_text = update_slide(0)
560
+ image.update(value=first_screenshot_url)
561
+ text.update(value=first_text)
562
+
563
  demo.launch(allowed_paths=["videos"])