Closed aliabd closed 2 years ago
That's a good point, creating a sketchpad is way too much effort. Maybe a generic Component()
which could take string shortcuts?
I think using strings for component names are not very proper and feels hacky to me. We can have these pre-prepared components in a class or in a file and import from there.
from gradio.component.Templates import Sketchpad
inputs = [Sketchpad()]
or
from gradio import Templates
inputs = [Templates.Sketchpad()]
or
from gradio.component import Sketchpad
inputs = [Sketchpad()]
String identifiers are pretty common practice in parameters the way we have them in inputs
and outputs
. For example, see https://keras.io/api/optimizers/ ("adam"
and Adam()
both work). I actually think they are part of the convenience of high level APIs like Keras and Gradio.
That being said, they are not very convenient in the Blocks context, since you can't just have a string by itself the way you could have a Class being instantiated. I think the approach you are suggesting @FarukOzderim make sense to me. I would prefer the last one, if possible, so that all of the components live in the same namespace. I think there is a small typo and it should read:
from gradio.component import Sketchpad
inputs = Sketchpad()
About this issue let's give the final decision
for blocks we want to have Template components that are implemented by us.
To clarify, how would this work? Would it be that we pass in Template("sketchpad")
and it renders the Image
component with the "sketchpad" parameters? If so, that seems reasonable to me.
What about Interface? Would you want to drop support shortcuts within Interface and move to Templates usage as well? Or still support shortcuts within Interface?
We should still support shortcuts within Interface: (a) because they make Interface easy to use for common use cases (b) backwards compatibility
Ok then;
from gradio import Sketchpad
sketchpad= Sketchpad()
Ah okay, got it! So Sketchpad
will subclass Image
, right? Sounds good to me.
cc @aliabid94
Yep I like @FarukOzderim suggestion
To distinguish real components and Custom or Template components I want to create a hierarchy and import mechanism like this, WDYT? The size of custom components can increase a lot in the future, we can even accept custom components from community.
Please also share your thoughts about naming
We could have
Template and Custom
as Template indicates preprepared components and Custom implies community designed components. Though Custom might not be necessary at all.from gradio import Templates
sketchpad = Templates.Sketchpad()
from gradio.Templates import Sketchpad
sketchpad = Sketchpad()
from gradio import CustomComponents
sketchpad = CustomComponents.Sketchpad()
To distinguish real components and Custom or Template components I want to create a hierarchy and import mechanism like this, WDYT? The size of custom components can increase a lot in the future, we can even accept custom components from community.
Sounds good to me. I prefer Templates
as it is shorter than CustomComponents
and a single word
@abidlabs @aliabd Would we want to have templates for these shortcuts?
Dataframe
{
"dataframe": {"type": "pandas"},
"numpy": {"type": "numpy"},
"matrix": {"type": "array"},
"list": {"type": "array", "col_count": 1},
}
I think we should. Not sure how commonly they are used, but there should be no harm in including them.
Can we support string shortcuts for components like in
Interface
?shortcuts like "sketchpad" save from having to define 4 parameters (
gr.inputs.Image(image_mode='L', source="canvas", shape=(28, 28), invert_colors=True)
)Not currently supported in blocks.