How aprendeingenia/shopping-ai works
Project Type and Purpose
• This is an edge‐oriented AI inference application (“Shopping-AI”) written in Python that performs real-time object detection of shopping items (fruits, vegetables, books, peripherals, etc.).
• Purpose: download a pre-trained model from Hugging Face, load it (PyTorch or ONNX), capture or ingest input frames/images, run inference, and pass detected items to a simple “store” business logic layer.
File Structure Analysis
Top-level
• README.md – project overview and instructions
• python_files/
– .gitignore
– get_pytorch_models.bat / get_onnx_models.bat (model-download scripts)
– requirements.txt
– ShoppingIA.py (inference module: load model, preprocess, detect)
– Tienda.py (business logic: manage detected items, pricing, “shopping cart”)
– main.py (application orchestrator: calls downloader, inference, business logic)
README Insights
• Emphasizes two supported runtimes: PyTorch and ONNX.
• Real-time, resource-constrained environments (e.g., peripheral devices).
• Uses advanced deep-learning frameworks.
• No frontend server or UI beyond CLI or local display.
Main Components
a. External Model Repository (Hugging Face)
b. Model Downloader Scripts (.bat files)
c. Local Model Storage (folder on disk)
d. Inference Module (ShoppingIA.py)
– Subcomponents:
• Model Loader (PyTorch / ONNX runtime)
• Preprocessor (resize, normalize)
• Detector (forward pass + postprocess)
e. Business Logic Module (Tienda.py)
– Shopping cart management, item lookup, pricing
f. Orchestrator (main.py)
– Initialization, selecting runtime, wiring modules
g. Input Source
– Camera / Video feed / Image input
h. Output Sink
– CLI console / Optional display overlay
i. Dependencies
– PyTorch / ONNX Runtime
– OpenCV or image-capture library
– Other Python libraries (from requirements.txt)
Relationships and Data Flow
1) User runs main.py ➔
2) main.py invokes model-download scripts if models not present ➔
3) model files saved to local storage ➔
4) Inference Module loads model ➔
5) Inference Module pulls frames from Input Source ➔
6) Preprocessor transforms frames ➔
7) Detector runs inference ➔
8) Detected items + metadata passed to Business Logic Module ➔
9) Business Logic outputs “shopping cart” summary to Output Sink
Architectural Patterns and Design Principles
• Modular layering: downloader, inference, business logic, orchestrator
• Strategy pattern for supporting multiple runtimes (PyTorch vs ONNX)
• Pipeline for data flow: capture ➔ preprocess ➔ infer ➔ postprocess ➔ consume
• Separation of concerns: detection vs shopping‐cart management