mirror of
https://github.com/gradio-app/gradio.git
synced 2024-12-27 02:30:17 +08:00
restore rebuild function
This commit is contained in:
parent
6dfe1dc3f8
commit
076f4c74d2
@ -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.
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user