Spaces:
Sleeping
Sleeping
def refresh_video_LLM_all_content(video_ids):
Browse files- app.py +58 -1
- storage_service.py +13 -0
app.py
CHANGED
@@ -2008,6 +2008,45 @@ def summary_add_markdown_version(video_id):
|
|
2008 |
return new_summary
|
2009 |
|
2010 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011 |
# AI 生成教學素材
|
2012 |
def get_meta_data(video_id, source="gcs"):
|
2013 |
if source == "gcs":
|
@@ -3433,7 +3472,25 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
|
|
3433 |
with gr.Tab("markdown"):
|
3434 |
gr.Markdown("## 請複製以下 markdown 並貼到你的心智圖工具中,建議使用:https://markmap.js.org/repl")
|
3435 |
mind_map = gr.Textbox(container=True, show_copy_button=True, lines=40, elem_id="mind_map_markdown")
|
3436 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3437 |
|
3438 |
# OPEN AI CHATBOT SELECT
|
3439 |
chatbot_select_outputs=[
|
|
|
2008 |
return new_summary
|
2009 |
|
2010 |
|
2011 |
+
# LLM 強制重刷
|
2012 |
+
def refresh_video_LLM_all_content(video_ids):
|
2013 |
+
# 輸入影片 id,以 , 逗號分隔 或是 \n 換行
|
2014 |
+
video_id_list = video_ids.replace('\n', ',').split(',')
|
2015 |
+
video_id_list = [vid.strip() for vid in video_id_list if vid.strip()]
|
2016 |
+
|
2017 |
+
success_video_ids = []
|
2018 |
+
failed_video_ids = []
|
2019 |
+
|
2020 |
+
for video_id in video_id_list:
|
2021 |
+
try:
|
2022 |
+
print(f"===refresh_all_LLM_content===")
|
2023 |
+
print(f"video_id: {video_id}")
|
2024 |
+
# 刪除 GCS 中所有以 video_id 開頭的檔案
|
2025 |
+
print(f"===delete_blobs_by_folder_name: {video_id}===")
|
2026 |
+
bucket_name = 'video_ai_assistant'
|
2027 |
+
GCS_SERVICE.delete_blobs_by_folder_name(bucket_name, video_id)
|
2028 |
+
print(f"所有以 {video_id} 開頭的檔案已刪除")
|
2029 |
+
|
2030 |
+
# process_youtube_link
|
2031 |
+
video_link = f"https://www.youtube.com/watch?v={video_id}"
|
2032 |
+
process_youtube_link(PASSWORD, video_link)
|
2033 |
+
|
2034 |
+
success_video_ids.append(video_id)
|
2035 |
+
except Exception as e:
|
2036 |
+
print(f"===refresh_all_LLM_content error===")
|
2037 |
+
print(f"video_id: {video_id}")
|
2038 |
+
print(f"error: {str(e)}")
|
2039 |
+
print(f"===refresh_all_LLM_content error===")
|
2040 |
+
failed_video_ids.append(video_id)
|
2041 |
+
|
2042 |
+
result = {
|
2043 |
+
"success_video_ids": success_video_ids,
|
2044 |
+
"failed_video_ids": failed_video_ids
|
2045 |
+
}
|
2046 |
+
return result
|
2047 |
+
|
2048 |
+
|
2049 |
+
|
2050 |
# AI 生成教學素材
|
2051 |
def get_meta_data(video_id, source="gcs"):
|
2052 |
if source == "gcs":
|
|
|
3472 |
with gr.Tab("markdown"):
|
3473 |
gr.Markdown("## 請複製以下 markdown 並貼到你的心智圖工具中,建議使用:https://markmap.js.org/repl")
|
3474 |
mind_map = gr.Textbox(container=True, show_copy_button=True, lines=40, elem_id="mind_map_markdown")
|
3475 |
+
with gr.Accordion("refresh all", open=False):
|
3476 |
+
with gr.Row():
|
3477 |
+
gr.Markdown("## 清單影片:重新生成所有內容")
|
3478 |
+
with gr.Row():
|
3479 |
+
refresh_video_ids = gr.Textbox(label="輸入影片 id,以 , 逗號分隔")
|
3480 |
+
refresh_btn = gr.Button("refresh", variant="primary")
|
3481 |
+
with gr.Row():
|
3482 |
+
refresh_result = gr.JSON()
|
3483 |
+
|
3484 |
+
refresh_btn.click(
|
3485 |
+
refresh_video_LLM_all_content,
|
3486 |
+
inputs=[refresh_video_ids],
|
3487 |
+
outputs=[refresh_result]
|
3488 |
+
).then(
|
3489 |
+
lambda: gr.update(interactive=False),
|
3490 |
+
inputs=[],
|
3491 |
+
outputs=[refresh_btn]
|
3492 |
+
)
|
3493 |
+
|
3494 |
|
3495 |
# OPEN AI CHATBOT SELECT
|
3496 |
chatbot_select_outputs=[
|
storage_service.py
CHANGED
@@ -53,3 +53,16 @@ class GoogleCloudStorage:
|
|
53 |
blob = self.client.bucket(bucket_name).blob(blob_name)
|
54 |
blob.delete()
|
55 |
print(f"Blob {blob_name} deleted from {bucket_name}.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
blob = self.client.bucket(bucket_name).blob(blob_name)
|
54 |
blob.delete()
|
55 |
print(f"Blob {blob_name} deleted from {bucket_name}.")
|
56 |
+
|
57 |
+
def list_blobs(self, bucket_name, prefix):
|
58 |
+
blobs = self.client.list_blobs(bucket_name, prefix=prefix)
|
59 |
+
return [blob.name for blob in blobs]
|
60 |
+
|
61 |
+
def delete_blobs_by_folder_name(self, bucket_name, folder_name):
|
62 |
+
bucket = self.client.bucket(bucket_name)
|
63 |
+
blobs = list(bucket.list_blobs(prefix=folder_name))
|
64 |
+
if blobs:
|
65 |
+
bucket.delete_blobs(blobs)
|
66 |
+
print(f"所有以 {folder_name} 開頭的檔案已批量刪除")
|
67 |
+
else:
|
68 |
+
print(f"未找到以 {folder_name} 開頭的檔案")
|