mirror of
https://github.com/gradio-app/gradio.git
synced 2025-03-07 11:46:51 +08:00
same for outputs
This commit is contained in:
parent
ea09fce16e
commit
b26355b851
@ -568,13 +568,6 @@ class Carousel(OutputComponent):
|
||||
**super().get_template_context()
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def get_shortcut_implementations(cls):
|
||||
return {
|
||||
"carousel": {},
|
||||
}
|
||||
|
||||
|
||||
def postprocess(self, y):
|
||||
if isinstance(y, list):
|
||||
if len(y) != 0 and not isinstance(y[0], list):
|
||||
@ -605,9 +598,12 @@ def get_output_instance(iface):
|
||||
return shortcut[0](**shortcut[1])
|
||||
elif isinstance(iface, dict): # a dict with `name` as the output component type and other keys as parameters
|
||||
name = iface.pop('name')
|
||||
component, params = OutputComponent.get_all_shortcut_implementations()[name]
|
||||
params.update(**iface)
|
||||
return component(**params)
|
||||
for component in OutputComponent.__subclasses__():
|
||||
if component.__name__.lower() == name:
|
||||
break
|
||||
else:
|
||||
raise ValueError("No such OutputComponent: {}".format(name))
|
||||
return component(**iface)
|
||||
elif isinstance(iface, OutputComponent):
|
||||
return iface
|
||||
else:
|
||||
|
@ -162,7 +162,7 @@ class TestSequential(unittest.TestCase):
|
||||
self.assertEqual(iface.process([x_data])[0], ["Sal"])
|
||||
|
||||
class TestNames(unittest.TestCase):
|
||||
def test_no_duplicate_uncased_names(self):
|
||||
def test_no_duplicate_uncased_names(self): # this ensures that get_input_instance() works correctly when instantiating from components
|
||||
subclasses = gr.inputs.InputComponent.__subclasses__()
|
||||
unique_subclasses_uncased = set([s.__name__.lower() for s in subclasses])
|
||||
self.assertEqual(len(subclasses), len(unique_subclasses_uncased))
|
||||
|
@ -188,6 +188,11 @@ class TestDataframe(unittest.TestCase):
|
||||
iface.process([[2, 3, 4]])[0][0],
|
||||
{"data": [[True, False, True]]})
|
||||
|
||||
class TestNames(unittest.TestCase):
|
||||
def test_no_duplicate_uncased_names(self): # this ensures that get_input_instance() works correctly when instantiating from components
|
||||
subclasses = gr.outputs.OutputComponent.__subclasses__()
|
||||
unique_subclasses_uncased = set([s.__name__.lower() for s in subclasses])
|
||||
self.assertEqual(len(subclasses), len(unique_subclasses_uncased))
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Loading…
Reference in New Issue
Block a user