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 api_key:
        # Display a pop-up info message
        gr.Info("API key is missing. Please enter your API key to proceed.")
        return "", ""
    
    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:
    gr.HTML("""
               
               """)
    with gr.Row():
        gr.Image(value="https://app.rootsignals.ai/images/root-signals-color.svg", height=70)
        gr.Markdown("