Skip to content

Commit

Permalink
restrict accepted files in file uploader (#319)
Browse files Browse the repository at this point in the history
Co-authored-by: Pierre-Olivier Simonard <[email protected]>
  • Loading branch information
pmeier and pierrotsmnrd authored Feb 20, 2024
1 parent b3cc95a commit c1c159d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
19 changes: 7 additions & 12 deletions ragna/deploy/_ui/components/file_uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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 = """
Expand Down Expand Up @@ -151,14 +144,16 @@ def perform_upload(self, event=None, after_upload_callback=None):
<img src="/imgs/cloud-upload.svg" width="24px" height="24px" />
<span><b>Click to upload</b> or drag and drop.<br /></span>
<div id='allowedDocuments'>
${allowed_documents_str}
Allowed files: ${allowed_documents_str}
</div>
<input type="file"
name="fileUpload"
class="fileUpload"
id="fileUpload"
multiple="multiple"
onchange="${script('file_input_on_change')}" />
multiple
onchange="${script('file_input_on_change')}"
accept="${allowed_documents_str}"
/>
</div>
<div id="fileListContainer" class="fileListContainer">
Expand Down
4 changes: 1 addition & 3 deletions ragna/deploy/_ui/modal_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]]

Expand Down

0 comments on commit c1c159d

Please sign in to comment.