Upload Upload-Post smolagents tool
Browse files- app.py +5 -0
- requirements.txt +2 -0
- tool.py +36 -0
app.py
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from smolagents import launch_gradio_demo
|
| 2 |
+
from tool import UploadPostStatusTool
|
| 3 |
+
|
| 4 |
+
tool = UploadPostStatusTool()
|
| 5 |
+
launch_gradio_demo(tool)
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
smolagents
|
| 2 |
+
upload_post
|
tool.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Any, Optional
|
| 2 |
+
from smolagents.tools import Tool
|
| 3 |
+
import upload_post
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
class UploadPostStatusTool(Tool):
|
| 7 |
+
name = "upload_post_status"
|
| 8 |
+
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."
|
| 9 |
+
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}}
|
| 10 |
+
output_type = "object"
|
| 11 |
+
|
| 12 |
+
def __init__(self, api_key=None):
|
| 13 |
+
super().__init__()
|
| 14 |
+
import os
|
| 15 |
+
|
| 16 |
+
self.api_key = api_key or os.environ.get("UPLOAD_POST_API_KEY")
|
| 17 |
+
self.client = None
|
| 18 |
+
|
| 19 |
+
def setup(self):
|
| 20 |
+
from upload_post import UploadPostClient
|
| 21 |
+
|
| 22 |
+
if not self.api_key:
|
| 23 |
+
raise ValueError(
|
| 24 |
+
"Missing Upload-Post API key: pass api_key=... or set UPLOAD_POST_API_KEY."
|
| 25 |
+
)
|
| 26 |
+
self.client = UploadPostClient(self.api_key)
|
| 27 |
+
self.is_initialized = True
|
| 28 |
+
|
| 29 |
+
def forward(self, request_id: Optional[str] = None, job_id: Optional[str] = None) -> Any:
|
| 30 |
+
if not self.is_initialized:
|
| 31 |
+
self.setup()
|
| 32 |
+
if request_id:
|
| 33 |
+
return self.client.get_status(request_id)
|
| 34 |
+
if job_id:
|
| 35 |
+
return self.client.get_job_status(job_id)
|
| 36 |
+
raise ValueError("Provide either request_id or job_id.")
|