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_cls: Type
|
||||||
self._index_ui: Any = None
|
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._default_settings: dict[str, dict] = {}
|
||||||
self._setting_mappings: dict[str, dict] = {}
|
self._setting_mappings: dict[str, dict] = {}
|
||||||
|
|
||||||
|
@ -249,10 +244,6 @@ class FileIndex(BaseIndex):
|
||||||
# user's modification
|
# user's modification
|
||||||
config.update(self.config)
|
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
|
self.config = config
|
||||||
|
|
||||||
# create the resources
|
# create the resources
|
||||||
|
@ -270,6 +261,13 @@ class FileIndex(BaseIndex):
|
||||||
self._docstore.drop()
|
self._docstore.drop()
|
||||||
shutil.rmtree(self._fs_path)
|
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):
|
def get_selector_component_ui(self):
|
||||||
if self._selector_ui is None:
|
if self._selector_ui is None:
|
||||||
self._selector_ui = self._selector_ui_cls(self._app, self)
|
self._selector_ui = self._selector_ui_cls(self._app, self)
|
||||||
|
|
|
@ -42,14 +42,17 @@ class DirectoryUpload(BasePage):
|
||||||
def __init__(self, app, index):
|
def __init__(self, app, index):
|
||||||
super().__init__(app)
|
super().__init__(app)
|
||||||
self._index = index
|
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()
|
self.on_building_ui()
|
||||||
|
|
||||||
def on_building_ui(self):
|
def on_building_ui(self):
|
||||||
with gr.Accordion(label="Directory upload", open=False):
|
with gr.Accordion(label="Directory upload", open=False):
|
||||||
gr.Markdown(
|
gr.Markdown(f"Supported file types: {self._supported_file_types_str}")
|
||||||
f"Supported file types: {', '.join(self._supported_file_types)}",
|
|
||||||
)
|
|
||||||
self.path = gr.Textbox(
|
self.path = gr.Textbox(
|
||||||
placeholder="Directory path...", lines=1, max_lines=1, container=False
|
placeholder="Directory path...", lines=1, max_lines=1, container=False
|
||||||
)
|
)
|
||||||
|
@ -69,7 +72,12 @@ class FileIndexPage(BasePage):
|
||||||
def __init__(self, app, index):
|
def __init__(self, app, index):
|
||||||
super().__init__(app)
|
super().__init__(app)
|
||||||
self._index = index
|
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_false = "Selected file: (please select above)"
|
||||||
self.selected_panel_true = "Selected file: {name}"
|
self.selected_panel_true = "Selected file: {name}"
|
||||||
# TODO: on_building_ui is not correctly named if it's always called in
|
# 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:
|
def upload_instruction(self) -> str:
|
||||||
msgs = []
|
msgs = []
|
||||||
if self._supported_file_types:
|
if self._supported_file_types:
|
||||||
msgs.append(
|
msgs.append(f"- Supported file types: {self._supported_file_types_str}")
|
||||||
f"- Supported file types: {', '.join(self._supported_file_types)}"
|
|
||||||
)
|
|
||||||
|
|
||||||
if max_file_size := self._index.config.get("max_file_size", 0):
|
if max_file_size := self._index.config.get("max_file_size", 0):
|
||||||
msgs.append(f"- Maximum file size: {max_file_size} MB")
|
msgs.append(f"- Maximum file size: {max_file_size} MB")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user