Put the preparation step in FileIndex to on_start (#20)
This commit is contained in:
parent
b507eef541
commit
f3e82b2e70
|
@ -81,11 +81,6 @@ class FileIndex(BaseIndex):
|
|||
self._index_ui_cls: Type
|
||||
self._index_ui: Any = None
|
||||
|
||||
self._setup_indexing_cls()
|
||||
self._setup_retriever_cls()
|
||||
self._setup_file_index_ui_cls()
|
||||
self._setup_file_selector_ui_cls()
|
||||
|
||||
self._default_settings: dict[str, dict] = {}
|
||||
self._setting_mappings: dict[str, dict] = {}
|
||||
|
||||
|
@ -249,10 +244,6 @@ class FileIndex(BaseIndex):
|
|||
# user's modification
|
||||
config.update(self.config)
|
||||
|
||||
# clean
|
||||
file_types_str = config["supported_file_types"]
|
||||
file_types = [each.strip() for each in file_types_str.split(",")]
|
||||
config["supported_file_types"] = file_types
|
||||
self.config = config
|
||||
|
||||
# create the resources
|
||||
|
@ -270,6 +261,13 @@ class FileIndex(BaseIndex):
|
|||
self._docstore.drop()
|
||||
shutil.rmtree(self._fs_path)
|
||||
|
||||
def on_start(self):
|
||||
"""Setup the classes and hooks"""
|
||||
self._setup_indexing_cls()
|
||||
self._setup_retriever_cls()
|
||||
self._setup_file_index_ui_cls()
|
||||
self._setup_file_selector_ui_cls()
|
||||
|
||||
def get_selector_component_ui(self):
|
||||
if self._selector_ui is None:
|
||||
self._selector_ui = self._selector_ui_cls(self._app, self)
|
||||
|
|
|
@ -42,14 +42,17 @@ class DirectoryUpload(BasePage):
|
|||
def __init__(self, app, index):
|
||||
super().__init__(app)
|
||||
self._index = index
|
||||
self._supported_file_types = self._index.config.get("supported_file_types", [])
|
||||
self._supported_file_types_str = self._index.config.get(
|
||||
"supported_file_types", ""
|
||||
)
|
||||
self._supported_file_types = [
|
||||
each.strip() for each in self._supported_file_types_str.split(",")
|
||||
]
|
||||
self.on_building_ui()
|
||||
|
||||
def on_building_ui(self):
|
||||
with gr.Accordion(label="Directory upload", open=False):
|
||||
gr.Markdown(
|
||||
f"Supported file types: {', '.join(self._supported_file_types)}",
|
||||
)
|
||||
gr.Markdown(f"Supported file types: {self._supported_file_types_str}")
|
||||
self.path = gr.Textbox(
|
||||
placeholder="Directory path...", lines=1, max_lines=1, container=False
|
||||
)
|
||||
|
@ -69,7 +72,12 @@ class FileIndexPage(BasePage):
|
|||
def __init__(self, app, index):
|
||||
super().__init__(app)
|
||||
self._index = index
|
||||
self._supported_file_types = self._index.config.get("supported_file_types", [])
|
||||
self._supported_file_types_str = self._index.config.get(
|
||||
"supported_file_types", ""
|
||||
)
|
||||
self._supported_file_types = [
|
||||
each.strip() for each in self._supported_file_types_str.split(",")
|
||||
]
|
||||
self.selected_panel_false = "Selected file: (please select above)"
|
||||
self.selected_panel_true = "Selected file: {name}"
|
||||
# TODO: on_building_ui is not correctly named if it's always called in
|
||||
|
@ -80,9 +88,7 @@ class FileIndexPage(BasePage):
|
|||
def upload_instruction(self) -> str:
|
||||
msgs = []
|
||||
if self._supported_file_types:
|
||||
msgs.append(
|
||||
f"- Supported file types: {', '.join(self._supported_file_types)}"
|
||||
)
|
||||
msgs.append(f"- Supported file types: {self._supported_file_types_str}")
|
||||
|
||||
if max_file_size := self._index.config.get("max_file_size", 0):
|
||||
msgs.append(f"- Maximum file size: {max_file_size} MB")
|
||||
|
|
Loading…
Reference in New Issue
Block a user