navodit17's picture
agent with search, file read, youtube
396f5a0
import requests
import os
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
files_folder = "gaia_files"
os.makedirs(files_folder, exist_ok=True)
def download_file_if_any(task_id: str) -> str:
url = f"{DEFAULT_API_URL}/files/{task_id}"
try:
response = requests.get(url)
response.raise_for_status()
content_disposition = response.headers.get("content-disposition")
filename = content_disposition.split("filename=")[1].strip('"') if content_disposition and "filename=" in content_disposition else None
if filename:
# path relative from app.py
file_path = os.path.join(files_folder, filename)
with open(file_path, "wb") as file:
file.write(response.content)
return str(file_path)
else:
return None
except requests.exceptions.RequestException as e:
print(f"Error making request: {e}")
return None
except ValueError as e:
print(f"Error decoding JSON response: {e}")
return None
if __name__ == "__main__":
print(download_file_if_any("f918266a-b3e0-4914-865d-4faa564f1aef"))