Repository: gradio-app/gradio
File: gradio/components/dialogue.py (Python)

Code before:
        )
        self.ui_mode = ui_mode
        self.type = type
        self.placeholder = placeholder
        self.autofocus = autofocus
        self.autoscroll = autoscroll
        self.max_lines = max_lines
        self.speakers = speakers
        self.tags = tags or []
        self.formatter = formatter
        self.unformatter = unformatter
        self.separator = separator
        self.color_map = color_map
        self.show_submit_button = show_submit_button
        self.show_copy_button = show_copy_button
        if not interactive:
            self.info = None

    def preprocess(self, payload: DialogueModel) -> str | list[dict[str, str]]:  # type: ignore
        """
        Parameters:
            payload: Expects a `DialogueModel` object or string.
        Returns:
            Returns the dialogue as a string or list of dictionaries.
        """
        if self.type == "dialogue":
            return payload.model_dump()
        return self._format(payload)

    def _format(self, payload: DialogueModel) -> str:
        if (isinstance(payload.root, str) and payload.root == "") or (
            isinstance(payload.root, list)
            and len(payload.root) == 1
            and payload.root[0].text == ""
        ):
            return ""
        formatter = self.formatter
        if not formatter:
            formatter = self.default_formatter
        if isinstance(payload.root, str):
            return payload.root
        return self.separator.join(
            [formatter(line.speaker, line.text) for line in payload.root]
        )

    @staticmethod
    def default_formatter(speaker: str, text: str) -> str:
        return f"[{speaker}] {text}"

    @staticmethod
    def default_unformatter(line: str) -> dict[str, str]:

Review comment (suggestion):
```suggestion
        if self.type == "list":
```

Code after:
        )
        if separator == " ":
            raise ValueError("Separator cannot be an empty string.")
        self.ui_mode = ui_mode
        self.type = type
        self.placeholder = placeholder
        self.autofocus = autofocus
        self.autoscroll = autoscroll
        self.max_lines = max_lines
        self.speakers = speakers
        self.tags = tags or []
        self.formatter = formatter
        self.unformatter = unformatter
        self.separator = separator
        self.color_map = color_map
        self.show_submit_button = show_submit_button
        self.show_copy_button = show_copy_button
        if not interactive:
            self.info = None

    def preprocess(self, payload: DialogueModel) -> str | list[dict[str, str]]:  # type: ignore
        """
        Parameters:
            payload: Expects a `DialogueModel` object or string.
        Returns:
            Returns the dialogue as a string or list of dictionaries.
        """
        if self.type == "list":
            return payload.model_dump()
        return self._format(payload)

    def _format(self, payload: DialogueModel) -> str:
        if (isinstance(payload.root, str) and payload.root == "") or (
            isinstance(payload.root, list)
            and len(payload.root) == 1
            and payload.root[0].text == ""
        ):
            return ""
        formatter = self.formatter
        if not formatter:
            formatter = self.default_formatter
        if isinstance(payload.root, str):
            return payload.root
        return self.separator.join(
            [formatter(line.speaker, line.text) for line in payload.root]
        )

    @staticmethod
    def default_formatter(speaker: str, text: str) -> str:
        return f"[{speaker}] {text}"