Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files
main.py
CHANGED
@@ -75,55 +75,32 @@ def leaderboard_search(query: str) -> str:
|
|
75 |
@tool
|
76 |
def get_space_content(space_id: str) -> str:
|
77 |
"""
|
78 |
-
|
79 |
|
80 |
Args:
|
81 |
-
space_id: The Hugging Face Space
|
82 |
-
|
83 |
-
Returns:
|
84 |
-
The space content or error message
|
85 |
"""
|
86 |
try:
|
87 |
-
|
88 |
-
|
89 |
-
response = requests.get(readme_url)
|
90 |
-
|
91 |
if response.status_code == 200:
|
92 |
-
return
|
93 |
-
|
94 |
-
# Try to get any available file
|
95 |
-
files_url = f"https://huggingface.co/api/spaces/{space_id}/tree/main"
|
96 |
-
files_response = requests.get(files_url)
|
97 |
-
|
98 |
-
if files_response.status_code == 200:
|
99 |
-
files = files_response.json()
|
100 |
-
return f"Available files in {space_id}:\n" + "\n".join([f"- {file['path']}" for file in files])
|
101 |
-
else:
|
102 |
-
return f"Space {space_id} exists but couldn't retrieve content"
|
103 |
-
|
104 |
except Exception as e:
|
105 |
-
return f"Error
|
106 |
|
107 |
@tool
|
108 |
def download_space_files(
|
109 |
space_id: str,
|
110 |
-
revision: Optional[str] = None,
|
111 |
-
local_dir: Optional[Union[str, Path]] = None,
|
112 |
-
allow_patterns: Optional[Union[List[str], str]] = None,
|
113 |
-
ignore_patterns: Optional[Union[List[str], str]] = None,
|
114 |
force_download: bool = False,
|
115 |
max_workers: int = 8
|
116 |
) -> str:
|
117 |
"""
|
118 |
-
Download all files from a Hugging
|
119 |
|
120 |
Args:
|
121 |
space_id: e.g. "owner/my-awesome-space"
|
122 |
-
|
123 |
-
local_dir: where to put the files (defaults to HF cache)
|
124 |
-
allow_patterns: only download files matching these patterns
|
125 |
-
ignore_patterns: skip files matching these patterns
|
126 |
-
force_download: re‑download even if cached
|
127 |
max_workers: parallel downloads
|
128 |
|
129 |
Returns:
|
@@ -133,10 +110,6 @@ def download_space_files(
|
|
133 |
folder = snapshot_download(
|
134 |
repo_id=space_id,
|
135 |
repo_type="space",
|
136 |
-
revision=revision,
|
137 |
-
local_dir=local_dir,
|
138 |
-
allow_patterns=allow_patterns,
|
139 |
-
ignore_patterns=ignore_patterns,
|
140 |
force_download=force_download,
|
141 |
max_workers=max_workers
|
142 |
)
|
|
|
75 |
@tool
|
76 |
def get_space_content(space_id: str) -> str:
|
77 |
"""
|
78 |
+
Fetch the full HTML content of a Hugging Face Space webpage.
|
79 |
|
80 |
Args:
|
81 |
+
space_id: The id of the Hugging Face Space (e.g., "owner/my-awesome-space") to view online
|
|
|
|
|
|
|
82 |
"""
|
83 |
try:
|
84 |
+
url = f"https://huggingface.co/spaces/{space_id}"
|
85 |
+
response = requests.get(url)
|
|
|
|
|
86 |
if response.status_code == 200:
|
87 |
+
return response.text # Return raw HTML
|
88 |
+
return f"Failed to fetch page for '{space_id}', status code: {response.status_code}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
except Exception as e:
|
90 |
+
return f"Error fetching content for '{space_id}': {e}"
|
91 |
|
92 |
@tool
|
93 |
def download_space_files(
|
94 |
space_id: str,
|
|
|
|
|
|
|
|
|
95 |
force_download: bool = False,
|
96 |
max_workers: int = 8
|
97 |
) -> str:
|
98 |
"""
|
99 |
+
Download all files from a Hugging Face Space (snapshot).
|
100 |
|
101 |
Args:
|
102 |
space_id: e.g. "owner/my-awesome-space"
|
103 |
+
force_download: redownload even if cached
|
|
|
|
|
|
|
|
|
104 |
max_workers: parallel downloads
|
105 |
|
106 |
Returns:
|
|
|
110 |
folder = snapshot_download(
|
111 |
repo_id=space_id,
|
112 |
repo_type="space",
|
|
|
|
|
|
|
|
|
113 |
force_download=force_download,
|
114 |
max_workers=max_workers
|
115 |
)
|