From 3b810e1118fbb510152a6e8f2fab5b8e74b4a257 Mon Sep 17 00:00:00 2001 From: Yifan Mai Date: Fri, 31 May 2024 16:52:56 -0700 Subject: [PATCH] Allow non-lists to be displayed in AnnotationsDisplay --- .../src/components/AnnotationsDisplay.tsx | 70 +++++++++++++------ 1 file changed, 48 insertions(+), 22 deletions(-) diff --git a/helm-frontend/src/components/AnnotationsDisplay.tsx b/helm-frontend/src/components/AnnotationsDisplay.tsx index 3bd7fbe8a95..0d44b8bd802 100644 --- a/helm-frontend/src/components/AnnotationsDisplay.tsx +++ b/helm-frontend/src/components/AnnotationsDisplay.tsx @@ -2,12 +2,56 @@ import CompletionAnnotation from "@/types/CompletionAnnotation"; import Preview from "./Preview"; import MediaObjectDisplay from "./MediaObjectDisplay"; +// TODO: This is a dirty hack to support annotations from +// Image2Structure and AIRBench, but eventually we should make sure +// all annotations are supported generally. type Props = { predictionAnnotations: - | Record> + | Record | Map> | undefined; }; +function listAnnotationDisplay(listAnnotation: Array) { + return ( +
+ {listAnnotation.map((annotation, idx) => ( +
+ {annotation.error && ( +
+

Error

+ {" "} +
+ )} + {annotation.text && ( +
+

Text

+ {" "} +
+ )} + {annotation.media_object && ( + + )} +
+ ))} +
+ ); +} + +function dictAnnotationDisplay( + dictAnnotation: Record, +) { + return ( +
+ {Object.entries(dictAnnotation).map(([key, value]) => ( +
+

{key}

+ +
+ ))} +
+ ); +} + export default function AnnotationDisplay({ predictionAnnotations }: Props) { return (
@@ -17,27 +61,9 @@ export default function AnnotationDisplay({ predictionAnnotations }: Props) {

{key}

- {value.map((annotation, idx) => ( -
- {annotation.error && ( -
-

Error

- {" "} -
- )} - {annotation.text && ( -
-

Text

- {" "} -
- )} - {annotation.media_object && ( - - )} -
- ))} + {Array.isArray(value) + ? listAnnotationDisplay(value) + : dictAnnotationDisplay(value)}
)) : null}