from typing import List import html import streamlit as st import asyncio from pydantic_models import Product from pydantic_ai_agents import Chatbot CARD_CSS = """ """ # class ProductReview(BaseModel): # ratings: Annotated[float, Field(le=5.0, ge=0.0)] = 0.0 # num_ratings: int = -1 # num_reviews : int = -1 # # class Product(BaseModel): # id: Optional[str] = None # pro_class : Annotated[Optional[ProductClass] ,Field(description="The category/type of the product")] = None # price: int # name: str # url: str # image: Optional[str] # review: Optional[ProductReview] # details: List[str] # delivery_date: datetime.date | str | None = None def render_products(products: List[Product], cols: int = 3): rows = [products[i : i + cols] for i in range(0, len(products), cols)] for row in rows: columns = st.columns(len(row), gap="large") for col, product in zip(columns, row): with col: # Card HTML name_escaped = html.escape(product.name) url = product.url image = product.image if product.image else None price = product.price rating = product.review.ratings if product.review else None num_ratings = product.review.num_ratings if product.review else None # If price is numeric, format it with comma separators if isinstance(price, (int, float)): price_str = "₹{:,.0f}".format(price) else: price_str = str(price) if price else "" # Build HTML for the card (image + title link) if image: card_html = f"""