cog
cog copied to clipboard
document how upload-url works
cog still supports upload files outside of replicate :yay:
- start cog server with flag
--upload-url=http://host/:port/basepath
- run http server listening on
host:port
- PUT /path/... should write file to disk
- GET /path/... should return the file
- when you make a prediction you need to include output_file_prefix
- this needs to match
http://host/:port/basepath
and then include any additional information to uniqueify - example:
http://host/:port/basepath/{uuid}-
where the client has to decide the uuid
A simple http server I wrote to test this
from http.server import BaseHTTPRequestHandler, HTTPServer
import os
class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
def _file_path(self):
path = os.getcwd() + self.path
print(path)
return path
def do_GET(self):
file_path = self._file_path()
if not os.path.exists(file_path):
self.send_response(404)
self.end_headers()
return
with open(file_path, 'rb') as file:
self.send_response(200)
self.send_header('Content-type', 'text/plain')
self.end_headers()
self.wfile.write(file.read())
def do_PUT(self):
file_path = self._file_path()
file_length = int(self.headers['Content-Length'])
with open(file_path, 'wb') as file:
file.write(self.rfile.read(file_length))
self.send_response(200)
self.end_headers()
def run(server_class=HTTPServer, handler_class=SimpleHTTPRequestHandler):
server_address = ('', 4321)
httpd = server_class(server_address, handler_class)
httpd.serve_forever()
if __name__ == '__main__':
run()
I checked the code, when using async prediction, output_file_prefix is ignored. They didn't even use it. I want to add a uuid in the path, and I don't know how to do it...