-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Blocks rendering fix #1102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Blocks rendering fix #1102
Changes from all commits
7b633e0
17708e5
6a6d982
db03987
fe89a14
6f4a5dd
dffeeb8
099fea3
ef116cb
73246b4
bea44e4
6b0a5a3
898c24e
a06d284
c9d9657
0ff1752
7504e61
83ce8d5
82580b2
af37bba
3a16a76
bebe7ef
53d14df
a39ddd5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import gradio as gr | ||
|
|
||
| identity_demo, input_demo, output_demo = gr.Blocks(), gr.Blocks(), gr.Blocks() | ||
|
|
||
| with identity_demo: | ||
| gr.Interface(lambda x:x, "text", "text") | ||
|
|
||
| with input_demo: | ||
| t = gr.Textbox(label="Enter your text here") | ||
| with gr.Row(): | ||
| btn = gr.Button("Submit") | ||
| clr = gr.Button("Clear") | ||
| clr.click(lambda x: "", t, t) | ||
|
|
||
| with output_demo: | ||
| gr.Textbox("This is a static output") | ||
|
|
||
| with gr.Blocks() as demo: | ||
| gr.Markdown("Three demos in one!") | ||
| with gr.Tabs(): | ||
| with gr.TabItem("Text Identity"): | ||
| identity_demo.render() | ||
| with gr.TabItem("Text Input"): | ||
| input_demo.render() | ||
| with gr.TabItem("Text Static"): | ||
| output_demo.render() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| demo.launch() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,10 +34,9 @@ def __init__( | |
| self, | ||
| *, | ||
| css: Optional[Dict] = None, | ||
| without_rendering: bool = False, | ||
| **kwargs, | ||
| ): | ||
| super().__init__(without_rendering=without_rendering, css=css, **kwargs) | ||
| super().__init__(css=css, **kwargs) | ||
|
|
||
| def __str__(self): | ||
| return self.__repr__() | ||
|
|
@@ -3091,7 +3090,6 @@ def __init__( | |
| self, | ||
| default_value: str = "", | ||
| *, | ||
| label: Optional[str] = None, | ||
| css: Optional[Dict] = None, | ||
| **kwargs, | ||
| ): | ||
|
|
@@ -3101,7 +3099,7 @@ def __init__( | |
| label (str): component name | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need to update docstring with the label's removal |
||
| css (dict): optional css parameters for the component | ||
| """ | ||
| super().__init__(label=label, css=css, **kwargs) | ||
| super().__init__(css=css, **kwargs) | ||
| self.md = MarkdownIt() | ||
| unindented_default_value = inspect.cleandoc(default_value) | ||
| self.default_value = self.md.render(unindented_default_value) | ||
|
|
@@ -3194,11 +3192,10 @@ def __init__( | |
| components: List[Component], | ||
| samples: List[List[Any]], | ||
| type: str = "values", | ||
| label: Optional[str] = None, | ||
| css: Optional[Dict] = None, | ||
| **kwargs, | ||
| ): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not related to this PR but, Dataset has no docstring, let's add one? |
||
| super().__init__(label=label, css=css, **kwargs) | ||
| super().__init__(css=css, **kwargs) | ||
| self.components = components | ||
| self.type = type | ||
| self.headers = [c.label for c in components] | ||
|
|
@@ -3275,11 +3272,10 @@ def __init__( | |
| self, | ||
| component: Component, | ||
| *, | ||
| label: Optional[str] = None, | ||
| css: Optional[Dict] = None, | ||
| **kwargs, | ||
| ): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not related to this PR but, Interpretation has no docstring, let's add one? |
||
| super().__init__(label=label, css=css, **kwargs) | ||
| super().__init__(css=css, **kwargs) | ||
| self.component = component | ||
|
|
||
| def get_template_context(self): | ||
|
|
@@ -3343,13 +3339,12 @@ def component(cls_name: str): | |
|
|
||
| def get_component_instance(comp: str | dict | Component): | ||
| if isinstance(comp, str): | ||
| return component(comp)() | ||
| elif isinstance( | ||
| comp, dict | ||
| ): # a dict with `name` as the input component type and other keys as parameters | ||
| component_cls = component(comp) | ||
| return component_cls() | ||
| elif isinstance(comp, dict): | ||
| name = comp.pop("name") | ||
| component_cls = component(name) | ||
| return component_cls(**comp, without_rendering=True) | ||
| return component_cls(**comp) | ||
| elif isinstance(comp, Component): | ||
| return comp | ||
| else: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.