"""Launches a Gradio app that runs an AI planning agent to find smart online deals. Uses Python's built-in logging system for consistent logs. Includes demo mode restrictions: MAX_DEMO_RUNS_PER_DAY runs per day. """ import os from typing import Tuple import gradio as gr from src.agents.pipeline import run_and_stream_logs from src.config.constants import ( IS_DEMO_VERSION, MAX_CATEGORY_SELECTION, MAX_DEMO_RUNS_PER_DAY, PROJECT_NAME, VERSION, ) from src.config.feeds import CATEGORY_FEEDS from src.ui.formatting import format_deals_table from src.utils.logger import console from src.utils.state_manager import can_run_app PROJECT_NAME_CAP = PROJECT_NAME.capitalize() REPO_URL = f"https://github.com/lisekarimi/{PROJECT_NAME}" DOC_URL = f"https://lisekarimi.github.io/{PROJECT_NAME}" def build_ui() -> gr.Blocks: """Constructs and returns the Gradio UI interface, with error handling.""" try: with open( os.path.join(os.path.dirname(__file__), "assets", "styles.css"), "r" ) as f: css = f.read() except Exception as e: css = "" console.print(f"[bold yellow]β οΈ Failed to load CSS:[/] {e}") # Set initial UI state here disable_btn = False initial_status = "Loading demo status..." # Building the UI try: with gr.Blocks(css=css, title=f"π·οΈ{PROJECT_NAME_CAP}") as ui: with gr.Column(elem_id="app-container"): # π Top content gr.Markdown(f"
π·οΈ Snapr, an Agentic AI System, discovers the best online deals for youβsmart, simple, and automatic. Let AI do the work, so you can save money without any effort.
1οΈβ£ Choose up to {MAX_CATEGORY_SELECTION} categories to search.
2οΈβ£ Click "Find Smart Deals" β AI scans, estimates prices, and filters top discounts.
3οΈβ£ See the best deals in a table with prices, discounts, and direct links.
β οΈ This is a demo version β limited to {MAX_DEMO_RUNS_PER_DAY} global runs per day for all users.
""" ) gr.Markdown( f"""π¦ Want more? You can run it locally with full instructions and documentation.
""" ) with gr.Column(elem_id="left-col"): category_selector = gr.Dropdown( choices=list(CATEGORY_FEEDS.keys()), value="Electronics", multiselect=True, label=( f"π§ Select up to {MAX_CATEGORY_SELECTION} Deal Categories" ), elem_id="category-selector", elem_classes="custom-dropdown", ) run_btn = gr.Button( "π Find Smart Deals", elem_id="run-btn", variant="primary", elem_classes="run-button", interactive=not disable_btn, ) status_msg = gr.HTML(value=initial_status, elem_id="status-message") # Logs + deals logs_output = gr.HTML( value="""