Interface#
This class uses the pydantic library as a base model.
validate_environment
: This method is a model injection that runs before validating the model. This method checks whether the gradio library is installed in the environment or not. If not, it throws a value error. Otherwise, it saves the value of gr in the model vocabulary.- src.openCHA.interface.base.Interface.validate_environment(values: Dict) Dict
Validate that api key and python package exists in environment.
This function checks if the gradio Python package is installed in the environment. If the package is not found, it raises a ValueError with an appropriate error message.
- Parameters:
cls (object) – The class to which this method belongs.
values (Dict) – A dictionary containing the environment values.
- Returns:
The updated values dictionary with the gradio package imported.
- Return type:
Dict
- Raises:
ValueError – If the gradio package is not found in the environment.
prepare_interface
: This method creates a user interface for a chatbot using the gradio library.- src.openCHA.interface.base.Interface.prepare_interface(self, respond, reset, upload_meta, available_tasks, share=False)
Prepare the Gradio interface for the chatbot.
This method sets up the Gradio interface for the chatbot. It creates various UI components such as a textbox for user input, a checkbox for enabling/disabling chat history, a dropdown for selecting tasks, and a clear button to reset the interface. The interface is then launched and stored in the self.interface attribute.
- Parameters:
self (object) – The instance of the class.
respond (function) – The function to handle user input and generate responses.
reset (function) – The function to reset the chatbot state.
upload_meta (Any) – meta data.
available_tasks (list, optional) – A list of available tasks. Defaults to an empty list.
share (bool, optional) – Flag indicating whether to enable sharing the interface. Defaults to False.
- Returns:
None
close
: This method closes the user interface and frees the related resources.- src.openCHA.interface.base.Interface.close(self)
Close the Gradio interface.
This method closes the Gradio interface associated with the chatbot. It calls the close method of the interface object stored in the self.interface attribute.
- Parameters:
self (object) – The instance of the class.
- Returns:
None