[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-80014":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":13,"contributorsCount":13,"subscribersCount":13,"size":13,"stars1d":13,"stars7d":13,"stars30d":13,"stars90d":13,"forks30d":13,"starsTrendScore":13,"compositeScore":13,"rankGlobal":10,"rankLanguage":10,"license":10,"archived":15,"fork":15,"defaultBranch":16,"hasWiki":17,"hasPages":15,"topics":18,"createdAt":10,"pushedAt":10,"updatedAt":19,"readmeContent":20,"aiSummary":21,"trendingCount":13,"starSnapshotCount":13,"syncStatus":22,"lastSyncTime":23,"discoverSource":24},80014,"AutoMart-AI","Abishek-kk\u002FAutoMart-AI","Abishek-kk","Developed an AI-powered supermarket analytics system using LSTM, K-Means, and Apriori to predict sales, segment customers, recommend products, and optimize inventory through an agent-based architecture with a Streamlit dashboard.","https:\u002F\u002Fautomart-ai-q53a5utpzascgl8rpolcmw.streamlit.app\u002F",null,"Python",69,0,1,false,"main",true,[],"2026-06-12 02:03:56","# AutoMart-AI\n\n> An end-to-end retail analytics platform combining ML models, intelligent agents, and an interactive dashboard to give supermarket managers actionable insights on customers, inventory, profit, and product recommendations.\n\n![Python](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FPython-3.8%2B-blue?logo=python&logoColor=white)\n![PyTorch](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FPyTorch-2.11.0-EE4C2C?logo=pytorch&logoColor=white)\n![Streamlit](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FStreamlit-1.56.0-FF4B4B?logo=streamlit&logoColor=white)\n![scikit-learn](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fscikit--learn-1.8.0-F7931E?logo=scikit-learn&logoColor=white)\n![License](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Flicense-MIT-green)\n\n---\n\n## Table of Contents\n\n- [Overview](#-overview)\n- [Architecture](#-architecture)\n- [Project Structure](#-project-structure)\n- [Models](#-models)\n- [Agents](#-agents)\n- [Dashboard](#-dashboard)\n- [Installation](#-installation)\n- [Usage](#-usage)\n- [Data Flow](#-data-flow)\n- [Configuration](#-configuration)\n- [Dependencies](#-dependencies)\n\n---\n\n##  Overview\n\nSupermarket AI is built around three core pillars:\nhttps:\u002F\u002Fautomart-ai-q53a5utpzascgl8rpolcmw.streamlit.app\u002F\n\n| Pillar | Description |\n|--------|-------------|\n| **ML Models** | Train on historical sales data to find patterns, customer segments, and sales forecasts |\n| **Intelligent Agents** | Wrap models with business logic to produce human-readable, actionable insights |\n| **Interactive Dashboard** | A Streamlit web app that presents all outputs visually for non-technical managers |\n\n### Tech Stack\n\n| Layer | Technology | Purpose |\n|-------|-----------|---------|\n| Data | `pandas`, CSV files | Load, clean, and engineer features |\n| ML Models | `scikit-learn`, `mlxtend`, `PyTorch` | Clustering, association rules, forecasting |\n| Agents | Python + LangChain (optional) | Business logic + AI insights |\n| Dashboard | Streamlit | Interactive web UI |\n| AI Insights | LangChain + Google Gemini | LLM-powered marketing suggestions |\n\n---\n\n##  Architecture\n\n```\nCSV Files\n  supermarket_dummy_data.csv ──→ utils\u002Fpreprocessing.py ──→ Enriched DataFrame\n  transaction_dataset.csv    ──→ models\u002Fapriori_model.py ──→ Association Rules\n\nEnriched DataFrame\n  ├──→ models\u002Fkmeans_model.py    ──→ Customer Clusters\n  │      └──→ agents\u002Fcustomer_agent.py   ──→ High\u002FLow Value + Insights\n  │\n  ├──→ models\u002Flstm_pytorch.py    ──→ Next-Day Sales Prediction\n  │\n  ├──→ agents\u002Finventory_agent.py ──→ Demand \u002F Stock \u002F Festival Insights\n  │\n  └──→ agents\u002Fprofit_agent.py    ──→ Profit \u002F Loss Analysis\n\nAssociation Rules\n  └──→ agents\u002Frecommendation_agent.py ──→ Product Bundle Suggestions\n\nAll Agent Outputs\n  ├──→ app\u002Fdashboard.py   (Streamlit UI)\n  └──→ main.py            (CLI output)\n```\n\n---\n\n##  Project Structure\n\n```\nsupermarket-ai\u002F\n│\n├── data\u002F\n│   ├── supermarket_dummy_data.csv   # Main sales dataset\n│   └── transaction_dataset.csv      # Transaction records for basket analysis\n│\n├── utils\u002F\n│   └── preprocessing.py             # Data loading & feature engineering pipeline\n│\n├── models\u002F\n│   ├── kmeans_model.py              # Customer segmentation (K-Means)\n│   ├── apriori_model.py             # Product recommendations (Apriori)\n│   └── lstm_pytorch.py              # Sales forecasting (LSTM)\n│\n├── agents\u002F\n│   ├── customer_agent.py            # Customer value segmentation + insights\n│   ├── inventory_agent.py           # Demand, stock, and festival tracking\n│   ├── profit_agent.py              # Product and store-level profit analysis\n│   └── recommendation_agent.py      # Cross-sell and bundling opportunities\n│\n├── app\u002F\n│   └── dashboard.py                 # Streamlit web dashboard\n│\n├── main.py                          # CLI entry point\n└── requirements.txt                 # Python dependencies\n```\n\n---\n\n##  Models\n\n### K-Means Customer Segmentation (`models\u002Fkmeans_model.py`)\n\nGroups customers into **Low \u002F Medium \u002F High Value** segments based on purchase behaviour.\n\n**Pipeline:** Aggregate by Customer ID → Normalize with `StandardScaler` → Apply `KMeans(n_clusters=3)` → Rank by profit\n\n| Function | Purpose |\n|----------|---------|\n| `prepare_customer_data(df)` | Aggregates raw rows into one row per customer |\n| `scale_features(customer_df)` | Normalises Quantity_Sold and Profit |\n| `apply_kmeans(customer_df)` | Runs KMeans and appends Cluster column |\n| `segment_customers(df)` | Full pipeline: prepare → scale → cluster |\n| `label_clusters(df)` | Adds human-readable Segment column |\n| `cluster_summary(df)` | Mean quantity, mean profit, and count per cluster |\n\n---\n\n### Apriori Association Rules (`models\u002Fapriori_model.py`)\n\nAnswers the question: *\"If a customer buys Product A, how likely are they to buy Product B?\"*\n\n| Metric | Meaning |\n|--------|---------|\n| **Support** | How often an itemset appears across all transactions |\n| **Confidence** | How often B is bought given A is bought |\n| **Lift** | How much more likely B is when A is present vs. by chance (Lift > 1 = genuine association) |\n\n**Pipeline:** Load `transaction_dataset.csv` → Build basket matrix → Run Apriori (`min_support=0.01`) → Generate rules (`min_lift=1`) → Sort by lift\n\n---\n\n### LSTM Sales Forecasting (`models\u002Flstm_pytorch.py`)\n\nPredicts **next-day total sales quantity** using a recurrent neural network trained on historical daily sales.\n\n**Model Architecture:**\n```\nInput: [batch, 7 days, 1 feature]\n  → LSTM(input_size=1, hidden_size=50, batch_first=True)\n  → Linear(50 → 1)\nOutput: Predicted next-day quantity (single float)\n```\n\n**Pipeline:** Aggregate daily sales → Create 7-day sliding window sequences → Train for 10 epochs (MSELoss + Adam) → Predict from last 7 days\n\n---\n\n##  Agents\n\nEach agent exposes a single `*_agent_summary()` master function used by both the dashboard and CLI. Models are pure ML; agents add the business interpretation on top.\n\n### Customer Agent (`agents\u002Fcustomer_agent.py`)\nSegments customers and generates marketing strategies. Uses **Google Gemini** via LangChain if `GEMINI_API_KEY` is set, otherwise falls back to rule-based logic:\n- Profit > 500 → Offer loyalty rewards\n- Profit \u003C 200 → Provide discounts\n- Otherwise → Target with promotions\n\n### Inventory Agent (`agents\u002Finventory_agent.py`)\nTracks product demand, flags low-stock items, calculates restock quantities, and surfaces festival-driven demand spikes.\n\n**Restock Formula:**\n```\nIf Quantity_Sold \u003C 100:  restock = 150 - Quantity_Sold\nElse:                    restock = 0   (no action needed)\n```\n\n### Profit Agent (`agents\u002Fprofit_agent.py`)\nAnalyses profitability at the product level and store level. Identifies top performers and products running at a loss.\n\n### Recommendation Agent (`agents\u002Frecommendation_agent.py`)\nUses the Apriori model to surface product bundling and cross-sell opportunities. Reads from `transaction_dataset.csv`.\n\n---\n\n##  Dashboard\n\nLaunch the interactive Streamlit dashboard:\n\n```bash\nstreamlit run app\u002Fdashboard.py\n```\n\n**Page 1 — Sales & Inventory**\n- Sales trend line chart\n- One-click LSTM next-day sales prediction\n- Top profitable products bar chart\n- Low-stock alerts and restock suggestions\n- Festival demand highlights\n\n**Page 2 — Customers & Recommendations**\n- Interactive customer segmentation table\n- High-value and low-value customer breakdowns\n- AI-powered marketing insights\n- Top product association rules\n\n---\n\n##  Installation\n\n**1. Clone the repository**\n```bash\ngit clone https:\u002F\u002Fgithub.com\u002Fyour-username\u002Fsupermarket-ai.git\ncd supermarket-ai\n```\n\n**2. Create a virtual environment (recommended)**\n```bash\npython -m venv venv\nsource venv\u002Fbin\u002Factivate        # macOS\u002FLinux\nvenv\\Scripts\\activate           # Windows\n```\n\n**3. Install dependencies (CPU-only for deployment)**\n\n**Local (Windows\u002FmacOS\u002FLinux):**\n```bash\npip install -r requirements.txt\n```\n\n**Streamlit Cloud (Deploy Ready):**\n```\nPlatform auto-installs from files:\n- packages.txt: empty (no apt deps)\n- requirements-pytorch.txt: torch\u002Ftorchvision\u002Ftorchaudio (CPU auto-select)\n- requirements.txt: standard deps (streamlit etc.)\n\nNo manual pip; push to GitHub → deploy succeeds without --index-url or apt errors.\n```\n\n*Compatible with CPU-only environments like Streamlit Cloud.*\n\n\n**4. (Optional) Set your Google Gemini API key for AI-powered insights**\n```bash\nexport GEMINI_API_KEY=\"your-api-key-here\"   # macOS\u002FLinux\nset GEMINI_API_KEY=your-api-key-here        # Windows\n```\n\n---\n\n##  Usage\n\n### Run the Dashboard (recommended)\n```bash\nstreamlit run app\u002Fdashboard.py\n```\n\n### Run the Full Pipeline via CLI\n```bash\npython main.py\n```\n\nThe CLI runner executes every pipeline step in order and prints results to the terminal. Each step is wrapped in `try\u002Fexcept` so a single failure won't crash the entire run.\n\n| Step | What Runs | Output |\n|------|-----------|--------|\n| 1 | `preprocess_data()` | Loads and enriches the CSV |\n| 2 | `run_lstm(df)` | Trains LSTM, prints predicted next-day sales |\n| 3 | `label_clusters(df)` | Prints customer segments and cluster stats |\n| 4 | `get_rules()` | Prints top Apriori association rules |\n| 5 | `inventory_agent_summary(df)` | Prints demand, low stock, and alerts |\n| 6 | `customer_agent_summary(df)` | Prints high-value customers and insights |\n| 7 | `profit_agent_summary(df)` | Prints profit totals and loss warnings |\n| 8 | `recommendation_agent_summary()` | Prints top product bundle rules |\n\n---\n\n##  Data Flow\n\nThe preprocessing module is called **once** at startup — both `main.py` and `dashboard.py` pass the same enriched DataFrame to every downstream component, avoiding duplicate file reads.\n\n| Component | Depends On | Feeds Into |\n|-----------|-----------|-----------|\n| `preprocessing.py` | Raw CSV files | All models and agents |\n| `kmeans_model.py` | `preprocessing.py` output | `customer_agent.py`, `dashboard.py` |\n| `apriori_model.py` | `transaction_dataset.csv` | `recommendation_agent.py`, `dashboard.py` |\n| `lstm_pytorch.py` | `preprocessing.py` output | `dashboard.py`, `main.py` |\n| `customer_agent.py` | `kmeans_model.py` | `dashboard.py`, `main.py` |\n| `inventory_agent.py` | `preprocessing.py` output | `dashboard.py`, `main.py` |\n| `profit_agent.py` | `preprocessing.py` output | `dashboard.py`, `main.py` |\n| `recommendation_agent.py` | `apriori_model.py` | `dashboard.py`, `main.py` |\n\n---\n\n##  Configuration\n\nThe system works out of the box without any configuration. The only optional setting is:\n\n| Variable | Description | Default |\n|----------|-------------|---------|\n| `GEMINI_API_KEY` | Google Gemini API key for LLM-powered marketing insights in the Customer Agent | Falls back to rule-based insights |\n\n---\n\n##  Dependencies\n\n| Package | Version | Purpose |\n|---------|---------|---------|\n| `streamlit` | 1.56.0 | Web dashboard framework |\n| `pandas` | 3.0.2 | Data loading, manipulation, and aggregation |\n| `numpy` | 2.4.4 | Numerical operations and array handling |\n| `torch` | 2.11.0 | LSTM model training and inference |\n| `scikit-learn` | 1.8.0 | KMeans clustering and StandardScaler |\n| `mlxtend` | 0.24.0 | Apriori algorithm and association rules |\n| `langchain-core` | 1.3.2 | Agent framework for LLM-powered insights |\n| `matplotlib` | 3.10.9 | Charting support |\n| `scipy` | 1.17.1 | Scientific computing (used by mlxtend) |\n\n---\n\n##  Key Design Decisions\n\n- **Single preprocessing call** — `preprocess_data()` runs once; the enriched DataFrame is passed to every component.\n- **Agent pattern** — Each agent exposes one `*_summary()` master function, keeping the dashboard and CLI interfaces clean.\n- **Graceful AI fallback** — The Customer Agent tries Google Gemini first but always falls back to rule-based insights, so the system works without any API key.\n- **Models vs. Agents separation** — Models are pure ML (no business logic). Agents add the business interpretation on top of model outputs.\n- **Error isolation** — Every step in `main.py` is wrapped in `try\u002Fexcept` so a single model failure doesn't crash the entire pipeline.\n\n---\n\n\n*Built with ❤️ using Python, PyTorch, and Streamlit*\n","AutoMart-AI 是一个基于人工智能的超市分析系统，利用LSTM、K-Means和Apriori算法进行销售预测、客户细分、产品推荐及库存优化。项目采用代理架构并通过Streamlit提供交互式仪表板，核心技术栈包括Python、PyTorch、scikit-learn等。通过机器学习模型发现历史销售数据中的模式，智能代理将这些模型与业务逻辑结合以生成可操作的洞察报告。此外，还提供了直观易用的可视化界面，使得非技术人员也能轻松获取关键信息。此工具非常适合需要精细化管理顾客关系、提升运营效率以及增加收益的零售场景。",2,"2026-06-11 03:58:55","CREATED_QUERY"]