import gradio as gr from root import RootSignals client = None # Initialize client as None ROOT_EVALUATORS = ['Answer Correctness', 'Answer Relevance', 'Clarity', 'Coherence', 'Conciseness', 'Confidentiality', 'Engagingness', 'Formality', 'Harmlessness', 'Helpfulness', 'Non-toxicity', 'Originality', 'Persuasiveness', 'Politeness', 'Precision', 'Quality of Writing Creative', 'Quality of Writing Professional', 'Relevance', 'Safety for Children', 'Sentiment recognition', ] def initialize_client(api_key): global client client = RootSignals(api_key=api_key) return gr.Dropdown(choices=ROOT_EVALUATORS) def process_and_evaluate(api_key, user_input, llm_response, selected_evaluator): global client if not client: evaluator_dropdown = initialize_client(api_key) # Get the evaluator instance by name evaluator = client.evaluators.get_by_name(name=selected_evaluator) # Run evaluation using selected evaluator evaluation_result = evaluator.run(request=user_input, response=llm_response) score = evaluation_result.score justification = evaluation_result.justification return score, justification # Create the interface with a custom layout with gr.Blocks(theme=gr.themes.Default(primary_hue="blue")) as demo: with gr.Row(): gr.Image(value="https://lh3.googleusercontent.com/d/1e49skZjYGTZscWCVrhf6Ad1bRP2pvwpI", height=60) gr.Markdown("