Download tool.py from upload-post/upload-post-status-tool: direct link, hf CLI and curl.
- Browser
- Download file 1.56 kB
-
https://huggingface.co/spaces/upload-post/upload-post-status-tool/resolve/main/tool.py
- Command line
-
hf download hf://spaces/upload-post/upload-post-status-tool/tool.py
-
curl -L -o tool.py https://huggingface.co/spaces/upload-post/upload-post-status-tool/resolve/main/tool.py
1.56 kB
| from typing import Any, Optional | |
| from smolagents.tools import Tool | |
| import os | |
| import upload_post | |
| class UploadPostStatusTool(Tool): | |
| name = "upload_post_status" | |
| description = "Check the status of an Upload-Post upload. Pass the request_id returned by an upload, or the job_id returned by a scheduled or queued post. Returns a dict with the per-platform results, including the post URLs once published." | |
| inputs = {'request_id': {'type': 'string', 'description': 'request_id returned by an upload.', 'nullable': True}, 'job_id': {'type': 'string', 'description': 'job_id returned by a scheduled or queued upload.', 'nullable': True}} | |
| output_type = "object" | |
| def __init__(self, api_key=None, **kwargs): | |
| super().__init__() | |
| import os | |
| self.api_key = api_key or os.environ.get("UPLOAD_POST_API_KEY") | |
| self.client = None | |
| def setup(self): | |
| from upload_post import UploadPostClient | |
| if not self.api_key: | |
| raise ValueError( | |
| "Missing Upload-Post API key: pass api_key=... or set UPLOAD_POST_API_KEY." | |
| ) | |
| self.client = UploadPostClient(self.api_key) | |
| self.is_initialized = True | |
| def forward(self, request_id: Optional[str] = None, job_id: Optional[str] = None) -> Any: | |
| if not self.is_initialized: | |
| self.setup() | |
| if request_id: | |
| return self.client.get_status(request_id) | |
| if job_id: | |
| return self.client.get_job_status(job_id) | |
| raise ValueError("Provide either request_id or job_id.") | |