From 74ccf3e957704f793ada88f4786633e847fc8a03 Mon Sep 17 00:00:00 2001 From: Martina Fumanelli <53374883+mfumanelli@users.noreply.github.com> Date: Thu, 2 Jun 2022 19:44:58 +0200 Subject: [PATCH] Fix/combine adjacent (#1426) * Fix combine_adjacent arg of HighlightedText * Delete multilingual_named_entity_recognition_using_mbert.md * Fix file components.py style * Fix style gradio/components.py * Add adjacent_separator parameter to HighlightedText class Co-authored-by: martina.fumanelli Co-authored-by: martina.fumanelli --- gradio/components.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/gradio/components.py b/gradio/components.py index ee78aa2403..9823788362 100644 --- a/gradio/components.py +++ b/gradio/components.py @@ -2758,6 +2758,7 @@ class HighlightedText(Changeable, IOComponent): color_map: Dict[str, str] = None, show_legend: bool = False, combine_adjacent: bool = False, + adjacent_separator: str = "", label: Optional[str] = None, show_label: bool = True, visible: bool = True, @@ -2766,7 +2767,10 @@ class HighlightedText(Changeable, IOComponent): ): """ Parameters: - value (List[Tuple[str, str | Number | None]]): Default value to show + value (List[Tuple[str, str | Number | None]]): Default value to show. + color_map (Dict[str, str]): Map between category and respective colors. + combine_adjacent (bool): If True, will merge the labels of adjacent tokens belonging to the same category. + adjacent_separator (str): Specifies the separator to be used between tokens if combine_adjacent is True. show_legend (bool): whether to show span categories in a separate legend or inline. label (Optional[str]): component name in interface. show_label (bool): if True, will display label. @@ -2780,6 +2784,7 @@ class HighlightedText(Changeable, IOComponent): ) self.show_legend = show_legend self.combine_adjacent = combine_adjacent + self.adjacent_separator = adjacent_separator self.value = self.postprocess(value) IOComponent.__init__( self, @@ -2834,7 +2839,7 @@ class HighlightedText(Changeable, IOComponent): running_text = text running_category = category elif category == running_category: - running_text += text + running_text += self.adjacent_separator + text else: output.append((running_text, running_category)) running_text = text