Creating a suitable file uploader for web apps
As you can imagine, this time, we are not using the radio button. Instead, we are directly uploading the files. So, referring to Figure 12.7, let’s comment all the code between lines 11 and 31.
Immediately in the subheading, on line 10, we can add file_uploader
, this time including all three types:
raw_text_file = st.file_uploader('Upload File', type=['txt', 'docx', 'pdf'])
When we try to upload the file from the browser, this time in our directory, we will see all three types of files and be able to select one of them.
As we did on line 15 in the code presented in Figure 12.5, we can check that the file is not null by writing the following:
if raw_text_file is not None:
After this if
clause, we must get the details of the file. We need these details to understand which type of file we selected and how to manage it. By using the raw_file_text
variable, which contains the file...