JabrilJacobs commited on
Commit
94d5f0f
·
verified ·
1 Parent(s): dc2af28

Update tools.py

Browse files
Files changed (1) hide show
  1. tools.py +23 -0
tools.py CHANGED
@@ -7,6 +7,29 @@ from typing import TypedDict, Annotated, Union, Dict, Any
7
  import base64
8
  from langchain_core.messages import HumanMessage
9
  from langchain_openai import ChatOpenAI
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
  def get_hub_stats(author: str) -> str:
12
  """Fetches the most downloaded model from a specific author on the Hugging Face Hub."""
 
7
  import base64
8
  from langchain_core.messages import HumanMessage
9
  from langchain_openai import ChatOpenAI
10
+ import requests
11
+ import os
12
+
13
+ def download_file(task_id: str, file_name: str) -> str:
14
+ """Downloads a file associated with a task_id and returns the local file path"""
15
+ try:
16
+ # Create downloads directory if it doesn't exist
17
+ os.makedirs("downloads", exist_ok=True)
18
+
19
+ # Download the file
20
+ file_url = f"https://agents-course-unit4-scoring.hf.space/files/{task_id}"
21
+ response = requests.get(file_url)
22
+ response.raise_for_status()
23
+
24
+ # Save the file locally
25
+ local_path = os.path.join("downloads", file_name)
26
+ with open(local_path, "wb") as f:
27
+ f.write(response.content)
28
+
29
+ return local_path
30
+
31
+ except Exception as e:
32
+ return f"Error downloading file: {str(e)}"
33
 
34
  def get_hub_stats(author: str) -> str:
35
  """Fetches the most downloaded model from a specific author on the Hugging Face Hub."""