I am trying to create a Widget that allows user to Upload a MP4 file and by saving it, it will save the MP4 in a folder.
However, I noticed that the Save button works only if I did not upload any file but once I uploaded a file, the save button does not work anymore. This happens to running other cells as well, after uploading a file the other cells keeps running with no output.
Here is the codes:
import ipywidgets as widgets from IPython.display import display import os import shutil import asyncio # Create a file uploader widget file_upload = widgets.FileUpload( accept='.mp4', multiple=False ) # Create a button widget save_button = widgets.Button( description="Save MP4", disabled=False, button_style='success' ) def save_mp4(b): if file_upload.value: # Get the uploaded file uploaded_file = list(file_upload.value.values()) # Specify the destination folder to save the file destination_folder = './output/' # Create the destination folder if it doesn't exist if not os.path.exists(destination_folder): os.makedirs(destination_folder) with open(os.path.join(destination_folder, uploaded_file['metadata']['name']), 'wb') as f: f.write(uploaded_file['content']) # Disable the file uploaded and update the button text file_upload.disabled = True save_button.description = "MP4 Saved!" else: print("Please upload an MP4 file first") save_button.on_click(save_mp4) display(file_upload, save_button)
Does anybody knows why this is happening and how can i fix this issue? Thank you!