зеркало из
https://github.com/ssciwr/AMMICO.git
synced 2025-10-28 20:54:14 +02:00
* colors expression by KMean algorithm * object detection by imageai * object detection by cvlib * add encapsulation of object detection * remove encapsulation of objdetect v0 * objects expression to dict * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * added imageai to requirements * add objects to dictionary * update for AnalysisMethod baseline * add objects dection support explore_analysis display * extend python version of misinf to allow imageai * account for older python * use global functionality for dict to csv convert * update for docker build * docker will build now but ipywidgets still not working * test code * include test data folder in repo * add some sample images * load cvs labels to dict * add test data * retrigger checks * add map to human coding * get orders from dict, missing dep * add module to test accuracy * retrigger checks * retrigger checks * now removing imageai * removed imageai * move labelmanager to analyse * multiple faces in mydict * fix pre-commit issues * map mydict * hide imageai * objects default using cvlib, isolate and disable imageai * correct python version * refactor faces tests * refactor objects tests * sonarcloud issues * refactor utils tests * address code smells * update readme * update notebook without imageai Co-authored-by: Ma Xianghe <825074348@qq.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: iulusoy <inga.ulusoy@uni-heidelberg.de>
71 строка
2.2 KiB
Python
71 строка
2.2 KiB
Python
import ipywidgets
|
|
from IPython.display import display
|
|
|
|
import misinformation.faces as faces
|
|
import misinformation.text as text
|
|
import misinformation.objects as objects
|
|
|
|
|
|
class JSONContainer:
|
|
"""Expose a Python dictionary as a JSON document in JupyterLab
|
|
rich display rendering.
|
|
"""
|
|
|
|
def __init__(self, data={}):
|
|
self._data = data
|
|
|
|
def _repr_json_(self):
|
|
return self._data
|
|
|
|
|
|
def explore_analysis(mydict, identify="faces"):
|
|
# dictionary mapping the type of analysis to be explored
|
|
identify_dict = {
|
|
"faces": faces.EmotionDetector,
|
|
"text-on-image": text.TextDetector,
|
|
"objects": objects.ObjectDetector,
|
|
}
|
|
# create a list containing the image ids for the widget
|
|
# image_paths = [mydict[key]["filename"] for key in mydict.keys()]
|
|
image_ids = [key for key in mydict.keys()]
|
|
# Create an image selector widget
|
|
image_select = ipywidgets.Select(
|
|
options=image_ids, 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
|
|
image_widget = ipywidgets.Box(
|
|
children=[],
|
|
layout=ipywidgets.Layout(width="50%"),
|
|
)
|
|
|
|
# Register the tab switch logic
|
|
def switch(_):
|
|
# Clear existing output
|
|
image_widget.children = ()
|
|
output.clear_output()
|
|
|
|
# Create the new content
|
|
image_widget.children = (
|
|
ipywidgets.Image.from_file(mydict[image_select.value]["filename"]),
|
|
)
|
|
|
|
# This output widget absorbes print statements that are messing with
|
|
# the widget output and cannot be disabled through the API.
|
|
with faces.NocatchOutput():
|
|
mydict[image_select.value] = identify_dict[identify](
|
|
mydict[image_select.value]
|
|
).analyse_image()
|
|
with output:
|
|
display(JSONContainer(mydict[image_select.value]))
|
|
|
|
# Register the handler and trigger it immediately
|
|
image_select.observe(switch, names=("value",), type="change")
|
|
switch(None)
|
|
|
|
# Show the combined widget
|
|
return ipywidgets.HBox([image_select, image_widget, output])
|