import gradio as gr from ui.layout import create_ui from tools.vision import process_receipt_image from agent.brain import process_workflow # Load the custom CSS for the "Off-Brand" Badge try: with open("ui/style.css", "r") as f: custom_css = f.read() except FileNotFoundError: custom_css = "" # Build the Gradio App demo = gr.Blocks() my_theme = gr.themes.Default( primary_hue="blue", neutral_hue="slate" ) with demo: # Initialize the UI layout from the ui folder image_input, audio_input, submit_btn, chatbot, msg_input = create_ui() # Bind the submit button to the Core Boss workflow def handle_analyze(image, user_msg, history): if not user_msg: user_msg = "Please analyze this bill." # Step 1: If an image is provided, extract raw text raw_text = None if image: raw_text = process_receipt_image(image) print(f"=== VISION MODEL RAW TEXT ===\n{raw_text}\n=============================") # Step 2: Route everything to the Core Boss bot_response = process_workflow(user_text=user_msg, raw_vision_text=raw_text) print(f"=== CORE ROUTER RESPONSE ===\n{bot_response}\n============================") # Step 3: Append to chat history history.append({"role": "user", "content": user_msg}) history.append({"role": "assistant", "content": str(bot_response)}) return history submit_btn.click( fn=handle_analyze, inputs=[image_input, msg_input, chatbot], outputs=[chatbot] ) if __name__ == "__main__": demo.launch(theme=my_theme, css=custom_css)