Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions gradio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@
Carousel,
Chatbot,
Checkbox,
Checkboxgroup,
CheckboxGroup,
DataFrame,
Dataframe,
Dropdown,
File,
Gallery,
Highlightedtext,
HighlightedText,
Image,
Keyvalues,
KeyValues,
Label,
Markdown,
Expand All @@ -30,6 +34,7 @@
Slider,
StatusTracker,
Textbox,
TimeSeries,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why twuce, typo?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Different spelling (or casing actually)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TimeSeries vs Timeseries

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is what you're referring to, right?

Timeseries,
Variable,
Video,
Expand Down
8 changes: 6 additions & 2 deletions gradio/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ def set_event_trigger(
self,
event_name: str,
fn: Optional[Callable],
inputs: List[Component],
outputs: List[Component],
inputs: Optional[Component | List[Component]],
outputs: Optional[Component | List[Component]],
preprocess: bool = True,
postprocess: bool = True,
js: Optional[str] = False,
Expand All @@ -97,6 +97,10 @@ def set_event_trigger(
Returns: None
"""
# Support for singular parameter
if inputs is None:
inputs = []
if outputs is None:
outputs = []
if not isinstance(inputs, list):
inputs = [inputs]
if not isinstance(outputs, list):
Expand Down
21 changes: 16 additions & 5 deletions gradio/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -2754,11 +2754,6 @@ def postprocess(self, y):
return {"type": dtype, "plot": out_y}


############################
# Static Components
############################


class Markdown(Component):
"""
Used for Markdown output. Expects a valid string that is rendered into Markdown.
Expand All @@ -2781,13 +2776,22 @@ def __init__(
unindented_default_value = inspect.cleandoc(default_value)
self.default_value = self.md.render(unindented_default_value)

def postprocess(self, y):
unindented_y = inspect.cleandoc(y)
return self.md.render(unindented_y)

def get_template_context(self):
return {
"default_value": self.default_value,
**Component.get_template_context(self),
}


############################
# Static Components
############################


class Button(Clickable, Component):
"""
Used to create a button, that can be assigned arbitrary click() events.
Expand Down Expand Up @@ -2942,3 +2946,10 @@ def get_component_instance(comp: str | dict | Component):
raise ValueError(
f"Component must provided as a `str` or `dict` or `Component` but is {comp}"
)


DataFrame = Dataframe
Keyvalues = KeyValues
Highlightedtext = HighlightedText
Checkboxgroup = CheckboxGroup
TimeSeries = Timeseries
10 changes: 5 additions & 5 deletions gradio/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ def from_pipeline(cls, pipeline: transformers.Pipeline, **kwargs) -> Interface:
def __init__(
self,
fn: Callable | List[Callable],
inputs: Optional[str | Component | List[str | Component]] = None,
outputs: Optional[str | Component | List[str | Component]] = None,
inputs: Optional[str | Component | List[str | Component]],
outputs: Optional[str | Component | List[str | Component]],
examples: Optional[List[Any] | List[List[Any]] | str] = None,
cache_examples: Optional[bool] = None,
examples_per_page: int = 10,
Expand Down Expand Up @@ -166,12 +166,12 @@ def __init__(
)

self.interface_type = self.InterfaceTypes.STANDARD
if inputs is None and outputs is None:
if (inputs is None or inputs == []) and (outputs is None or outputs == []):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since you call super.init() first, you could just check if self.inputs == [].

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where in Blocks() do I assign self.inputs?

raise ValueError("Must provide at least one of `inputs` or `outputs`")
elif outputs is None:
elif outputs is None or outputs == []:
outputs = []
self.interface_type = self.InterfaceTypes.INPUT_ONLY
elif inputs is None:
elif inputs is None or inputs == []:
inputs = []
self.interface_type = self.InterfaceTypes.OUTPUT_ONLY

Expand Down