Open lippings opened 4 days ago
I can work around this by adding an if-clause for ComponentMessage in Chatbot._postprocess_content:
def _postprocess_content(
self,
chat_message: str
| tuple
| list
| FileDataDict
| FileData
| GradioComponent
| None,
) -> str | FileMessage | ComponentMessage | None:
if chat_message is None:
return None
elif isinstance(chat_message, FileMessage):
return chat_message
elif isinstance(chat_message, FileData):
return FileMessage(file=chat_message)
elif isinstance(chat_message, ComponentMessage): # <------------ This is the added clause
return chat_message
elif isinstance(chat_message, GradioComponent):
component = import_component_and_data(type(chat_message).__name__)
if component:
component = chat_message.__class__(**chat_message.constructor_args)
chat_message.constructor_args.pop("value", None)
config = component.get_config()
return ComponentMessage(
component=type(chat_message).__name__.lower(),
value=config.get("value", None),
constructor_args=chat_message.constructor_args,
props=config,
)
elif isinstance(chat_message, dict) and "path" in chat_message:
filepath = chat_message["path"]
return self._create_file_message(chat_message, filepath)
elif isinstance(chat_message, (tuple, list)):
filepath = str(chat_message[0])
return self._create_file_message(chat_message, filepath)
elif isinstance(chat_message, str):
chat_message = inspect.cleandoc(chat_message)
return chat_message
else:
raise ValueError(f"Invalid message for Chatbot component: {chat_message}")
But I'm not sure this is the "proper" way to fix this, since I'm not too familiar with Gradio's internals.
Describe the bug
I have a chatbot implemented using gradio.Chatbot, where I am streaming the chatbot's response. I also want the chatbot to be able to include gradio components in it's responses, as well as text. I can get the component to show up fine, but the next yield from the generator function after the component is shown causes a ValueError.
Have you searched existing issues? π
Reproduction
The bot should respond with text, an image, and more text after that.
Screenshot
There is an error before the last piece of text, immediately after the image.
Logs
System Info
Severity
I can work around it