Skip to content

Commit

Permalink
added rebuild flagged to inputs/outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
aliabd committed Jul 27, 2020
1 parent b9a3b62 commit 593af4e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
22 changes: 21 additions & 1 deletion gradio/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def rebuild_flagged(self, dir, msg):
"""
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):
"""
Expand Down Expand Up @@ -356,6 +356,16 @@ def preprocess(self, inp):
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):
"""
Expand Down Expand Up @@ -393,6 +403,16 @@ def preprocess(self, inp):
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):
"""
Expand Down
2 changes: 1 addition & 1 deletion gradio/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def rebuild_flagged(self, dir, msg):
"""
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):
Expand Down

0 comments on commit 593af4e

Please sign in to comment.