youngtsai commited on
Commit
4ab6d4c
1 Parent(s): 2cf6264
Files changed (1) hide show
  1. app.py +60 -6
app.py CHANGED
@@ -667,7 +667,7 @@ def download_youtube_video(youtube_id, output_path=OUTPUT_PATH):
667
  print(f"[Pytube] Video downloaded successfully: {output_path}/{youtube_id}.mp4")
668
  except Exception as e:
669
  ydl_opts = {
670
- 'format': 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best', # This ensures the best quality combining video and audio
671
  'outtmpl': os.path.join(output_path, f'{youtube_id}.mp4'), # Output filename template
672
  }
673
  with yt_dlp.YoutubeDL(ydl_opts) as ydl:
@@ -1775,6 +1775,14 @@ def update_LLM_content(video_id, new_content, kind):
1775
  questions_answers_text = json.dumps(questions_answers_json, ensure_ascii=False, indent=2)
1776
  GCS_SERVICE.upload_json_string(bucket_name, blob_name, questions_answers_text)
1777
  updated_content = questions_answers_text
 
 
 
 
 
 
 
 
1778
 
1779
  print(f"{kind} 已更新到GCS")
1780
  return gr.update(value=updated_content, interactive=False)
@@ -2803,7 +2811,8 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
2803
  chatbot_open_ai_name = gr.State("chatbot_open_ai")
2804
  gr.Image(value=vaitor_chatbot_avatar_url, height=100, width=100, show_label=False, show_download_button=False)
2805
  vaitor_chatbot_select_btn = gr.Button("👆選擇【飛特精靈】", elem_id="chatbot_btn", visible=True, variant="primary")
2806
- vaitor_chatbot_description_value = gr.Markdown(value=vaitor_chatbot_description, visible=True)
 
2807
  # 狐狸貓
2808
  with gr.Column(scale=1, variant="panel"):
2809
  foxcat_chatbot_avatar_url = "https://storage.googleapis.com/wpassets.junyiacademy.org/1/2020/06/%E7%A7%91%E5%AD%B8%E5%BE%BD%E7%AB%A0-2-150x150.png"
@@ -2818,7 +2827,8 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
2818
  foxcat_chatbot_name = gr.State("foxcat")
2819
  gr.Image(value=foxcat_chatbot_avatar_url, height=100, width=100, show_label=False, show_download_button=False)
2820
  foxcat_chatbot_select_btn = gr.Button("👆選擇【狐狸貓】", visible=True, variant="primary", elem_classes="chatbot_select_btn")
2821
- foxcat_chatbot_description_value = gr.Markdown(value=foxcat_chatbot_description, visible=True)
 
2822
  # 梨梨
2823
  with gr.Column(scale=1, variant="panel"):
2824
  lili_chatbot_avatar_url = "https://junyitopicimg.s3.amazonaws.com/live/v1283-new-topic-44-icon.png?v=20230529071206714"
@@ -2833,7 +2843,8 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
2833
  lili_chatbot_name = gr.State("lili")
2834
  gr.Image(value=lili_chatbot_avatar_url, height=100, width=100, show_label=False, show_download_button=False)
2835
  lili_chatbot_select_btn = gr.Button("👆選擇【梨梨】", visible=True, variant="primary", elem_classes="chatbot_select_btn")
2836
- lili_chatbot_description_value = gr.Markdown(value=lili_chatbot_description, visible=True)
 
2837
  # 麥麥
2838
  with gr.Column(scale=1, variant="panel"):
2839
  maimai_chatbot_avatar_url = "https://storage.googleapis.com/wpassets.junyiacademy.org/1/2020/07/%E6%80%9D%E8%80%83%E5%8A%9B%E8%B6%85%E4%BA%BA%E5%BE%BD%E7%AB%A0_%E5%B7%A5%E4%BD%9C%E5%8D%80%E5%9F%9F-1-%E8%A4%87%E6%9C%AC-150x150.png"
@@ -2848,7 +2859,8 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
2848
  maimai_chatbot_name = gr.State("maimai")
2849
  gr.Image(value=maimai_chatbot_avatar_url, height=100, width=100, show_label=False, show_download_button=False)
2850
  maimai_chatbot_select_btn = gr.Button("👆選擇【麥麥】", visible=True, variant="primary", elem_classes="chatbot_select_btn")
2851
- maimai_chatbot_description_value = gr.Markdown(value=maimai_chatbot_description, visible=True)
 
2852
  # 飛特音速
2853
  with gr.Column(scale=1, variant="panel", visible=True):
2854
  streaming_chatbot_avatar_url = "https://storage.googleapis.com/wpassets.junyiacademy.org/1/2020/11/1-%E6%98%9F%E7%A9%BA%E9%A0%AD%E8%B2%BC-%E5%A4%AA%E7%A9%BA%E7%8B%90%E7%8B%B8%E8%B2%93-150x150.png"
@@ -2861,7 +2873,8 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
2861
  chatbot_open_ai_streaming_name = gr.State("chatbot_open_ai_streaming")
