Skip to content

Commit

Permalink
Merge pull request #84 from ScottyB/quality/for-demo
Browse files Browse the repository at this point in the history
Quality/for demo
  • Loading branch information
ScottyB authored Mar 21, 2019
2 parents 8c05861 + fe4ac6d commit 03455f0
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 17 deletions.
5 changes: 3 additions & 2 deletions surround/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
],
"files": [
("requirements.txt", "surround==0.0.3\ntornado==6.0.1"),
("{project_name}/config.yaml", "output:\n text: Hello World"),
(".surround/config.yaml", "project-info:\n project-name: {project_name}")
],
"templates" : [
Expand All @@ -42,7 +41,9 @@
("{project_name}/wrapper.py", "wrapper.py.txt", True),
("upload.html", "upload.html.txt", False),
("dodo.py", "dodo.py.txt", False),
("Dockerfile", "Dockerfile.txt", False)
("Dockerfile", "Dockerfile.txt", False),
("{project_name}/config.yaml", "config.yaml.txt", False)

]
}
}
Expand Down
2 changes: 1 addition & 1 deletion surround/defaults.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
company: a2i2
image: dock
version: latest
image: surround

surround:
stages: false
Expand Down
7 changes: 4 additions & 3 deletions surround/runner/web/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ def initialize(self, wrapper):

def post(self):
print("info: started post request at /predict")
output = None
if self.wrapper.type_of_uploaded_object == AllowedTypes.IMAGE:
fileinfo = self.request.files['data'][0]
self.wrapper.process(fileinfo['body'])
output = self.wrapper.process(fileinfo['body'])
else:
self.wrapper.process(None)
self.write("Task executed successfully")
output = self.wrapper.process(self.request.body)
self.write({"output": output})
print("info: finished post request at /predict")

def make_app(wrapper_object):
Expand Down
5 changes: 4 additions & 1 deletion surround/surround.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,7 @@ def validate_type_of_uploaded_object(self):

def process(self, input_data):
Wrapper.run(self, input_data)
self.run(input_data)
return self.run(input_data)

def get_config(self):
return self.surround.config
2 changes: 1 addition & 1 deletion surround/tests/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_merging_config(self):
config.read_config_files([self.f1.name, self.f2.name])
output = {
'company': 'a2i2',
'image': 'dock',
'image': 'surround',
'version': 'latest',
'surround' : {
"stages" : False,
Expand Down
6 changes: 6 additions & 0 deletions templates/new/config.yaml.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
output:
text: Hello World

image: {project_name}
company: yourcompany
version: latest
9 changes: 7 additions & 2 deletions templates/new/main.py.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import logging
from .wrapper import PipelineWrapper

import os
import json
logging.basicConfig(level=logging.INFO)

def main():
wrapper = PipelineWrapper()
wrapper.run(None)
config = wrapper.get_config()
output = wrapper.run(json.dumps({{"data": "hello"}}))
with open(os.path.join(config["output_path"], "output.txt"), 'w') as f:
f.write(output["output"])
logging.info(output)

if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions templates/new/stages.py.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class {project_name}Data(SurroundData):

def __init__(self, input_data):
self.input_data = input_data
self.errors = []

class ValidateData(Stage):
def operate(self, surround_data, config):
Expand Down
12 changes: 5 additions & 7 deletions templates/new/wrapper.py.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import os
import json
from surround import Surround, Wrapper, AllowedTypes
from stages import ValidateData, {project_name}Data

class PipelineWrapper(Wrapper):
def __init__(self):
surround = Surround([ValidateData()], __name__)
type_of_uploaded_object = AllowedTypes.IMAGE
self.config = surround.config
super().__init__(surround, type_of_uploaded_object)
super().__init__(surround)

def run(self, input_data):
data = {project_name}Data(input_data)
text = json.loads(input_data)["data"]
data = {project_name}Data(text)
self.surround.process(data)

with open(os.path.abspath(os.path.join(self.config["output_path"], "output.txt")), 'w') as f:
f.write(data.output_data)
return {{"output": data.output_data}}
4 changes: 4 additions & 0 deletions templates/tutorial/config.yaml.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
output:
text: Hello World

image: {project_name}

0 comments on commit 03455f0

Please sign in to comment.