-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from AkshatBajaj/feature/web-adapter
NEW: Predict Endpoint
- Loading branch information
Showing
37 changed files
with
315 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.doit.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
project-info: | ||
project-name: hello_world_web |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Run project | ||
`cd examples/hello_world_web` | ||
`surround run dev` |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
DOIT_CONFIG = {'verbosity':2} | ||
|
||
def task_dev(): | ||
"""Run the main task for the project""" | ||
return { | ||
'actions': ["python3 -m hello-world-web"], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import os | ||
import sys | ||
|
||
sys.path.append(os.path.dirname(os.path.realpath(__file__))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import logging | ||
from .wrapper import PipelineWrapper | ||
|
||
logging.basicConfig(level=logging.INFO) | ||
|
||
def main(): | ||
wrapper = PipelineWrapper() | ||
wrapper.run(None) | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
output: | ||
text: Hello World |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from surround import Stage, SurroundData | ||
|
||
class HelloStage(Stage): | ||
def operate(self, surround_data, config): | ||
surround_data.text = "hello" | ||
|
||
class BasicData(SurroundData): | ||
text = None | ||
|
||
def __init__(self, input_data): | ||
self.input_data = input_data | ||
|
||
class RotateImage(Stage): | ||
def operate(self, surround_data, config): | ||
"""Add operate code | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from surround import Surround, Wrapper, AllowedTypes | ||
from stages import HelloStage, RotateImage, BasicData | ||
|
||
class PipelineWrapper(Wrapper): | ||
def __init__(self): | ||
surround = Surround([HelloStage(), RotateImage()]) | ||
type_of_uploaded_object = AllowedTypes.IMAGE | ||
self.config = surround.config | ||
super().__init__(surround, type_of_uploaded_object) | ||
|
||
def run(self, input_data): | ||
data = BasicData(input_data) | ||
self.surround.process(data) |
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
surround==0.0.2 |
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<html> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> | ||
<title>Upload Form</title> | ||
</head> | ||
<body> | ||
<p><h1>Select & Upload</h1></p> | ||
<form enctype="multipart/form-data" action="/predict" method="post"> | ||
File: <input type="file" name="data" /> | ||
<br /> | ||
<br /> | ||
<input type="submit" value="upload" /> | ||
</form> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
from .surround import Surround, SurroundData | ||
from .surround import Surround, SurroundData, Wrapper, AllowedTypes | ||
from .stage import Stage | ||
from .config import Config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import datetime | ||
import os | ||
import tornado.ioloop | ||
import tornado.web | ||
import pkg_resources | ||
from surround import AllowedTypes | ||
|
||
# Get time for uptime calculation. | ||
START_TIME = datetime.datetime.now() | ||
|
||
class HealthCheck(tornado.web.RequestHandler): | ||
def get(self): | ||
print("info: started get request at /") | ||
self.write(dict( | ||
app="Surround Server", | ||
version=pkg_resources.get_distribution("surround").version, | ||
uptime=str(datetime.datetime.now() - START_TIME) | ||
)) | ||
print("info: finished get request at /") | ||
|
||
class Upload(tornado.web.RequestHandler): | ||
def get_template_path(self): | ||
return os.getcwd() | ||
|
||
def get(self): | ||
print("info: started get request at /upload") | ||
self.render("upload.html") | ||
print("info: finished get request at /upload") | ||
|
||
class Predict(tornado.web.RequestHandler): | ||
def initialize(self, wrapper): | ||
self.wrapper = wrapper | ||
|
||
def post(self): | ||
print("info: started post request at /predict") | ||
if self.wrapper.type_of_uploaded_object == AllowedTypes.IMAGE: | ||
fileinfo = self.request.files['data'][0] | ||
self.wrapper.process(fileinfo['body']) | ||
else: | ||
self.wrapper.process(None) | ||
self.write("Task executed successfully") | ||
print("info: finished post request at /predict") | ||
|
||
def make_app(wrapper_object): | ||
predict_init_args = dict(wrapper=wrapper_object) | ||
|
||
return tornado.web.Application([ | ||
(r"/", HealthCheck), | ||
(r"/upload", Upload), | ||
(r"/predict", Predict, predict_init_args), | ||
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import os | ||
import sys | ||
|
||
sys.path.append(os.path.dirname(os.path.realpath(__file__))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,11 @@ | ||
import logging | ||
import argparse | ||
import os | ||
from surround import Surround | ||
from .stages import ValidateData, {project_name}Data | ||
from .wrapper import PipelineWrapper | ||
|
||
logging.basicConfig(level=logging.INFO) | ||
|
||
def main(): | ||
surround = Surround([ValidateData()], __name__) | ||
config = surround.config | ||
|
||
# TODO: Read data from input directory here | ||
# os.path.join(config["data_path"], "your file here") | ||
|
||
data = {project_name}Data("data") | ||
surround.process(data) | ||
with open(os.path.abspath(os.path.join(config["output_path"], "output.txt")), 'w') as f: | ||
f.write(data.output_data) | ||
logging.info(data.output_data) | ||
wrapper = PipelineWrapper() | ||
wrapper.run(None) | ||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.