| import gradio as gr |
| from ui.layout import create_ui |
| from tools.vision import process_receipt_image |
| from agent.brain import process_workflow |
|
|
| |
| try: |
| with open("ui/style.css", "r") as f: |
| custom_css = f.read() |
| except FileNotFoundError: |
| custom_css = "" |
|
|
| |
| demo = gr.Blocks() |
| my_theme = gr.themes.Default( |
| primary_hue="blue", |
| neutral_hue="slate" |
| ) |
|
|
| with demo: |
| |
| image_input, audio_input, submit_btn, chatbot, msg_input = create_ui() |
| |
| |
| def handle_analyze(image, user_msg, history): |
| if not user_msg: |
| user_msg = "Please analyze this bill." |
| |
| |
| raw_text = None |
| if image: |
| raw_text = process_receipt_image(image) |
| print(f"=== VISION MODEL RAW TEXT ===\n{raw_text}\n=============================") |
| |
| |
| bot_response = process_workflow(user_text=user_msg, raw_vision_text=raw_text) |
| print(f"=== CORE ROUTER RESPONSE ===\n{bot_response}\n============================") |
| |
| |
| 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) |
|
|