Spaces:
Running
Running
upload_content_directly
Browse files
app.py
CHANGED
@@ -125,22 +125,12 @@ def upload_content_directly(service, file_name, folder_id, content):
|
|
125 |
def upload_file_directly(service, file_name, folder_id, file_path):
|
126 |
# 上傳 .json to Google Drive
|
127 |
file_metadata = {'name': file_name, 'parents': [folder_id]}
|
128 |
-
media = MediaFileUpload(file_path, mimetype='application/json'
|
129 |
-
|
130 |
-
request = service.files().create(body=file_metadata, media_body=media, fields='id')
|
131 |
-
|
132 |
-
response = None
|
133 |
-
while response is None:
|
134 |
-
status, response = request.next_chunk()
|
135 |
-
if status:
|
136 |
-
print("Uploaded %d%%." % (status.progress() * 100))
|
137 |
-
else:
|
138 |
-
print("Upload Complete!")
|
139 |
-
|
140 |
-
# 文件上传完成后,获取文件ID
|
141 |
-
file_id = response.get('id')
|
142 |
|
143 |
-
|
|
|
|
|
144 |
|
145 |
def upload_img_directly(service, file_name, folder_id, file_path):
|
146 |
file_metadata = {'name': file_name, 'parents': [folder_id]}
|
@@ -467,16 +457,17 @@ def get_video_id_summary(video_id, df_string):
|
|
467 |
if not exists:
|
468 |
summary = generate_summarise(df_string)
|
469 |
# processed_summary = processed_video_summary_to_json(summary)
|
470 |
-
summary_json = { "summary": str(summary
|
471 |
summary_text = json.dumps(summary_json, ensure_ascii=False, indent=2)
|
|
|
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 |
-
|
476 |
-
|
|
|
|
|
477 |
|
478 |
-
# file_id = upload_content_directly(service, file_name, folder_id, summary_text)
|
479 |
-
file_id = upload_file_directly(service, file_name, folder_id, f'{OUTPUT_PATH}/{video_id}_summary.json')
|
480 |
print("summary已上傳到Google Drive")
|
481 |
else:
|
482 |
# 逐字稿已存在,下载逐字稿内容
|
|
|
125 |
def upload_file_directly(service, file_name, folder_id, file_path):
|
126 |
# 上傳 .json to Google Drive
|
127 |
file_metadata = {'name': file_name, 'parents': [folder_id]}
|
128 |
+
media = MediaFileUpload(file_path, mimetype='application/json')
|
129 |
+
file = service.files().create(body=file_metadata, media_body=media, fields='id').execute()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
|
131 |
+
|
132 |
+
# return file.get('id') # 返回文件ID
|
133 |
+
return True
|
134 |
|
135 |
def upload_img_directly(service, file_name, folder_id, file_path):
|
136 |
file_metadata = {'name': file_name, 'parents': [folder_id]}
|
|
|
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 |
# 逐字稿已存在,下载逐字稿内容
|