2862
  gr.Image(value=streaming_chatbot_avatar_url, height=100, width=100, show_label=False, show_download_button=False)
2863
  chatbot_open_ai_streaming_select_btn = gr.Button("👆選擇【飛特音速】", elem_id="streaming_chatbot_btn", visible=True, variant="primary")
2864
- gr.Markdown(value=streaming_chatbot_description, visible=True)
 
2865
  # 尚未開放
2866
  with gr.Column(scale=1, variant="panel"):
2867
  gr.Markdown(value="### 尚未開放", visible=True)
@@ -3074,6 +3087,16 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
3074
  questions_answers_create_button = gr.Button("重建", size="sm", variant="primary")
3075
  with gr.Row():
3076
  questions_answers_json = gr.Textbox(label="Questions Answers", lines=40, interactive=False, show_copy_button=True)
 
 
 
 
 
 
 
 
 
 
3077
  with gr.Tab("逐字稿"):
3078
  simple_html_content = gr.HTML(label="Simple Transcript")
3079
  with gr.Tab("圖文"):
@@ -3482,6 +3505,37 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
3482
  'inputs': [video_id, questions_answers_json, questions_answers_kind],
3483
  'outputs': [questions_answers_json]
3484
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3485
  ]
3486
  setup_content_buttons(content_buttons_config)
3487
 
 
667
  print(f"[Pytube] Video downloaded successfully: {output_path}/{youtube_id}.mp4")
668
  except Exception as e:
669
  ydl_opts = {
670
+ 'format': "bestvideo[height<=720][ext=mp4]",
671
  'outtmpl': os.path.join(output_path, f'{youtube_id}.mp4'), # Output filename template
672
  }
673
  with yt_dlp.YoutubeDL(ydl_opts) as ydl:
 
1775
  questions_answers_text = json.dumps(questions_answers_json, ensure_ascii=False, indent=2)
1776
  GCS_SERVICE.upload_json_string(bucket_name, blob_name, questions_answers_text)
1777
  updated_content = questions_answers_text
1778
+ elif kind == "ai_content_list":
1779
+ if isinstance(new_content, str):
1780
+ ai_content_json = json.loads(new_content)
1781
+ else:
1782
+ ai_content_json = new_content
1783
+ ai_content_text = json.dumps(ai_content_json, ensure_ascii=False, indent=2)
1784
+ GCS_SERVICE.upload_json_string(bucket_name, blob_name, ai_content_text)
1785
+ updated_content = ai_content_text
1786
 
1787
  print(f"{kind} 已更新到GCS")
1788
  return gr.update(value=updated_content, interactive=False)
 
2811
  chatbot_open_ai_name = gr.State("chatbot_open_ai")
2812
  gr.Image(value=vaitor_chatbot_avatar_url, height=100, width=100, show_label=False, show_download_button=False)
2813
  vaitor_chatbot_select_btn = gr.Button("👆選擇【飛特精靈】", elem_id="chatbot_btn", visible=True, variant="primary")
2814
+ with gr.Accordion("🦄 飛特精靈 敘述", open=False):
2815
+ vaitor_chatbot_description_value = gr.Markdown(value=vaitor_chatbot_description, visible=True)
2816
  # 狐狸貓
2817
  with gr.Column(scale=1, variant="panel"):
2818
  foxcat_chatbot_avatar_url = "https://storage.googleapis.com/wpassets.junyiacademy.org/1/2020/06/%E7%A7%91%E5%AD%B8%E5%BE%BD%E7%AB%A0-2-150x150.png"
 
2827
  foxcat_chatbot_name = gr.State("foxcat")
2828
  gr.Image(value=foxcat_chatbot_avatar_url, height=100, width=100, show_label=False, show_download_button=False)
2829
  foxcat_chatbot_select_btn = gr.Button("👆選擇【狐狸貓】", visible=True, variant="primary", elem_classes="chatbot_select_btn")
2830
+ with gr.Accordion("💜 狐狸貓 敘述", open=False):
2831
+ foxcat_chatbot_description_value = gr.Markdown(value=foxcat_chatbot_description, visible=True)
2832
  # 梨梨
2833
  with gr.Column(scale=1, variant="panel"):
2834
  lili_chatbot_avatar_url = "https://junyitopicimg.s3.amazonaws.com/live/v1283-new-topic-44-icon.png?v=20230529071206714"
 
2843
  lili_chatbot_name = gr.State("lili")
2844
  gr.Image(value=lili_chatbot_avatar_url, height=100, width=100, show_label=False, show_download_button=False)
2845
  lili_chatbot_select_btn = gr.Button("👆選擇【梨梨】", visible=True, variant="primary", elem_classes="chatbot_select_btn")
2846
+ with gr.Accordion("🧡 梨梨 敘述", open=False):
2847
+ lili_chatbot_description_value = gr.Markdown(value=lili_chatbot_description, visible=True)
2848
  # 麥麥
