youngtsai commited on
Commit
b5201dc
1 Parent(s): 0fa689e

TRASCRIPTS = []

Browse files
Files changed (1) hide show
  1. app.py +39 -79
app.py CHANGED
@@ -49,13 +49,11 @@ from urllib.parse import urlparse, parse_qs
49
 
50
 
51
  OUTPUT_PATH = 'videos'
52
-
53
 
54
  OPEN_AI_KEY = os.getenv("OPEN_AI_KEY")
55
  client = OpenAI(api_key=OPEN_AI_KEY)
56
 
57
- JS = ''
58
- CSS = ''
59
 
60
  # # ====drive====初始化Google Drive服务
61
  def init_drive_service():
@@ -311,92 +309,28 @@ def process_youtube_link(link):
311
  df_string_output = json.dumps(transcript, ensure_ascii=False, indent=2)
312
  df_summarise = generate_df_summarise(transcript)
313
 
 
 
 
314
  # 确保返回与 UI 组件预期匹配的输出
315
  return questions[0] if len(questions) > 0 else "", \
316
  questions[1] if len(questions) > 1 else "", \
317
  questions[2] if len(questions) > 2 else "", \
318
  df_string_output, \
319
  df_summarise, \
320
- html_content,
 
321
 
322
  def format_transcript_to_html(formatted_transcript):
323
- # html_content = ""
324
- # for entry in formatted_transcript:
325
- # html_content += f"<h3>{entry['start_time']} - {entry['end_time']}</h3>"
326
- # html_content += f"<p>{entry['text']}</p>"
327
- # html_content += f"<img src='{entry['screenshot_path']}' width='500px' />"
328
- # return html_content
329
-
330
- CSS = """
331
- #contentDisplay {{
332
- width: 500px;
333
- margin: auto;
334
- text-align: center;
335
- }}
336
- #imageDisplay {{
337
- width: 500px;
338
- height: 300px;
339
- background-color: #f0f0f0;
340
- background-size: contain;
341
- background-position: center center;
342
- background-repeat: no-repeat;
343
- margin-bottom: 20px;
344
- }}
345
- """
346
-
347
- # 将逐字稿数据转换为 JavaScript 对象数组
348
- entries_js_array = ',\n '.join([
349
- json.dumps({
350
- "start_time": entry['start_time'],
351
- "end_time": entry['end_time'],
352
- "text": entry['text'],
353
- "screenshot_path": entry['screenshot_path']
354
- }, ensure_ascii=False) for entry in formatted_transcript
355
- ])
356
-
357
- JS = f"""
358
- var entries = [
359
- {entries_js_array}
360
- ];
361
- var currentIndex = 0;
362
-
363
- function updateContentDisplay(index) {{
364
- var entry = entries[index];
365
- document.getElementById('imageDisplay').style.backgroundImage = 'url(' + entry.screenshot_path + ')';
366
- document.getElementById('timeDisplay').innerText = entry.start_time + " - " + entry.end_time;
367
- document.getElementById('textDisplay').innerText = entry.text;
368
- }}
369
-
370
- updateContentDisplay(currentIndex);
371
-
372
- document.getElementById('prevButton').addEventListener('click', function() {{
373
- if (currentIndex > 0) {{
374
- currentIndex -= 1;
375
- updateContentDisplay(currentIndex);
376
- }}
377
- }});
378
-
379
- document.getElementById('nextButton').addEventListener('click', function() {{
380
- if (currentIndex < entries.length - 1) {{
381
- currentIndex += 1;
382
- updateContentDisplay(currentIndex);
383
- }}
384
- }});
385
- """
386
-
387
- html_content = """
388
- <div id="contentDisplay">
389
- <div id="imageDisplay"></div>
390
- <p id="timeDisplay"></p>
391
- <p id="textDisplay"></p>
392
- <button id="prevButton">上一個</button>
393
- <button id="nextButton">下一個</button>
394
- </div>
395
- """
396
-
397
  return html_content
398
 
399
 
 
400
  def get_embedded_youtube_link(video_id, start_time):
401
  embed_url = f"https://www.youtube.com/embed/{video_id}?start={start_time}&autoplay=1"
402
  return embed_url
@@ -544,7 +478,21 @@ def respond(user_message, df_string_output, chat_history):
544
  # 返回聊天历史和空字符串清空输入框
545
  return "", chat_history
546
 
547
- with gr.Blocks(css=CSS, js=JS) as demo:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
548
  with gr.Row():
549
  with gr.Column():
550
  file_upload = gr.File(label="Upload your CSV or Word file")
@@ -555,6 +503,18 @@ with gr.Blocks(css=CSS, js=JS) as demo:
555
  send_button = gr.Button("Send")
556
 
557
  with gr.Column():
 
 
 
 
 
 
 
 
 
 
 
 
558
  with gr.Tab("YouTube Transcript and Video"):
559
  transcript_html = gr.HTML(label="YouTube Transcript and Video")
560
  with gr.Tab("資料本文"):
 
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)
56
 
 
 
57
 
58
  # # ====drive====初始化Google Drive服务
59
  def init_drive_service():
 
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 "", \
317
  questions[1] if len(questions) > 1 else "", \
318
  questions[2] if len(questions) > 2 else "", \
319
  df_string_output, \
320
  df_summarise, \
321
+ html_content
322
+
323
 
324
  def format_transcript_to_html(formatted_transcript):
325
+ html_content = ""
326
+ for entry in formatted_transcript:
327
+ html_content += f"<h3>{entry['start_time']} - {entry['end_time']}</h3>"
328
+ html_content += f"<p>{entry['text']}</p>"
329
+ html_content += f"<img src='{entry['screenshot_path']}' width='500px' />"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
330
  return html_content
331
 
332
 
333
+
334
  def get_embedded_youtube_link(video_id, start_time):
335
  embed_url = f"https://www.youtube.com/embed/{video_id}?start={start_time}&autoplay=1"
336
  return embed_url
 
478
  # 返回聊天历史和空字符串清空输入框
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():
497
  with gr.Column():
498
  file_upload = gr.File(label="Upload your CSV or Word file")
 
503
  send_button = gr.Button("Send")
504
 
505
  with gr.Column():
506
+ with gr.Tab("投影片"):
507
+
508
+ image = gr.Image()
509
+ text = gr.Textbox()
510
+ with gr.Row():
511
+ prev_button = gr.Button("上一个")
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
  with gr.Tab("YouTube Transcript and Video"):
519
  transcript_html = gr.HTML(label="YouTube Transcript and Video")
520
  with gr.Tab("資料本文"):