Spaces:
Sleeping
Sleeping
File size: 9,517 Bytes
aa6cac1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | """
Setup script to populate the inventory database with sample e-commerce products.
Run this after creating the database schema in Supabase.
"""
from .models import OrderDatabase
from dotenv import load_dotenv
load_dotenv()
def setup_sample_inventory():
"""Add sample products to the inventory"""
db = OrderDatabase()
print("๐๏ธ Setting up E-Commerce Inventory...")
print("=" * 50)
# Sample products across different categories
products = [
# Electronics
{
"product_id": "PROD001",
"name": "MacBook Pro 14-inch",
"description": "Apple M2 Pro chip, 16GB RAM, 512GB SSD. Perfect for professional work and creative tasks.",
"price": 1999.99,
"category": "Electronics",
"stock_quantity": 25,
"low_stock_threshold": 5
},
{
"product_id": "PROD002",
"name": "iPhone 15 Pro",
"description": "Latest iPhone with A17 Pro chip, 256GB storage, titanium design.",
"price": 999.99,
"category": "Electronics",
"stock_quantity": 50,
"low_stock_threshold": 10
},
{
"product_id": "PROD003",
"name": "AirPods Pro (2nd Gen)",
"description": "Active noise cancellation, spatial audio, USB-C charging.",
"price": 249.99,
"category": "Electronics",
"stock_quantity": 3, # Low stock!
"low_stock_threshold": 10
},
{
"product_id": "PROD004",
"name": "Samsung 4K Smart TV 55-inch",
"description": "Crystal UHD display, HDR support, built-in streaming apps.",
"price": 599.99,
"category": "Electronics",
"stock_quantity": 15,
"low_stock_threshold": 5
},
{
"product_id": "PROD005",
"name": "Sony WH-1000XM5 Headphones",
"description": "Industry-leading noise cancellation, 30-hour battery life.",
"price": 399.99,
"category": "Electronics",
"stock_quantity": 0, # Out of stock!
"low_stock_threshold": 8
},
# Clothing
{
"product_id": "PROD101",
"name": "Classic Denim Jacket",
"description": "100% cotton denim, available in multiple sizes. Timeless style.",
"price": 79.99,
"category": "Clothing",
"stock_quantity": 100,
"low_stock_threshold": 20
},
{
"product_id": "PROD102",
"name": "Running Shoes - ProRun Elite",
"description": "Lightweight, breathable, excellent cushioning for long runs.",
"price": 129.99,
"category": "Clothing",
"stock_quantity": 45,
"low_stock_threshold": 15
},
{
"product_id": "PROD103",
"name": "Wool Sweater",
"description": "Merino wool, soft and warm, perfect for winter.",
"price": 89.99,
"category": "Clothing",
"stock_quantity": 8, # Low stock!
"low_stock_threshold": 10
},
# Home & Kitchen
{
"product_id": "PROD201",
"name": "Espresso Machine - BrewMaster Pro",
"description": "15-bar pressure, milk frother included, makes cafรฉ-quality coffee at home.",
"price": 299.99,
"category": "Home & Kitchen",
"stock_quantity": 20,
"low_stock_threshold": 5
},
{
"product_id": "PROD202",
"name": "Robot Vacuum Cleaner",
"description": "Smart navigation, auto-charging, works with Alexa and Google Home.",
"price": 349.99,
"category": "Home & Kitchen",
"stock_quantity": 12,
"low_stock_threshold": 5
},
{
"product_id": "PROD203",
"name": "Non-Stick Cookware Set",
"description": "10-piece set, dishwasher safe, includes pots, pans, and utensils.",
"price": 149.99,
"category": "Home & Kitchen",
"stock_quantity": 30,
"low_stock_threshold": 10
},
# Sports & Outdoors
{
"product_id": "PROD301",
"name": "Yoga Mat Premium",
"description": "6mm thick, non-slip surface, eco-friendly materials.",
"price": 39.99,
"category": "Sports & Outdoors",
"stock_quantity": 75,
"low_stock_threshold": 20
},
{
"product_id": "PROD302",
"name": "Camping Tent 4-Person",
"description": "Waterproof, easy setup, includes carrying bag.",
"price": 199.99,
"category": "Sports & Outdoors",
"stock_quantity": 5, # Low stock!
"low_stock_threshold": 8
},
{
"product_id": "PROD303",
"name": "Hiking Backpack 40L",
"description": "Durable, multiple compartments, ergonomic design.",
"price": 89.99,
"category": "Sports & Outdoors",
"stock_quantity": 18,
"low_stock_threshold": 10
},
# Books
{
"product_id": "PROD401",
"name": "The Art of AI Engineering",
"description": "Comprehensive guide to building AI applications.",
"price": 49.99,
"category": "Books",
"stock_quantity": 40,
"low_stock_threshold": 10
},
{
"product_id": "PROD402",
"name": "Python for Automation",
"description": "Learn to automate tasks with Python, from basics to advanced.",
"price": 39.99,
"category": "Books",
"stock_quantity": 60,
"low_stock_threshold": 15
}
]
# Add products to database
added = 0
failed = 0
for product in products:
print(f"\nAdding: {product['name']}")
result = db.add_product(**product)
if result["success"]:
added += 1
stock_status = "โ
IN STOCK" if product["stock_quantity"] > 0 else "โ OUT OF STOCK"
if product["stock_quantity"] <= product["low_stock_threshold"] and product["stock_quantity"] > 0:
stock_status = "โ ๏ธ LOW STOCK"
print(f" {stock_status} - {product['stock_quantity']} units | ${product['price']}")
else:
failed += 1
print(f" โ Failed: {result.get('error', 'Unknown error')}")
print("\n" + "=" * 50)
print(f"โ
Successfully added: {added} products")
if failed > 0:
print(f"โ Failed to add: {failed} products")
# Show summary
print("\n๐ Inventory Summary:")
print("-" * 50)
categories = {}
for p in products:
cat = p["category"]
if cat not in categories:
categories[cat] = {"count": 0, "total_value": 0}
categories[cat]["count"] += 1
categories[cat]["total_value"] += p["price"] * p["stock_quantity"]
for category, stats in categories.items():
print(f"{category}: {stats['count']} products | Inventory value: ${stats['total_value']:,.2f}")
# Check for low stock items
print("\nโ ๏ธ Checking for low stock items...")
low_stock_result = db.get_low_stock_products()
if low_stock_result["success"] and low_stock_result["products"]:
print(f"\n๐ด {len(low_stock_result['products'])} product(s) need restocking:")
for p in low_stock_result["products"]:
print(f" - {p['name']}: {p['available_quantity']} units (threshold: {p['threshold']})")
else:
print("โ
All products are adequately stocked!")
def setup_sample_customers():
"""Add sample customers for testing"""
db = OrderDatabase()
print("\n\n๐ฅ Setting up Sample Customers...")
print("=" * 50)
customers = [
{
"customer_id": "CUST001",
"email": "john.doe@example.com",
"name": "John Doe"
},
{
"customer_id": "CUST002",
"email": "jane.smith@example.com",
"name": "Jane Smith"
},
{
"customer_id": "CUST003",
"email": "bob.wilson@example.com",
"name": "Bob Wilson"
}
]
for customer in customers:
result = db.create_customer(**customer)
if result["success"]:
print(f"โ
Added customer: {customer['name']} ({customer['customer_id']})")
else:
print(f"โ Failed to add {customer['name']}: {result.get('error', '')}")
if __name__ == "__main__":
print("๐ E-Commerce Inventory Setup")
print("=" * 50)
print("\nThis script will populate your database with sample products.")
print("Make sure you've already created the database tables in Supabase!\n")
input("Press Enter to continue...")
# Setup inventory
setup_sample_inventory()
# Setup customers
setup_sample_customers()
print("\n" + "=" * 50)
print("โ
Setup Complete!")
print("\nYou can now run your e-commerce agent with:")
print(" python main.py")
print("\nOr test with Gradio:")
print(" python app.py") |