-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* readme * readme * updated images * updated images * removing gpuutil and allowing user to set gpuid * adding ai_application.py * add ai_application
- Loading branch information
Showing
2 changed files
with
38 additions
and
1 deletion.
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
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"}) |
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 +1 @@ | ||
__version__ = "1.3.25" | ||
__version__ = "1.3.26" |