Skip to content

Commit

Permalink
Add ai_application (#11)
Browse files Browse the repository at this point in the history
* readme

* readme

* updated images

* updated images

* removing gpuutil and allowing user to set gpuid

* adding ai_application.py

* add ai_application
  • Loading branch information
gregchu authored May 10, 2019
1 parent d9d4d96 commit d331461
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
37 changes: 37 additions & 0 deletions multivitamin/applications/ai_application.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import json
from abc import (ABC, abstractmethod)

import glog as log
from flask import jsonify

from multivitamin.data import Request, Response


class AiApplication(ABC):
'''
This class represent an AI Application. An AI Application is a list of modules to
iterate over.
'''
models = None # Where we keep the model when it's loaded

@abstractmethod
def get_modules(self):
pass

def predict(self, input):
try:
req = Request(input)
response = Response(req)

for module in self.get_modules():
log.debug(f"Processing request for module: {module}")
response = module.process(response)
log.debug(f"response.to_dict(): {json.dumps(response.to_dict(), indent=2)}")

if req.bin_encoding:
return response.to_bytes()
else:
return jsonify(response.to_dict())
except Exception:
log.exception(f"Error processing request {input}")
return jsonify({"error": "Could not process this request"})
2 changes: 1 addition & 1 deletion multivitamin/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.3.25"
__version__ = "1.3.26"

0 comments on commit d331461

Please sign in to comment.