mirror of
https://github.com/gradio-app/gradio.git
synced 2025-03-13 11:57:29 +08:00
added rebuild flagged to inputs/outputs
This commit is contained in:
parent
b9a3b62fc1
commit
593af4ebf6
@ -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):
|
||||
"""
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user