diff --git a/src/aind_qc_portal/panel/evaluation.py b/src/aind_qc_portal/panel/evaluation.py
index 19c0928..9ba6757 100644
--- a/src/aind_qc_portal/panel/evaluation.py
+++ b/src/aind_qc_portal/panel/evaluation.py
@@ -46,7 +46,7 @@ def panel(self):
md = f"""
{md_style(12, self._data.description if self._data.description else "*no description provided*")}
-{md_style(8, f"Current state: **{status_html(self._data.status)}**")}
+{md_style(8, f"Current state: **{status_html(self._data.status())}**")}
{md_style(8, f"Contains **{len(self._data.metrics)}** metrics. {allow_failing_str}")}
"""
diff --git a/src/aind_qc_portal/panel/metric.py b/src/aind_qc_portal/panel/metric.py
index b3cfd7c..7480866 100644
--- a/src/aind_qc_portal/panel/metric.py
+++ b/src/aind_qc_portal/panel/metric.py
@@ -129,7 +129,7 @@ def metric_panel(self):
auto_value = True
elif isinstance(value, dict):
# first, check if every key/value pair has the same length, if so coerce to a dataframe
- if all([len(v) == len(value[list(value.keys())[0]]) for v in value.values()]):
+ if all([isinstance(v, list) for v in value.values()]) and all([len(v) == len(value[list(value.keys())[0]]) for v in value.values()]):
df = pd.DataFrame(value)
value_widget = pn.pane.DataFrame(df)
else:
@@ -184,17 +184,10 @@ def _media_panel(reference, parent):
elif "s3" in reference:
bucket = reference.split("/")[2]
key = "/".join(reference.split("/")[3:])
- media_data = _get_s3_asset(parent.s3_client, bucket, key)
- # [TODO] this needs to handle different media types
- return pn.pane.Image(media_data, sizing_mode='scale_width', max_width=1200, max_height=2000)
+ return _get_s3_asset(parent.s3_client, bucket, key)
elif "png" in reference:
- if reference.startswith("/"):
- reference = reference[reference.find("/", 1):]
-
- image_data = _get_s3_asset(parent.s3_client, parent.s3_bucket, parent.s3_prefix + reference)
- # [TODO] this needs to handle different media types
- return pn.pane.Image(image_data, sizing_mode='scale_width', max_width=1200, max_height=2000)
+ return _get_s3_asset(parent.s3_client, parent.s3_bucket, parent.s3_prefix + reference)
elif reference == "ecephys-drift-map":
return ""
@@ -203,25 +196,27 @@ def _media_panel(reference, parent):
return f"Unable to parse {reference}"
-# def _parse_type(reference, media_data):
-# """Interpret the media type from the reference string
+def _parse_type(reference, data):
+ """Interpret the media type from the reference string
-# Parameters
-# ----------
-# reference : _type_
-# _description_
-# media_data : _type_
-# _description_
-# """
-# if parsed_url.path.endswith(".png") or parsed_url.path.endswith(".jpg"):
-# return pn.pane.Image(reference, sizing_mode='scale_width', max_width=1200)
-# elif parsed_url.path.endswith(".mp4"):
-# return pn.pane.Video(reference, controls=True, sizing_mode='scale_width', max_width=1200)
-# elif "neuroglancer" in reference:
-# iframe_html = f''
-# return pn.pane.HTML(iframe_html, sizing_mode='stretch_both')
-# else:
-# return pn.widgets.StaticText(value=f'Reference: link')
+ Parameters
+ ----------
+ reference : _type_
+ _description_
+ data : _type_
+ _description_
+ """
+ if reference.endswith(".png") or reference.endswith(".jpg"):
+ return pn.pane.Image(data, sizing_mode='scale_width', max_width=1200)
+ elif reference.endswith(".mp4"):
+ return pn.pane.Video(reference, controls=True, sizing_mode='scale_width', max_width=1200)
+ elif "neuroglancer" in reference:
+ iframe_html = f''
+ return pn.pane.HTML(iframe_html, sizing_mode='stretch_both')
+ elif "http" in reference:
+ return pn.widgets.StaticText(value=f'Reference: link')
+ else:
+ return pn.widgets.StaticText(value=data)
def _get_s3_asset(s3_client, bucket, key):
@@ -238,6 +233,7 @@ def _get_s3_asset(s3_client, bucket, key):
"""
try:
response = s3_client.get_object(Bucket=bucket, Key=key)
- return BytesIO(response['Body'].read())
+ data = BytesIO(response['Body'].read())
+ return _parse_type(key, data)
except Exception as e:
return f"[ERROR] Failed to fetch asset {bucket}/{key}: {e}"
diff --git a/src/aind_qc_portal/panel/quality_control.py b/src/aind_qc_portal/panel/quality_control.py
index 487e750..6abe3e3 100644
--- a/src/aind_qc_portal/panel/quality_control.py
+++ b/src/aind_qc_portal/panel/quality_control.py
@@ -146,7 +146,7 @@ def panel(self):
# build the header
md = f"""
-# Quality control for {self.asset_name}
+Quality control for {self.asset_name}
"""
header = pn.pane.Markdown(md)
@@ -155,9 +155,9 @@ def panel(self):
failing_eval_str = ""
state_md = f"""
-Current state:
-Status: **{status_html(self._data.status)}**
-Contains {len(self.evaluations)} evaluations. {failing_eval_str}
+Current state:
+Status: **{status_html((self._data.status()))}**
+Contains {len(self.evaluations)} evaluations. {failing_eval_str}
"""
state_pane = pn.pane.Markdown(state_md)
diff --git a/src/aind_qc_portal/qc_asset_app.py b/src/aind_qc_portal/qc_asset_app.py
index 9d61df1..76c7108 100644
--- a/src/aind_qc_portal/qc_asset_app.py
+++ b/src/aind_qc_portal/qc_asset_app.py
@@ -94,7 +94,7 @@ def parse_records(self):
if "quality_control" in record and record["quality_control"]:
qc = QualityControl.model_validate_json(json.dumps(record["quality_control"]))
- status = qc.status.value
+ status = qc.status().value
else:
status = "No QC"
diff --git a/src/aind_qc_portal/qc_portal_app.py b/src/aind_qc_portal/qc_portal_app.py
index bc3a566..71c08d4 100644
--- a/src/aind_qc_portal/qc_portal_app.py
+++ b/src/aind_qc_portal/qc_portal_app.py
@@ -37,7 +37,7 @@ def __init__(self):
try:
qc = QualityControl.model_validate_json(json.dumps(record["quality_control"]))
- status = qc.status.value
+ status = qc.status().value
except Exception as e:
print(f"QC object failed to validate: {e}")
status = "Invalid QC"