diff --git a/gradio/inputs.py b/gradio/inputs.py index 62fac86a19..3da585f1ba 100644 --- a/gradio/inputs.py +++ b/gradio/inputs.py @@ -67,7 +67,7 @@ class AbstractInput(ABC): """ All interfaces should define a method that rebuilds the flagged input when it's passed back (i.e. rebuilds image from base64) """ - pass + return msg class Textbox(AbstractInput): """ @@ -356,6 +356,16 @@ class Sketchpad(AbstractInput): def process_example(self, example): return preprocessing_utils.convert_file_to_base64(example) + def rebuild_flagged(self, dir, msg): + """ + Default rebuild method to decode a base64 image + """ + im = preprocessing_utils.decode_base64_to_image(msg) + 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 Webcam(AbstractInput): """ @@ -393,6 +403,16 @@ class Webcam(AbstractInput): im, (self.image_width, self.image_height)) return np.array(im) + def rebuild_flagged(self, dir, msg): + """ + Default rebuild method to decode a base64 image + """ + im = preprocessing_utils.decode_base64_to_image(msg) + 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 Microphone(AbstractInput): """ diff --git a/gradio/outputs.py b/gradio/outputs.py index 553b93c7b3..5e9735991b 100644 --- a/gradio/outputs.py +++ b/gradio/outputs.py @@ -48,7 +48,7 @@ class AbstractOutput(ABC): """ All interfaces should define a method that rebuilds the flagged input when it's passed back (i.e. rebuilds image from base64) """ - pass + return msg class Textbox(AbstractOutput):