import asyncio import json import os import re import time from typing import Dict, List, Tuple from openai import AsyncAzureOpenAI from tqdm import tqdm # ===================== 1. Configuration ===================== PRED_FILE = "eval/narration/youcook2/results/yc2_text_q_85.jsonl" GT_FILE = "xxx/YouCook2/data/youcook2_ourtest.json" OUTPUT_FILE = "eval/narration/youcook2/test_q_eval_85.jsonl" azure_base_url = "" azure_api_version = "" azure_ak = "" azure_model_name = "" MAX_CONCURRENT_REQUESTS = 50 MAX_RETRIES = 5 RETRY_DELAY = 8 TIMEOUT = 10 # Maximum waiting time (seconds) for each request # ===================== 2. Text Preprocessing & Structure Construction ===================== def clean_text_for_concat(text: str) -> str: """Simple text cleaning: remove <|im_end|> and compress whitespace.""" if text.startswith(".<|im_end|>"): text = text.replace(".<|im_end|>", "") print(text) text = text.replace("<|im_end|>", " ") if text != "": text = " ".join(text.strip().split()) return text def load_gt(gt_path: str) -> Dict[str, Dict]: """ Load youcook2_ourtest.json Returns: id2gt[vid] = { "segments": [ { "segment": [start, end], "text": ... }, ... ], "query_text": "