download_file change
Browse files16 unmodified lines171819202021222324242526272829302731323334353637383940413242434445106 unmodified lines15215315414515515615715816 unmodified lines
def 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}" 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=15) 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 None with open(save_path, "wb") as f: with open(save_path, "wb") as f: f.write(resp.content) print(f"Downloaded attachment for task {task_id} -> {save_path}") return save_path except 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 None except Exception as e: print(f"Attachment download failed for {task_id}: {e}") print(f"Attachment download failed for {task_id}/{filename}: {e}") return None
class BasicAgent:106 unmodified lines results_log = [] answers_payload = [] print(f"Running agent on {len(questions_data)} questions...") for idx, item in enumerate(questions_data[:1]): 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