|
from huggingface_hub import snapshot_download |
|
import os |
|
import shutil |
|
|
|
def download_space_repo(space_id: str, local_dir: str = "repo_files"): |
|
""" |
|
Downloads all files from a Hugging Face Space repository. |
|
|
|
Args: |
|
space_id (str): The ID of the Hugging Face Space (e.g., "naman1102/Final_Assignment_Template"). |
|
local_dir (str): Local directory to store the downloaded files. |
|
""" |
|
print(f"Downloading Space '{space_id}'...") |
|
|
|
|
|
repo_path = snapshot_download(repo_id=space_id, repo_type="space") |
|
|
|
|
|
if os.path.exists(local_dir): |
|
shutil.rmtree(local_dir) |
|
|
|
|
|
shutil.copytree(repo_path, local_dir) |
|
|
|
print(f"All files from Space '{space_id}' downloaded to: {local_dir}") |
|
|
|
|
|
|
|
|
|
from huggingface_hub import list_spaces |
|
|
|
def search_top_spaces(query: str, limit: int = 5): |
|
""" |
|
Search and return top Hugging Face Space repo IDs based on a keyword. |
|
|
|
Args: |
|
query (str): The keyword to search for (e.g., "image", "chatbot"). |
|
limit (int): Maximum number of results to return. |
|
|
|
Returns: |
|
List of repo IDs. |
|
""" |
|
results = list(list_spaces(search=query, sort="likes", direction=-1)) |
|
top_spaces = [space.id for space in results[:limit]] |
|
|
|
return top_spaces |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|