From f071a23c12218033ee947d9913328efebc90af97 Mon Sep 17 00:00:00 2001
From: Christopher Hesse <christopher.hesse@gmail.com>
Date: Wed, 22 Feb 2017 22:49:22 -0800
Subject: [PATCH] Add process-remote script

---
 server/README.md         |  3 +--
 server/process-remote.py | 25 +++++++++++++++++++++++++
 tools/tfimage.py         |  4 +++-
 3 files changed, 29 insertions(+), 3 deletions(-)
 create mode 100644 server/process-remote.py

diff --git a/server/README.md b/server/README.md
index 8edaf9c..c42eb5e 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 0000000..44fa99a
--- /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 8618f7a..0c6f3d5 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":
-- 
GitLab