From 2d06cd290aae583d161ae0ab4e70aab0b91d19f0 Mon Sep 17 00:00:00 2001 From: Dominic Kempf Date: Wed, 13 Jul 2022 16:16:54 +0200 Subject: [PATCH] Use a widget layout for exploration that shows all filenames --- .gitmodules | 3 +++ Face-Mask-Detection | 1 + misinformation/faces.py | 37 +++++++++++++++++++----------- notebooks/facial_expressions.ipynb | 2 +- 4 files changed, 28 insertions(+), 15 deletions(-) create mode 100644 .gitmodules create mode 160000 Face-Mask-Detection diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..65e6169 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "Face-Mask-Detection"] + path = Face-Mask-Detection + url = https://github.com/chandrikadeb7/Face-Mask-Detection.git diff --git a/Face-Mask-Detection b/Face-Mask-Detection new file mode 160000 index 0000000..7e50074 --- /dev/null +++ b/Face-Mask-Detection @@ -0,0 +1 @@ +Subproject commit 7e500749401bad4bb338790fbdb89b58e41ef2d9 diff --git a/misinformation/faces.py b/misinformation/faces.py index 2fa6ef3..6c073f7 100644 --- a/misinformation/faces.py +++ b/misinformation/faces.py @@ -46,30 +46,39 @@ class JSONContainer: def explore_face_recognition(image_paths): + # Create an image selector widget + image_select = ipywidgets.Select( + options=image_paths, layout=ipywidgets.Layout(width="20%"), rows=20 + ) + # Set up the facial recognition output widget output = ipywidgets.Output(layout=ipywidgets.Layout(width="30%")) # Set up the image selection and display widget - images = [ipywidgets.Image.from_file(p) for p in image_paths] - image_widget = ipywidgets.Tab( - children=images, - titles=[f"#{i}" for i in range(len(image_paths))], - layout=ipywidgets.Layout(width="70%"), + image_widget = ipywidgets.Box( + children=[], + layout=ipywidgets.Layout(width="50%"), ) - # Precompute all the results for a user experience without delay - with ipywidgets.Output(): - results = [facial_expression_analysis(i) for i in image_paths] - # Register the tab switch logic - def tabswitch(_): + def switch(_): + # Clear existing output + image_widget.children = () output.clear_output() + + # Create the new content + image_widget.children = (ipywidgets.Image.from_file(image_select.value),) + + # This output widget absorbes print statements that are messing with + # the widget output and cannot be disabled through the API. + with ipywidgets.Output(): + analysis = facial_expression_analysis(image_select.value) with output: - display(JSONContainer(results[image_widget.selected_index])) + display(JSONContainer(analysis)) # Register the handler and trigger it immediately - image_widget.observe(tabswitch, names=("selected_index",), type="change") - tabswitch(None) + image_select.observe(switch, names=("value",), type="change") + switch(None) # Show the combined widget - return ipywidgets.HBox([image_widget, output]) + return ipywidgets.HBox([image_select, image_widget, output]) diff --git a/notebooks/facial_expressions.ipynb b/notebooks/facial_expressions.ipynb index 1a63a7e..3262f0a 100644 --- a/notebooks/facial_expressions.ipynb +++ b/notebooks/facial_expressions.ipynb @@ -41,7 +41,7 @@ "metadata": {}, "outputs": [], "source": [ - "images = misinformation.find_files()" + "images = misinformation.find_files(limit=1000)" ] }, {