Spaces:
Sleeping
Sleeping
debug
Browse files
app.py
CHANGED
@@ -2341,48 +2341,54 @@ def refresh_video_LLM_all_content_by_sheet(sheet_url, sheet_qa_column, video_ids
|
|
2341 |
|
2342 |
if ids_to_refresh:
|
2343 |
print(f"\n開始處理 {len(ids_to_refresh)} 個需要刷新的 Video ID...")
|
|
|
2344 |
for video_id in ids_to_refresh:
|
2345 |
row_number = video_id_to_row_map[video_id] # 必定存在,前面已檢查
|
2346 |
print(f" 正在刷新 {video_id} (第 {row_number} 列)...")
|
2347 |
try:
|
2348 |
refresh_video_LLM_all_content_by_id(video_id)
|
2349 |
print(f" - {video_id} 刷新成功。")
|
2350 |
-
successfully_refreshed_ids.append((video_id, row_number))
|
2351 |
time.sleep(1) # 避免過於頻繁觸發其他 API (例如 GCS 刪除/上傳)
|
2352 |
except Exception as e:
|
2353 |
print(f" - {video_id} 刷新失敗: {str(e)}")
|
2354 |
-
failed_refresh_ids.append((video_id, row_number))
|
2355 |
time.sleep(5) # 失敗時稍作停頓
|
2356 |
|
2357 |
# 7. 批次更新刷新結果 (OO for success, XX for failure)
|
|
|
2358 |
update_data_oo2 = []
|
2359 |
update_data_xx = []
|
2360 |
sheet_name = SHEET_SERVICE.get_sheet_name_by_url(sheet_url) # 再次獲取或使用之前獲取的
|
2361 |
|
2362 |
if sheet_name:
|
|
|
2363 |
for vid, row_num in successfully_refreshed_ids:
|
2364 |
update_data_oo2.append({
|
2365 |
'range': f"{sheet_name}!{qa_col_letter}{row_num}",
|
2366 |
'value': sheet_qa_success_tag
|
2367 |
})
|
|
|
2368 |
for vid, row_num in failed_refresh_ids:
|
2369 |
update_data_xx.append({
|
2370 |
'range': f"{sheet_name}!{qa_col_letter}{row_num}",
|
2371 |
'value': sheet_qa_failed_tag
|
2372 |
})
|
2373 |
|
|
|
2374 |
if update_data_oo2:
|
2375 |
print(f"\n準備批次更新 {len(update_data_oo2)} 個 Video ID 的 QA 為 '{sheet_qa_success_tag}' (刷新成功)...")
|
2376 |
try:
|
2377 |
-
SHEET_SERVICE.batch_update_cells(sheet_url, update_data_oo2)
|
2378 |
print(f"成功批次更新 {len(update_data_oo2)} 個儲存格為 '{sheet_qa_success_tag}'。")
|
2379 |
except Exception as e:
|
2380 |
print(f"批次更新 QA 為 '{sheet_qa_success_tag}' (刷新成功) 時發生錯誤: {e}")
|
2381 |
|
|
|
2382 |
if update_data_xx:
|
2383 |
print(f"\n準備批次更新 {len(update_data_xx)} 個 Video ID 的 QA 為 '{sheet_qa_failed_tag}' (刷新失敗)...")
|
2384 |
try:
|
2385 |
-
SHEET_SERVICE.batch_update_cells(sheet_url, update_data_xx)
|
2386 |
print(f"成功批次更新 {len(update_data_xx)} 個儲存格為 '{sheet_qa_failed_tag}'。")
|
2387 |
except Exception as e:
|
2388 |
print(f"批次更新 QA 為 '{sheet_qa_failed_tag}' 時發生錯誤: {e}")
|
@@ -2390,7 +2396,6 @@ def refresh_video_LLM_all_content_by_sheet(sheet_url, sheet_qa_column, video_ids
|
|
2390 |
if successfully_refreshed_ids or failed_refresh_ids:
|
2391 |
print("錯誤:無法獲取工作表名稱,無法批次更新刷新結果。")
|
2392 |
|
2393 |
-
|
2394 |
# 8. 整理最終結果
|
2395 |
final_success_ids = [item[0] for item in ids_to_set_oo_phase1] + [item[0] for item in successfully_refreshed_ids]
|
2396 |
final_failed_ids = [item[0] for item in failed_refresh_ids]
|
|
|
2341 |
|
2342 |
if ids_to_refresh:
|
2343 |
print(f"\n開始處理 {len(ids_to_refresh)} 個需要刷新的 Video ID...")
|
2344 |
+
# 這個迴圈只負責執行刷新並記錄結果,不直接更新 Sheet
|
2345 |
for video_id in ids_to_refresh:
|
2346 |
row_number = video_id_to_row_map[video_id] # 必定存在,前面已檢查
|
2347 |
print(f" 正在刷新 {video_id} (第 {row_number} 列)...")
|
2348 |
try:
|
2349 |
refresh_video_LLM_all_content_by_id(video_id)
|
2350 |
print(f" - {video_id} 刷新成功。")
|
2351 |
+
successfully_refreshed_ids.append((video_id, row_number)) # 記錄成功
|
2352 |
time.sleep(1) # 避免過於頻繁觸發其他 API (例如 GCS 刪除/上傳)
|
2353 |
except Exception as e:
|
2354 |
print(f" - {video_id} 刷新失敗: {str(e)}")
|
2355 |
+
failed_refresh_ids.append((video_id, row_number)) # 記錄失敗
|
2356 |
time.sleep(5) # 失敗時稍作停頓
|
2357 |
|
2358 |
# 7. 批次更新刷新結果 (OO for success, XX for failure)
|
2359 |
+
# --- 更新 Sheet 的程式碼在這裡 ---
|
2360 |
update_data_oo2 = []
|
2361 |
update_data_xx = []
|
2362 |
sheet_name = SHEET_SERVICE.get_sheet_name_by_url(sheet_url) # 再次獲取或使用之前獲取的
|
2363 |
|
2364 |
if sheet_name:
|
2365 |
+
# 準備成功刷新的更新資料
|
2366 |
for vid, row_num in successfully_refreshed_ids:
|
2367 |
update_data_oo2.append({
|
2368 |
'range': f"{sheet_name}!{qa_col_letter}{row_num}",
|
2369 |
'value': sheet_qa_success_tag
|
2370 |
})
|
2371 |
+
# 準備刷新失敗的更新資料
|
2372 |
for vid, row_num in failed_refresh_ids:
|
2373 |
update_data_xx.append({
|
2374 |
'range': f"{sheet_name}!{qa_col_letter}{row_num}",
|
2375 |
'value': sheet_qa_failed_tag
|
2376 |
})
|
2377 |
|
2378 |
+
# 執行成功的批次更新
|
2379 |
if update_data_oo2:
|
2380 |
print(f"\n準備批次更新 {len(update_data_oo2)} 個 Video ID 的 QA 為 '{sheet_qa_success_tag}' (刷新成功)...")
|
2381 |
try:
|
2382 |
+
SHEET_SERVICE.batch_update_cells(sheet_url, update_data_oo2) # <--- 實際呼叫更新 Sheet 的函數
|
2383 |
print(f"成功批次更新 {len(update_data_oo2)} 個儲存格為 '{sheet_qa_success_tag}'。")
|
2384 |
except Exception as e:
|
2385 |
print(f"批次更新 QA 為 '{sheet_qa_success_tag}' (刷新成功) 時發生錯誤: {e}")
|
2386 |
|
2387 |
+
# 執行失敗的批次更新
|
2388 |
if update_data_xx:
|
2389 |
print(f"\n準備批次更新 {len(update_data_xx)} 個 Video ID 的 QA 為 '{sheet_qa_failed_tag}' (刷新失敗)...")
|
2390 |
try:
|
2391 |
+
SHEET_SERVICE.batch_update_cells(sheet_url, update_data_xx) # <--- 實際呼叫更新 Sheet 的函數
|
2392 |
print(f"成功批次更新 {len(update_data_xx)} 個儲存格為 '{sheet_qa_failed_tag}'。")
|
2393 |
except Exception as e:
|
2394 |
print(f"批次更新 QA 為 '{sheet_qa_failed_tag}' 時發生錯誤: {e}")
|
|
|
2396 |
if successfully_refreshed_ids or failed_refresh_ids:
|
2397 |
print("錯誤:無法獲取工作表名稱,無法批次更新刷新結果。")
|
2398 |
|
|
|
2399 |
# 8. 整理最終結果
|
2400 |
final_success_ids = [item[0] for item in ids_to_set_oo_phase1] + [item[0] for item in successfully_refreshed_ids]
|
2401 |
final_failed_ids = [item[0] for item in failed_refresh_ids]
|