restore rebuild function

This commit is contained in:
Ali Abid 2021-01-29 07:25:54 -08:00
parent 6dfe1dc3f8
commit 076f4c74d2
4 changed files with 22 additions and 12 deletions

View File

@ -713,6 +713,17 @@ class Image(InputComponent):
im = processing_utils.resize_and_crop(im, (shape[0], shape[1]))
return np.asarray(im).flatten()
def rebuild(self, dir, data):
"""
Default rebuild method to decode a base64 image
"""
im = processing_utils.decode_base64_to_image(data)
timestamp = datetime.datetime.now()
filename = f'input_{timestamp.strftime("%Y-%m-%d-%H-%M-%S")}.png'
im.save(f'{dir}/{filename}', 'PNG')
return filename
class Video(InputComponent):
"""
Component creates a video file upload that is converted to a file path.

View File

@ -172,16 +172,7 @@ class Interface:
pass
if self.allow_flagging:
if self.title is not None:
dir_name = "_".join(self.title.split(" "))
else:
dir_name = "_".join([fn.__name__ for fn in self.predict])
index = 1
while os.path.exists(self.flagging_dir + "/" + dir_name +
"_{}".format(index)):
index += 1
self.flagging_dir = self.flagging_dir + "/" + dir_name + \
"_{}".format(index)
os.makedirs(self.flagging_dir, exist_ok=True)
if self.analytics_enabled:
try:

View File

@ -210,8 +210,6 @@ def predict_examples():
def flag():
log_feature_analytics('flag')
flag_path = os.path.join(app.cwd, app.interface.flagging_dir)
os.makedirs(flag_path,
exist_ok=True)
output = {'inputs': [app.interface.input_interfaces[
i].rebuild(
flag_path, request.json['data']['input_data'][i]) for i

View File

@ -186,6 +186,16 @@ class Image(OutputComponent):
raise ValueError("Unknown type: " + dtype + ". Please choose from: 'numpy', 'pil', 'file', 'plot'.")
return out_y, coordinates
def rebuild(self, dir, data):
"""
Default rebuild method to decode a base64 image
"""
im = processing_utils.decode_base64_to_image(data)
timestamp = datetime.datetime.now()
filename = 'output_{}_{}.png'.format(self.label, timestamp.strftime("%Y-%m-%d-%H-%M-%S"))
im.save('{}/{}'.format(dir, filename), 'PNG')
return filename
class Video(OutputComponent):
'''
Used for video output.