# controller for the application that calls the model and explanation functions # and returns the updated conversation history # external imports import gradio as gr # internal imports from model import godel from explanation import interpret_shap as sint, visualize as viz # main interference function that that calls chat functions depending on selections def interference( prompt: str, history: list, knowledge: str, system_prompt: str, xai_selection: str, ): # if no system prompt is given, use a default one if system_prompt == "": system_prompt = """ You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. """ # if a XAI approach is selected, grab the XAI instance if xai_selection in ("SHAP", "Visualizer"): match xai_selection.lower(): case "shap": xai = sint case "visualizer": xai = viz case _: # use Gradio warning to display error message gr.Warning(f""" There was an error in the selected XAI Approach. It is "{xai_selection}" """) raise RuntimeError("There was an error in the selected XAI approach.") # call the explained chat function prompt_output, history_output, xai_graphic, xai_plot, xai_markup = ( explained_chat( model=godel, xai=xai, message=prompt, history=history, system_prompt=system_prompt, knowledge=knowledge, ) ) # if no (or invalid) XAI approach is selected call the vanilla chat function else: # call the vanilla chat function prompt_output, history_output = vanilla_chat( model=godel, message=prompt, history=history, system_prompt=system_prompt, knowledge=knowledge, ) # set XAI outputs to disclaimer html/none xai_graphic, xai_plot, xai_markup = ( """