From c1c159d196db99cb0372cddd4abf8ecee3ce255d Mon Sep 17 00:00:00 2001 From: Philip Meier Date: Tue, 20 Feb 2024 11:38:13 +0100 Subject: [PATCH] restrict accepted files in file uploader (#319) Co-authored-by: Pierre-Olivier Simonard --- ragna/deploy/_ui/components/file_uploader.py | 19 +++++++------------ ragna/deploy/_ui/modal_configuration.py | 4 +--- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/ragna/deploy/_ui/components/file_uploader.py b/ragna/deploy/_ui/components/file_uploader.py index 1e36106e..383b6789 100644 --- a/ragna/deploy/_ui/components/file_uploader.py +++ b/ragna/deploy/_ui/components/file_uploader.py @@ -30,14 +30,7 @@ def can_proceed_to_upload(self): @param.depends("allowed_documents", watch=True) def update_allowed_documents_str(self): - if len(self.allowed_documents) == 1: - self.allowed_documents_str = ( - "Only " + self.allowed_documents[0] + " files are allowed." - ) - else: - self.allowed_documents_str = "Allowed files : " + ", ".join( - self.allowed_documents - ) + self.allowed_documents_str = ", ".join(self.allowed_documents) @param.depends("uploaded_documents_json", watch=True) async def did_finish_upload(self): @@ -69,7 +62,7 @@ def perform_upload(self, event=None, after_upload_callback=None): _child_config = { "custom_js": "template", "uploaded_documents_json": "template", - "allowed_documents_str": "literal", + "allowed_documents_str": "template", } _template = """ @@ -151,14 +144,16 @@ def perform_upload(self, event=None, after_upload_callback=None): Click to upload or drag and drop.
- ${allowed_documents_str} + Allowed files: ${allowed_documents_str}
+ multiple + onchange="${script('file_input_on_change')}" + accept="${allowed_documents_str}" + />
diff --git a/ragna/deploy/_ui/modal_configuration.py b/ragna/deploy/_ui/modal_configuration.py index a0c72fe2..7567c572 100644 --- a/ragna/deploy/_ui/modal_configuration.py +++ b/ragna/deploy/_ui/modal_configuration.py @@ -164,9 +164,7 @@ async def model_section(self): # TODO : use the components to set up the default values for the various params config = ChatConfig() - config.allowed_documents = [ - ext[1:].upper() for ext in components["documents"] - ] + config.allowed_documents = components["documents"] assistants = [component["title"] for component in components["assistants"]]