| import os | |
| import asyncio | |
| from huggingface_hub import HfApi | |
| api = HfApi() | |
| async def upload_to_dataset(local_path, md5_name, original_name, repo_id, token): | |
| if not token or not os.path.exists(local_path): return | |
| try: | |
| await asyncio.to_thread(api.upload_file, path_or_fileobj=local_path, path_in_repo=md5_name, repo_id=repo_id, repo_type="dataset", commit_message=f"Upload {original_name}", token=token) | |
| os.remove(local_path) | |
| except Exception: pass |