2849
  with gr.Column(scale=1, variant="panel"):
2850
  maimai_chatbot_avatar_url = "https://storage.googleapis.com/wpassets.junyiacademy.org/1/2020/07/%E6%80%9D%E8%80%83%E5%8A%9B%E8%B6%85%E4%BA%BA%E5%BE%BD%E7%AB%A0_%E5%B7%A5%E4%BD%9C%E5%8D%80%E5%9F%9F-1-%E8%A4%87%E6%9C%AC-150x150.png"
 
2859
  maimai_chatbot_name = gr.State("maimai")
2860
  gr.Image(value=maimai_chatbot_avatar_url, height=100, width=100, show_label=False, show_download_button=False)
2861
  maimai_chatbot_select_btn = gr.Button("👆選擇【麥麥】", visible=True, variant="primary", elem_classes="chatbot_select_btn")
2862
+ with gr.Accordion("💙 麥��� 敘述", open=False):
2863
+ maimai_chatbot_description_value = gr.Markdown(value=maimai_chatbot_description, visible=True)
2864
  # 飛特音速
2865
  with gr.Column(scale=1, variant="panel", visible=True):
2866
  streaming_chatbot_avatar_url = "https://storage.googleapis.com/wpassets.junyiacademy.org/1/2020/11/1-%E6%98%9F%E7%A9%BA%E9%A0%AD%E8%B2%BC-%E5%A4%AA%E7%A9%BA%E7%8B%90%E7%8B%B8%E8%B2%93-150x150.png"
 
2873
  chatbot_open_ai_streaming_name = gr.State("chatbot_open_ai_streaming")
2874
  gr.Image(value=streaming_chatbot_avatar_url, height=100, width=100, show_label=False, show_download_button=False)
2875
  chatbot_open_ai_streaming_select_btn = gr.Button("👆選擇【飛特音速】", elem_id="streaming_chatbot_btn", visible=True, variant="primary")
2876
+ with gr.Accordion("🚀 飛特音速 敘述", open=False):
2877
+ gr.Markdown(value=streaming_chatbot_description, visible=True)
2878
  # 尚未開放
2879
  with gr.Column(scale=1, variant="panel"):
2880
  gr.Markdown(value="### 尚未開放", visible=True)
 
3087
  questions_answers_create_button = gr.Button("重建", size="sm", variant="primary")
3088
  with gr.Row():
3089
  questions_answers_json = gr.Textbox(label="Questions Answers", lines=40, interactive=False, show_copy_button=True)
3090
+ with gr.Tab("教學備課"):
3091
+ with gr.Row() as worksheet_admin:
3092
+ worksheet_kind = gr.Textbox(value="ai_content_list", show_label=False)
3093
+ worksheet_get_button = gr.Button("取得", size="sm", variant="primary")
3094
+ worksheet_edit_button = gr.Button("編輯", size="sm", variant="primary")
3095
+ worksheet_update_button = gr.Button("儲存", size="sm", variant="primary")
3096
+ worksheet_delete_button = gr.Button("刪除", size="sm", variant="primary")
3097
+ worksheet_create_button = gr.Button("重建(X)", size="sm", variant="primary", interactive=False)
3098
+ with gr.Row():
3099
+ worksheet_json = gr.Textbox(label="worksheet", lines=40, interactive=False, show_copy_button=True)
3100
  with gr.Tab("逐字稿"):
3101
  simple_html_content = gr.HTML(label="Simple Transcript")
3102
  with gr.Tab("圖文"):
 
3505
  'inputs': [video_id, questions_answers_json, questions_answers_kind],
3506
  'outputs': [questions_answers_json]
3507
  },
3508
+ # Worksheet actions
3509
+ {
3510
+ 'button': worksheet_get_button,
3511
+ 'action': get_LLM_content,
3512
+ 'inputs': [video_id, worksheet_kind],
3513
+ 'outputs': [worksheet_json]
3514
+ },
3515
+ {
3516
+ 'button': worksheet_create_button,
3517
+ 'action': create_LLM_content,
3518
+ 'inputs': [video_id, df_string_output, worksheet_kind],
3519
+ 'outputs': [worksheet_json]
3520
+ },
3521
+ {
3522
+ 'button': worksheet_delete_button,
3523
+ 'action': delete_LLM_content,
3524
+ 'inputs': [video_id, worksheet_kind],
3525
+ 'outputs': [worksheet_json]
3526
+ },
3527
+ {
3528
+ 'button': worksheet_edit_button,
3529
+ 'action': enable_edit_mode,
3530
+ 'inputs': [],
3531
+ 'outputs': [worksheet_json]
3532
+ },
3533
+ {
3534
+ 'button': worksheet_update_button,
3535
+ 'action': update_LLM_content,
3536
+ 'inputs': [video_id, worksheet_json, worksheet_kind],
3537
+ 'outputs': [worksheet_json]
3538
+ },
3539
  ]
3540
  setup_content_buttons(content_buttons_config)
3541