diff --git a/server/README.md b/server/README.md index 8edaf9ce79c40a1b5ef075cf6d25313ce43bdcf3..c42eb5e76f23a48a2bfedd237dd9bb6b91b5a9a2 100644 --- a/server/README.md +++ b/server/README.md @@ -19,8 +19,7 @@ python ../tools/dockrun.py process-local.py \ # run local server python ../tools/dockrun.py --port 8000 serve.py --local_models_dir models # test the local server -curl -X POST http://localhost:8000/example \ - --data-binary @static/facades-input.png >! output.png +python ../tools/dockrun.py process-remote.py --input_file static/facades-input.png --url http://localhost:8000/example --output_file output.png ``` If you open [http://localhost:8000/](http://localhost:8000/) in a browser, you should see an interactive demo, though this expects the server to be hosting the exported models available here: diff --git a/server/process-remote.py b/server/process-remote.py new file mode 100644 index 0000000000000000000000000000000000000000..44fa99aeff33a5a0191a415d9a2980a04ed2bf6e --- /dev/null +++ b/server/process-remote.py @@ -0,0 +1,25 @@ +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import urllib +import argparse + + +parser = argparse.ArgumentParser() +parser.add_argument("--input_file", required=True, help="input PNG image file") +parser.add_argument("--url", required=True, help="url to use for processing") +parser.add_argument("--output_file", required=True, help="output PNG image file") +a = parser.parse_args() + + +def main(): + with open(a.input_file) as f: + input_data = f.read() + + output_data = urllib.urlopen(a.url, data=input_data).read() + + with open(a.output_file, "wb") as f: + f.write(output_data) + +main() \ No newline at end of file diff --git a/tools/tfimage.py b/tools/tfimage.py index 8618f7acd5b13dfbc9c7852465d7b85b1f103db8..0c6f3d5f13f05958eab35c7ff6592c81c45c22ea 100644 --- a/tools/tfimage.py +++ b/tools/tfimage.py @@ -95,7 +95,9 @@ to_float32 = create_op( def load(path): - contents = open(path).read() + with open(path) as f: + contents = f.read() + _, ext = os.path.splitext(path.lower()) if ext == ".jpg":