download_file change
Browse files16 unmodified lines17181920212223242526272829303132333435106 unmodified lines14214314414514614714816 unmodified linesdef download_file(task_id, filename, save_dir="attachments"):os.makedirs(save_dir, exist_ok=True)url = f"https://agents-course-unit4-scoring.hf.space/files/{task_id}"save_path = os.path.join(save_dir, filename)print(f"[DEBUG] Try download: url={url} save_path={save_path}")try:resp = requests.get(url, timeout=15)print(f"[DEBUG] HTTP {resp.status_code} for {url}")resp.raise_for_status()with open(save_path, "wb") as f:f.write(resp.content)print(f"Downloaded attachment for task {task_id} -> {save_path}")return save_pathexcept Exception as e:print(f"Attachment download failed for {task_id}: {e}")return Noneclass BasicAgent:106 unmodified linesresults_log = []answers_payload = []print(f"Running agent on {len(questions_data)} questions...")for idx, item in enumerate(questions_data[:1]):task_id = item.get("task_id")question_text = item.get("question")file_list = item.get("files", [])16 unmodified lines1718192021222324252627282930313233343536373839404142434445106 unmodified lines15215315415515615715816 unmodified linesdef download_file(task_id, filename, save_dir="attachments"):os.makedirs(save_dir, exist_ok=True)url = f"https://agents-course-unit4-scoring.hf.space/files/{task_id}/{filename}"save_path = os.path.join(save_dir, filename)print(f"[DEBUG] Try download: url={url} save_path={save_path}")try:resp = requests.get(url, timeout=30)print(f"[DEBUG] HTTP {resp.status_code} for {url}")resp.raise_for_status()if resp.headers.get('content-type', '').startswith('text/html'):print(f"Warning: Received HTML response, file might not exist: {filename}")return Nonewith open(save_path, "wb") as f:f.write(resp.content)print(f"Downloaded attachment for task {task_id} -> {save_path}")return save_pathexcept requests.exceptions.HTTPError as e:if e.response.status_code == 404:print(f"File not found: {filename} for task {task_id}")else:print(f"HTTP error downloading {filename}: {e}")return Noneexcept Exception as e:print(f"Attachment download failed for {task_id}/{filename}: {e}")return Noneclass BasicAgent:106 unmodified linesresults_log = []answers_payload = []print(f"Running agent on {len(questions_data)} questions...")for idx, item in enumerate(questions_data[3:4]):task_id = item.get("task_id")question_text = item.get("question")file_list = item.get("files", [])
app.py+15-5