Build an AI Agent for Automated Warehouse Management with Barcode Recognition and NocoDB Updates Using Qwen VL on VPS
Detailed guide to building an AI agent that automatically recognizes barcodes and updates inventory data into NocoDB using Qwen VL on a VPS.
Image credit: 2857440 · Pixabay Content License
Build an AI Agent for Automated Warehouse Management with Barcode Recognition
In the digital age, effective and automated warehouse management is a key factor in helping businesses reduce costs, speed up processing, and minimize errors. An AI agent combined with a barcode recognition model like Qwen VL (from Alibaba Cloud) can automatically scan, analyze, and update inventory data into management systems such as NocoDB. This guide will walk you through building this system on a VPS with high RAM, suitable for self-hosting AI models.
Requirements and Environment Setup
To deploy the system, you need:
- VPS with 16GB RAM or more (see: High-RAM Cloud VPS for Self-Hosted LLMs & API Gateways)
- Operating system: Ubuntu 22.04 LTS
- Python 3.10+
- Connected IP camera or USB webcam
Install Required Tools
Run the following commands on the VPS to set up the environment:
# Update the system
sudo apt update && sudo apt upgrade -y
# Install Python and pip
sudo apt install python3 python3-pip python3-venv -y
# Create a virtual environment
python3 -m venv ai_stock_env
source ai_stock_env/bin/activate
# Install necessary libraries
pip install opencv-python numpy requests pillow qwen-vl
Set Up NocoDB and API
NocoDB is a self-hosted data management platform similar to Airtable. You can install it on your VPS or use the hosted version at nocodb.com.
Create Database Table in NocoDB
Set up a new table with the following columns:
| Column Name | Type | Notes |
|---|---|---|
| Product Code | Text | Product code |
| Product Name | Text | Product name |
| Quantity | Number | Quantity |
| Barcode Image | File | Barcode image |
| Last Updated | Date | Update time |
Configure NocoDB API
Access the API Key in NocoDB and save it. Use this API to update data from the AI agent.
import requests
import json
# NocoDB configuration
BASE_URL = "https://your-nocodb-url.com/api/v1"
TABLE_ID = "your-table-id"
API_KEY = "your-api-key"
def update_nocodb(product_code, product_name, quantity):
headers = {
"xc-token": API_KEY,
"Content-Type": "application/json"
}
data = {
"Product Code": product_code,
"Product Name": product_name,
"Quantity": quantity,
"Last Updated": "now"
}
response = requests.post(f"{BASE_URL}/tables/{TABLE_ID}/records", headers=headers, data=json.dumps(data))
return response.status_code
Perform Barcode Recognition with Qwen VL
Qwen VL is a multimodal model that supports image recognition, including barcodes. Here’s an example of processing images from a camera and extracting barcodes:
from qwen_vl import QwenVL
import cv2
import numpy as np
# Initialize the model
model = QwenVL(model_name="qwen-vl")
# Capture image from camera
cap = cv2.VideoCapture(0)
ret, frame = cap.read()
cv2.imwrite("barcode.jpg", frame)
cap.release()
# Recognize barcode
result = model.ocr("barcode.jpg", task="barcode")
if result:
barcode = result[0]["text"]
print(f"Detected barcode: {barcode}")
else:
print("No barcode detected.")
Run the AI Agent Automatically
Run a script that automatically scans, recognizes, and updates data:
import time
import os
from datetime import datetime
# Main script
while True:
# Capture image
os.system("fswebcam -r 1280x720 --no-banner barcode.jpg")
# Recognize barcode
result = model.ocr("barcode.jpg", task="barcode")
if result:
barcode = result[0]["text"]
# Assume product lookup logic
product_name = "Product A"
quantity = 100
# Update NocoDB
status = update_nocodb(barcode, product_name, quantity)
print(f"Updated NocoDB: {status}")
else:
print("No barcode found.")
# Wait 5 seconds
time.sleep(5)
Testing and Troubleshooting
- Barcode not recognized: Check lighting, image clarity, and barcode position.
- NocoDB API errors: Verify API Key, URL, and table access permissions.
- AI agent not running: Check logs, RAM usage, and service status.
References
High-RAM Cloud VPS Plans Optimized for AI, Databases & Cache
Enterprise RAID 10 NVMe SSDs, CMC & FPT District 9 uplinks with Anycast Anti-DDoS and 99.99% SLA.
VPS-4E
10% VAT included
- CPU: 4 vCPU
- RAM: 8 GB
- SSD: 50 GB NVMe
