youngtsai commited on
Commit
a766c13
1 Parent(s): d770843

upload_content_directly(service, file_name, folder_id, summary_text)

Files changed (1) hide show
  1. app.py +37 -33
app.py CHANGED
@@ -446,41 +446,45 @@ def processed_video_summary_to_json(summary):
446
  # get video_id_summary.json content
447
  def get_video_id_summary(video_id, df_string):
448
  print("===get_video_id_summary===")
449
- try:
450
- service = init_drive_service()
451
- parent_folder_id = '1GgI4YVs0KckwStVQkLa1NZ8IpaEMurkL'
452
- folder_id = create_folder_if_not_exists(service, video_id, parent_folder_id)
453
- file_name = f'{video_id}_summary.json'
454
-
455
- # 检查逐字稿是否存在
456
- exists, file_id = check_file_exists(service, folder_id, file_name)
457
- if not exists:
458
- summary = generate_summarise(df_string)
459
- # processed_summary = processed_video_summary_to_json(summary)
460
- summary_json = { "summary": str(summary) }
461
- summary_text = json.dumps(summary_json, ensure_ascii=False, indent=2)
462
- file_id = upload_content_directly(service, file_name, folder_id, summary_text)
463
-
464
- # 存在 local at OUTPUT_PATH as {video_id}_summary.json
465
- # with open(f'{OUTPUT_PATH}/{video_id}_summary.json', 'w') as f:
466
- # f.write(summary_text)
467
- # print(f"summary已存在 local at {OUTPUT_PATH}/{video_id}_summary.json")
468
- # file_id = upload_file_directly(service, file_name, folder_id, f'{OUTPUT_PATH}/{video_id}_summary.json')
469
-
470
 
471
- print("summary已上傳到Google Drive")
472
- else:
473
- # 逐字稿已存在,下载逐字稿内容
474
- print("summary已存在Google Drive中")
475
- summary_text = download_file_as_string(service, file_id)
476
- summary_json = json.loads(summary_text)
 
477
 
478
- return summary_json
479
- except Exception as e:
480
- error_msg = f" {video_id} 摘要錯誤: {str(e)}"
481
- print("===get_video_id_summary error===")
482
- print(error_msg)
483
- raise gr.Error(error_msg)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
484
 
485
  def generate_summarise(df_string):
486
  # 使用 OpenAI 生成基于上传数据的问题
 
446
  # get video_id_summary.json content
447
  def get_video_id_summary(video_id, df_string):
448
  print("===get_video_id_summary===")
449
+ service = init_drive_service()
450
+ parent_folder_id = '1GgI4YVs0KckwStVQkLa1NZ8IpaEMurkL'
451
+ folder_id = create_folder_if_not_exists(service, video_id, parent_folder_id)
452
+ file_name = f'{video_id}_summary.json'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
453
 
454
+ # 检查逐字稿是否存在
455
+ exists, file_id = check_file_exists(service, folder_id, file_name)
456
+ if not exists:
457
+ summary = generate_summarise(df_string)
458
+ # processed_summary = processed_video_summary_to_json(summary)
459
+ summary_json = { "summary": str(summary) }
460
+ summary_text = json.dumps(summary_json, ensure_ascii=False, indent=2)
461
 
462
+ try:
463
+ upload_content_directly(service, file_name, folder_id, summary_text)
464
+ print("summary已上傳到Google Drive")
465
+
466
+ except Exception as e:
467
+ error_msg = f" {video_id} 摘要錯誤: {str(e)}"
468
+ print("===get_video_id_summary error===")
469
+ print(error_msg)
470
+ raise gr.Error(error_msg)
471
+
472
+
473
+ # 存在 local at OUTPUT_PATH as {video_id}_summary.json
474
+ # with open(f'{OUTPUT_PATH}/{video_id}_summary.json', 'w') as f:
475
+ # f.write(summary_text)
476
+ # print(f"summary已存在 local at {OUTPUT_PATH}/{video_id}_summary.json")
477
+ # file_id = upload_file_directly(service, file_name, folder_id, f'{OUTPUT_PATH}/{video_id}_summary.json')
478
+
479
+
480
+ else:
481
+ # 逐字稿已存在,下载逐字稿内容
482
+ print("summary已存在Google Drive中")
483
+ summary_text = download_file_as_string(service, file_id)
484
+ summary_json = json.loads(summary_text)
485
+
486
+ return summary_json
487
+
488
 
489
  def generate_summarise(df_string):
490
  # 使用 OpenAI 生成基于上传数据的问题