Skip to content

Commit

Permalink
Fix test args parser
Browse files Browse the repository at this point in the history
This is a patch to fig a bug in test parser that keep piling up the test
args of the previous modules.

For example if the module loading order is image-classification and then
satellites, the image classification predict method module would show
the test args of image-classification but the satellites predict method
would show the test args of both satellites and image-classification.
  • Loading branch information
ignacio authored and alvarolopez committed Sep 4, 2019
1 parent 16beab1 commit 09f9c80
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions deepaas/api/v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
# License for the specific language governing permissions and limitations
# under the License.

import copy

import flask
import flask_restplus
from flask_restplus import fields
Expand Down Expand Up @@ -163,22 +165,24 @@ def get(self):
return m

# Fill the test parser with the supported arguments. Different models may
# have different arguments.
# have different arguments. We get here a copy of the original parser,
# since otherwise if we have several models the arguments will pile up.
test_parser = copy.deepcopy(data_parser)
test_args = model_obj.get_test_args()
for k, v in test_args.items():
data_parser.add_argument(k, **v)
test_parser.add_argument(k, **v)

@api.marshal_with(response, envelope='resource')
@api.route('/%s/predict' % model_name)
class ModelPredict(flask_restplus.Resource):
model_name = model_name
model_obj = model_obj

@api.expect(data_parser)
@api.expect(test_parser)
def post(self):
"""Make a prediction given the input data."""

args = data_parser.parse_args()
args = test_parser.parse_args()

if (not any([args["urls"], args["files"]]) or
all([args["urls"], args["files"]])):
Expand Down

0 comments on commit 09f9c80

Please sign in to comment.