youngtsai commited on
Commit
75ac158
1 Parent(s): 939f3b1

raise gr.Error(error_msg)

Browse files
Files changed (1) hide show
  1. app.py +24 -21
app.py CHANGED
@@ -379,27 +379,30 @@ def process_web_link(link):
379
 
380
  # get video_id_summary.json content
381
  def get_video_id_summary(video_id, df_string):
382
- service = init_drive_service()
383
- parent_folder_id = '1GgI4YVs0KckwStVQkLa1NZ8IpaEMurkL'
384
- folder_id = create_folder_if_not_exists(service, video_id, parent_folder_id)
385
- file_name = f'{video_id}_summary.json'
386
-
387
- # 检查逐字稿是否存在
388
- exists, file_id = check_file_exists(service, folder_id, file_name)
389
- if not exists:
390
- summary = generate_summarise(df_string)
391
- summary_json = {"summary": summary}
392
- summary_text = json.dumps(summary_json, ensure_ascii=False, indent=2)
393
- file_id = upload_content_directly(service, file_name, folder_id, summary_text)
394
- print("summary已上传到Google Drive")
395
- else:
396
- # 逐字稿已存在,下载逐字稿内容
397
- print("summary已存在于Google Drive中")
398
- summary_text = download_file_as_string(service, file_id)
399
- summary_json = json.loads(summary_text)
400
-
401
- return summary_json
402
-
 
 
 
403
 
404
  def generate_summarise(df_string):
405
  # 使用 OpenAI 生成基于上传数据的问题
 
379
 
380
  # get video_id_summary.json content
381
  def get_video_id_summary(video_id, df_string):
382
+ try:
383
+ service = init_drive_service()
384
+ parent_folder_id = '1GgI4YVs0KckwStVQkLa1NZ8IpaEMurkL'
385
+ folder_id = create_folder_if_not_exists(service, video_id, parent_folder_id)
386
+ file_name = f'{video_id}_summary.json'
387
+
388
+ # 检查逐字稿是否存在
389
+ exists, file_id = check_file_exists(service, folder_id, file_name)
390
+ if not exists:
391
+ summary = generate_summarise(df_string)
392
+ summary_json = {"summary": summary}
393
+ summary_text = json.dumps(summary_json, ensure_ascii=False, indent=2)
394
+ file_id = upload_content_directly(service, file_name, folder_id, summary_text)
395
+ print("summary已上传到Google Drive")
396
+ else:
397
+ # 逐字稿已存在,下载逐字稿内容
398
+ print("summary已存在于Google Drive中")
399
+ summary_text = download_file_as_string(service, file_id)
400
+ summary_json = json.loads(summary_text)
401
+
402
+ return summary_json
403
+ except Exception as e:
404
+ error_msg = f" {video_id} 摘要錯誤: {str(e)}"
405
+ raise gr.Error(error_msg)
406
 
407
  def generate_summarise(df_string):
408
  # 使用 OpenAI 生成基于上传数据的问题