import json, argparse, pandas as pd import os import requests from dotenv import load_dotenv load_dotenv() from agent import OptimaAgent DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space" DOWNLOAD_DIR = "downloaded_files" # Files downloaded by run_local.py go here directly DATA_DIR = "data" # Root for persistent data like videos and frames (task_id structured) def main(file: str): # Ensure root download and data directories exist os.makedirs(DOWNLOAD_DIR, exist_ok=True) os.makedirs(DATA_DIR, exist_ok=True) # Further subdirectories like data/videos or data/frames will be created by tools agent = OptimaAgent() print(f"Processing questions from file: {file}...") qs = json.load(open(file)) rows = [] for item in qs: print("processing item:", item) file_path = None task_id = item["task_id"] if "file_name" in item and item["file_name"]: file_name = item["file_name"] # This is usually . file_url = f"{DEFAULT_API_URL}/files/{task_id}" # Save directly into DOWNLOAD_DIR local_file_path = os.path.join(DOWNLOAD_DIR, file_name) print(f"Downloading file for task {task_id}: {file_name} to {local_file_path}...") try: response = requests.get(file_url, stream=True) response.raise_for_status() with open(local_file_path, "wb") as f: for chunk in response.iter_content(chunk_size=8192): f.write(chunk) print(f"Successfully downloaded to {local_file_path}") file_path = local_file_path except requests.exceptions.RequestException as e: print(f"Error downloading file for task {task_id}: {e}") # Call agent with question, task_id, and potential file path answer = agent(item["question"], task_id=task_id, file_path=file_path) rows.append( { "task_id": task_id, "question": item["question"][:60] + "…", "answer": answer, } ) print(pd.DataFrame(rows)) print("DONE") if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument( "-f", "--file", default="questions.json", help="Path to the questions JSON file.", ) main(**vars(parser.parse_args()))