[AUR-411] Adopt to Example2 project (#28)

Add the chatbot from Example2. Create the UI for chat.
This commit is contained in:
Nguyen Trung Duc (john)
2023-10-12 15:13:25 +07:00
committed by GitHub
parent 533fffa6db
commit 6e7905cbc0
16 changed files with 919 additions and 99 deletions

View File

@@ -18,3 +18,26 @@ DEFAULT_COMPONENT_BY_TYPES = {
"float": "number",
"list": "dropdown",
}
def get_component(component_def: dict) -> gr.components.Component:
"""Get the component based on component definition"""
component_cls = None
if "component" in component_def:
component = component_def["component"]
if component not in SUPPORTED_COMPONENTS:
raise ValueError(
f"Unsupported UI component: {component}. "
f"Must be one of {SUPPORTED_COMPONENTS}"
)
component_cls = COMPONENTS_CLASS[component]
else:
raise ValueError(
f"Cannot decide the component from {component_def}. "
"Please specify `component` with 1 of the following "
f"values: {SUPPORTED_COMPONENTS}"
)
return component_cls(**component_def.get("params", {}))