An intelligent full-stack web application that analyzes food product ingredients and classifies them as Halal, Haram, or Mushbooh (Doubtful) using a hybrid pipeline of OCR, semantic similarity, and Retrieval-Augmented Generation (RAG).
Scan4Halal bridges the gap between raw ingredient labels and consumer understanding by combining:
- πΈ OCR-based text extraction
- π§ Semantic embedding + similarity matching
- π Curated halal knowledge base
- π€ LLM-powered contextual explanations
The system enables users to scan, analyze, understand, and store ingredient insights in a seamless workflow.
Image Upload
β
OCR (PyTesseract)
β
Text Preprocessing
β
Ingredient Parsing
β
Multi-Stage Matching Pipeline
β
Semantic Similarity (Embeddings)
β
Halal Classification
β
RAG Explanation (LLM)
β
Frontend Display + User Actions
-
React + DaisyUI SPA
-
Handles:
- Image upload
- Results visualization
- Chat interface
- Bookmarking & history
-
Centralized request handling
-
JWT-based authentication
-
Routes:
- OCR processing
- Ingredient matching
- RAG explanation
- User operations
- Extracts raw text using PyTesseract
-
Regex + string normalization
-
Removes noise like:
- "Ingredients:"
- Special characters
- Formatting inconsistencies
A 3-stage hybrid matching system:
-
Exact Matching
- Direct string comparison
-
Fuzzy Matching
- Handles typos using Levenshtein distance
-
Semantic Similarity Engine
-
Uses embeddings for contextual understanding
-
Matches:
- Synonyms
- E-numbers
- Misspellings
-
- SentenceTransformers (
all-MiniLM-L6-v2) - Fine-tuned on ingredient variants
- Generates 384-dimensional vectors
- Cosine similarity using NumPy
- Finds closest ingredient match in database
-
Powered by Mistral 7B (via Hugging Face)
-
Combines:
- Retrieved ingredient context
- LLM generation
-
Produces human-readable explanations
Collections:
ingredientsβ canonical data + embeddingsusersβ authentication + profilesscansβ historybookmarksβ saved ingredientssubmissionsβ unknown ingredient requests
Traditional systems rely on exact matching. Scan4Halal introduces embedding-based semantic matching:
-
Handles:
- βE471β β βMono- and Diglyceridesβ
- Misspellings
- Variants across regions
-
Enables:
- High accuracy with small datasets (~100+ ingredients)
- Reduced dependency on strict naming conventions
- Base Model:
all-MiniLM-L6-v2 - Training Platform: Google Colab + Hugging Face
- Generated 700,000+ pairs
- Balanced to 8,000+ high-quality pairs
- Positive pairs β synonym matches
- Negative pairs β unrelated ingredients
-
Improved recognition of:
- Variants
- Abbreviations
- E-number mappings
Each ingredient is classified into:
| Status | Meaning |
|---|---|
| β Halal | Permissible |
| β Haram | Forbidden |
| Doubtful / unclear |
Custom taxonomy:
ENA-1000+β E-NumbersNOI-2000+β Natural IngredientsNUS-3000+β NutrientsPAM-4000+β Additives
Each entry includes:
- Synonyms
- Halal status
- Source
- Processing info
- Usage context
- React
- Tailwind CSS + DaisyUI
- Context API
- Flask
- Flask-JWT-Extended
- PyMongo
- PyTesseract (OCR)
- Sentence Transformers
- NumPy (cosine similarity)
- Mistral 7B (RAG)
- MongoDB Atlas
- VS Code
- Postman
- Git & GitHub
- Google Colab
cd scan4halal-backend
python -m venv venv
venv\Scripts\activate
pip install -r requirements.txtCreate .env:
MONGO_URI=your_mongodb_uri
JWT_SECRET_KEY=your_secretRun:
python app.pycd scan4halal-frontend
npm install
npm start| Method | Endpoint | Description |
|---|---|---|
| POST | /ocr |
Extract text |
| POST | /match |
Ingredient classification |
| POST | /rag/explain |
AI explanation |
| POST | /rag/chat |
Chat interaction |
| POST | /bookmark |
Save ingredient |
| GET | /bookmarks |
Retrieve bookmarks |
- Muslim consumers verifying food products
- Educational tool for ingredient awareness
- Smart retail or scanning applications
-
Limited Training Data The semantic embedding model was trained on a relatively small and curated dataset of ingredients and their variants. As a result, the system may struggle when processing real-world product labels that contain unfamiliar, rare, or untrained ingredients. This can lead to a higher number of ingredients being classified as unknown or requiring further verification.
-
Surface-Level Halal Verification The system performs analysis primarily at the ingredient level based on available label information. However, true halal verification often depends on deeper factors such as:
- Source of ingredients (e.g., animal-derived vs plant-based)
- Processing methods
- Cross-contamination during manufacturing
- Certification standards
Since such information is typically not disclosed on product labels, the system cannot provide definitive halal certification, but rather serves as an informational and decision-support tool.
π Expand and Continuously Update Ingredient Dataset Increase the size and diversity of the training dataset to better handle real-world ingredient variations and reduce the number of unknown classifications.
π§ Adaptive Learning / Feedback Loop Incorporate user-submitted ingredients and feedback into the system to continuously improve model accuracy and database coverage. π Deeper Ingredient Context Awareness Enhance the system to consider additional factors such as ingredient sources, processing methods, and certification data where available, moving beyond surface-level label analysis.
π·οΈ Positioning as a General Ingredient Awareness Tool Extend the application beyond halal verification to serve as an ingredient awareness platform for all consumers, providing insights into:
- Additives and preservatives
- Nutritional and health implications
- Potential allergens or dietary concerns
This broadens the usability of the system and makes it valuable for a wider audience focused on informed food choices and transparency.
- π± Mobile app version
- π· Barcode scanning
- π Multi-language support
- β‘ Vector database integration (Pinecone / Weaviate)
- βοΈ External model hosting
- Type: Final Year Dissertation Project
- Duration: June 2025 β Sep 2025
- Affiliation: Cardiff Metropolitan University
Mazeena Cader
Software Engineering Graduate | MERN Stack Developer | ML Enthusiast
π Portfolio: https://mazeenacader.netlify.app
This project is developed for academic and educational purposes.
Give this project a β on GitHub!
