Skip to content
Open
Changes from all 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
17 changes: 12 additions & 5 deletions gradio/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
Sequence,
)
from contextlib import contextmanager
from functools import wraps
from functools import lru_cache, wraps
from io import BytesIO
from pathlib import Path
from types import ModuleType, NoneType
Expand Down Expand Up @@ -635,6 +635,7 @@ def resolve_singleton(_list: list[Any] | Any) -> Any:
return _list


@lru_cache(maxsize=1)
def get_all_components() -> list[type[Component] | type[BlockContext]]:
import gradio as gr

Expand Down Expand Up @@ -686,12 +687,18 @@ def component_or_layout_class(cls_name: str) -> type[Component] | type[BlockCont

components = {c.__name__.lower(): c for c in get_all_components()}
# add aliases such as 'text'
for name, cls in components_module.__dict__.items():
if isinstance(cls, type) and issubclass(cls, Component):
# Use local variables for better loop performance
comp_dict_items = components_module.__dict__.items()
comp_type = type
comp_cls = Component
issub = issubclass
for name, cls in comp_dict_items:
if isinstance(cls, comp_type) and issub(cls, comp_cls):
components[name.lower()] = cls

if cls_name.replace("_", "") in components:
return components[cls_name.replace("_", "")]
key = cls_name.replace("_", "")
if key in components:
return components[key]

raise ValueError(
f"No such component or layout: {cls_name}. "
Expand Down