"""Gradio interface builder for email assistant UI.""" import gradio as gr from typing import Callable, Tuple from .config import UIConfig def create_gradio_interface(process_fn: Callable[[str], Tuple[str, str, str, str]]) -> gr.Blocks: """Create Gradio interface with all components. Args: process_fn: Function that processes a query and returns (subject, body, stats, chunks_html) Returns: Gradio Blocks interface ready to launch """ theme = UIConfig.create_theme() with gr.Blocks(title=UIConfig.TITLE, theme=theme) as demo: gr.Markdown(f"# {UIConfig.TITLE}") # Query input section query_input = gr.Textbox( label=UIConfig.QUERY_LABEL, placeholder=UIConfig.QUERY_PLACEHOLDER, lines=UIConfig.QUERY_LINES ) submit_btn = gr.Button( UIConfig.SUBMIT_BUTTON_TEXT, variant=UIConfig.SUBMIT_BUTTON_VARIANT ) stats_output = gr.Markdown(label=UIConfig.STATS_LABEL) # Output section: Email and chunks side by side with gr.Row(): with gr.Column(scale=1): gr.Markdown(UIConfig.EMAIL_HEADER) subject_output = gr.Textbox( label=UIConfig.SUBJECT_LABEL, lines=UIConfig.SUBJECT_LINES ) body_output = gr.Textbox( label=UIConfig.BODY_LABEL, lines=UIConfig.BODY_LINES ) with gr.Column(scale=1): gr.Markdown(UIConfig.DOCUMENTS_HEADER) chunks_output = gr.HTML() # Define outputs list for reuse outputs = [subject_output, body_output, stats_output, chunks_output] # Event handlers submit_btn.click( fn=process_fn, inputs=[query_input], outputs=outputs, show_progress=True ) query_input.submit( fn=process_fn, inputs=[query_input], outputs=outputs, show_progress=True ) # Examples examples = gr.Examples( examples=UIConfig.EXAMPLES, inputs=[query_input] ) examples.dataset.click( fn=process_fn, inputs=[query_input], outputs=outputs ) return demo