Expanic commited on
Commit
0227d98
Β·
1 Parent(s): 14144d6

docs: rewrite README with full setup guide, demo link, BPOM regulation references, and test case instructions

Browse files
Files changed (1) hide show
  1. README.md +233 -9
README.md CHANGED
@@ -1,8 +1,8 @@
1
  ---
2
  title: PRESUNI BPOM
3
- emoji: πŸ“š
4
- colorFrom: yellow
5
- colorTo: purple
6
  sdk: gradio
7
  sdk_version: 6.15.2
8
  python_version: '3.13'
@@ -10,12 +10,236 @@ app_file: app.py
10
  pinned: false
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
14
 
15
- # BPOM Compliance AI System
16
 
17
- Aplikasi cerdas untuk mengecek kepatuhan produk pangan dan suplemen berdasarkan standar BPOM menggunakan metode Hybrid (Rule-based Deterministik + AI LLM/RAG).
18
 
19
- **Dokumentasi & Contoh Output Lengkap**
20
- Bagi pengguna atau developer yang ingin memahami arsitektur lengkap, mekanisme rule-based, hingga melihat contoh output dan skema proses aplikasi secara mendalam, silakan baca dokumentasi detail kami di file berikut:
21
- πŸ‘‰ [blueprint.md](./blueprint.md)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  title: PRESUNI BPOM
3
+ emoji: πŸ›οΈ
4
+ colorFrom: blue
5
+ colorTo: indigo
6
  sdk: gradio
7
  sdk_version: 6.15.2
8
  python_version: '3.13'
 
10
  pinned: false
11
  ---
12
 
13
+ <div align="center">
14
 
15
+ # πŸ›οΈ BPOM Compliance AI System
16
 
17
+ **Sistem Cerdas Pemeriksaan Kepatuhan Registrasi Produk Pangan Berbasis AI**
18
 
19
+ [![Hugging Face Space](https://img.shields.io/badge/πŸ€—%20Demo-Hugging%20Face%20Space-blue)](https://huggingface.co/spaces/Expanic/PRESUNI_BPOM)
20
+ [![Python](https://img.shields.io/badge/Python-3.9+-3776AB?logo=python&logoColor=white)](https://python.org)
21
+ [![Gradio](https://img.shields.io/badge/Gradio-UI-orange?logo=gradio)](https://gradio.app)
22
+ [![Gemini](https://img.shields.io/badge/Google%20Gemini-AI-4285F4?logo=google&logoColor=white)](https://ai.google.dev)
23
+
24
+ [**πŸš€ Coba Demo Langsung**](https://huggingface.co/spaces/Expanic/PRESUNI_BPOM) Β· [**πŸ“˜ Blueprint Teknis**](./blueprint.md) Β· [**πŸ§ͺ Contoh Test Case**](./TEST_CASES.md)
25
+
26
+ </div>
27
+
28
+ ---
29
+
30
+ ## πŸ“‹ Apa Itu Aplikasi Ini?
31
+
32
+ **BPOM Compliance AI** adalah aplikasi berbasis web yang secara otomatis memeriksa apakah produk pangan/suplemen memenuhi standar keamanan **BPOM (Badan Pengawas Obat dan Makanan)** Republik Indonesia.
33
+
34
+ Pengguna cukup meng-upload **laporan uji laboratorium** (PDF/DOCX) atau mengetik data hasil uji secara manual, lalu sistem akan:
35
+
36
+ 1. πŸ” **Mengekstrak** data cemaran mikroba, logam berat, dan informasi produk secara otomatis
37
+ 2. 🏷️ **Mengklasifikasi** kategori produk (Suplemen, Dairy, Daging Olahan, Buah & Sayur)
38
+ 3. βš–οΈ **Memeriksa kepatuhan** setiap parameter secara deterministik terhadap ambang batas resmi BPOM
39
+ 4. πŸ€– **Menjelaskan** hasil pelanggaran dalam bahasa Indonesia yang mudah dipahami menggunakan AI (Gemini)
40
+ 5. πŸ“„ **Menghasilkan laporan** final dalam format PDF yang siap cetak
41
+
42
+ ### Arsitektur Hybrid: Rule-Based + AI
43
+
44
+ | Komponen | Metode | Kenapa? |
45
+ |---|---|---|
46
+ | Pengecekan Lulus/Gagal | **Rule-Based (Deterministik)** | Kepastian hukum mutlak β€” tidak boleh ada halusinasi AI |
47
+ | Klasifikasi Produk | **Hybrid (Keyword + LLM Fallback)** | Keyword matching cepat, LLM hanya dipanggil jika ambigu |
48
+ | Penjelasan Pelanggaran | **RAG + LLM (Gemini)** | Menjelaskan mengapa gagal, lengkap dengan pasal hukum |
49
+ | Referensi Hukum | **Vector DB (ChromaDB)** | Semantic search ke dokumen peraturan BPOM asli |
50
+
51
+ ---
52
+
53
+ ## πŸ“š Dasar Regulasi BPOM
54
+
55
+ Seluruh ambang batas dan aturan dalam sistem ini **bersumber langsung dari peraturan resmi BPOM** yang diunduh dari [JDIH BPOM](https://jdih.pom.go.id/):
56
+
57
+ | Peraturan | Ruang Lingkup | Digunakan Untuk |
58
+ |---|---|---|
59
+ | **PerBPOM No. 13 Tahun 2019** | Batas Maksimal Cemaran Mikroba dalam Pangan Olahan | Pengecekan ALT, Coliform, E.coli, Salmonella, S.aureus, Kapang/Khamir, B.cereus |
60
+ | **PerBPOM No. 9 Tahun 2022** | Persyaratan Cemaran Logam Berat dalam Pangan Olahan | Pengecekan Timbal (Pb), Kadmium (Cd), Merkuri (Hg), Arsen (As) |
61
+ | **PerBPOM No. 22 Tahun 2021** | Cara Produksi Pangan Olahan yang Baik (CPPOB) | Checklist sanitasi, higiene, penyimpanan, dan transportasi |
62
+
63
+ ### Kategori Produk yang Didukung
64
+
65
+ | Kategori | Contoh Produk |
66
+ |---|---|
67
+ | `SUPLEMEN` | Suplemen kesehatan, multivitamin, herbal kapsul |
68
+ | `DAIRY` | Susu UHT, yoghurt, keju olahan |
69
+ | `DAGING_OLAHAN` | Sosis, nugget, kornet, bakso kemasan |
70
+ | `BUAH_SAYUR` | Jus buah kemasan, sayur beku, manisan buah |
71
+
72
+ ---
73
+
74
+ ## πŸš€ Cara Menggunakan
75
+
76
+ ### Opsi 1: Langsung Coba Online (Tanpa Install)
77
+
78
+ Buka demo yang sudah di-deploy di Hugging Face Spaces:
79
+
80
+ πŸ‘‰ **[https://huggingface.co/spaces/Expanic/PRESUNI_BPOM](https://huggingface.co/spaces/Expanic/PRESUNI_BPOM)**
81
+
82
+ ---
83
+
84
+ ### Opsi 2: Jalankan Sendiri di Lokal
85
+
86
+ #### Prasyarat
87
+ - Python 3.9 atau lebih baru
88
+ - API Key Google Gemini (gratis)
89
+
90
+ #### Step 1: Clone Repository
91
+
92
+ ```bash
93
+ git clone https://github.com/Expanics/PRESUNIV_BPOM.git
94
+ cd PRESUNIV_BPOM
95
+ ```
96
+
97
+ #### Step 2: Buat Virtual Environment & Install Dependencies
98
+
99
+ ```bash
100
+ python -m venv venv
101
+ source venv/bin/activate # Mac / Linux
102
+ # venv\Scripts\activate # Windows
103
+
104
+ pip install -r requirements.txt
105
+ ```
106
+
107
+ #### Step 3: Dapatkan API Key dari Google AI Studio
108
+
109
+ 1. Buka **[Google AI Studio](https://aistudio.google.com/apikey)**
110
+ 2. Klik **"Create API Key"**
111
+ 3. Copy API Key yang dihasilkan (format: `AIzaSy...`)
112
+
113
+ #### Step 4: Buat File `.env`
114
+
115
+ Buat file `.env` di root project:
116
+
117
+ ```bash
118
+ echo "GEMINI_API_KEY=PASTE_API_KEY_KAMU_DISINI" > .env
119
+ ```
120
+
121
+ Contoh isi `.env`:
122
+ ```env
123
+ GEMINI_API_KEY=AIzaSyC1234567890abcdefghijklmnop
124
+ ```
125
+
126
+ > ⚠️ **Jangan commit file `.env` ke GitHub!** File ini berisi API key pribadi kamu.
127
+
128
+ #### Step 5: (Opsional) Update Database Regulasi
129
+
130
+ Jika kamu menambahkan PDF regulasi BPOM baru ke folder `data/regulations/`, jalankan:
131
+
132
+ ```bash
133
+ python src/ingest.py
134
+ ```
135
+
136
+ #### Step 6: Jalankan Aplikasi
137
+
138
+ ```bash
139
+ python src/app.py
140
+ ```
141
+
142
+ Buka browser di **[http://127.0.0.1:7860](http://127.0.0.1:7860)** πŸŽ‰
143
+
144
+ ---
145
+
146
+ ## πŸ§ͺ Cara Mencoba / Test Case
147
+
148
+ Tersedia **3 skenario pengujian** di file [`TEST_CASES.md`](./TEST_CASES.md) yang bisa langsung di-copy-paste ke dalam aplikasi:
149
+
150
+ | No | Skenario | Deskripsi | Hasil yang Diharapkan |
151
+ |----|----------|-----------|----------------------|
152
+ | 1 | **Full Approve** βœ… | Semua parameter lolos | Semua PASS, narasi positif |
153
+ | 2 | **Partial Violations** ⚠️ | Coliform, Kapang, Timbal, Arsen melebihi batas | 4 parameter FAIL, sisanya PASS |
154
+ | 3 | **Full Fail** ❌ | Semua cemaran gagal + klaim obat ilegal | Semua FAIL + peringatan klaim terlarang |
155
+
156
+ ### Cara Coba:
157
+ 1. Buka aplikasi β†’ Tab **"1. πŸ“₯ Input Dokumen"**
158
+ 2. Buka file [`TEST_CASES.md`](./TEST_CASES.md), copy salah satu blok teks
159
+ 3. Paste ke area **"Atau Masukkan Teks Manual"**
160
+ 4. Klik **"πŸ” Analisis Dokumen"**
161
+ 5. Cek hasilnya di Tab **"2. πŸ“‹ Review Hasil AI"**
162
+ 6. Klik **"βœ… Setuju & Buat Laporan Final"** untuk generate laporan PDF
163
+
164
+ ---
165
+
166
+ ## πŸ—οΈ Struktur Project
167
+
168
+ ```
169
+ PRESUNIV_BPOM/
170
+ β”œβ”€β”€ app.py # Entry point (untuk Hugging Face Spaces)
171
+ β”œβ”€β”€ requirements.txt # Daftar library Python
172
+ β”œβ”€β”€ .env # API Key Gemini (JANGAN di-commit)
173
+ β”œβ”€β”€ blueprint.md # Dokumentasi teknis lengkap
174
+ β”œβ”€β”€ TEST_CASES.md # Contoh data input untuk pengujian
175
+ β”‚
176
+ β”œβ”€β”€ src/ # Source code utama
177
+ β”‚ β”œβ”€β”€ app.py # UI Gradio & state management
178
+ β”‚ β”œβ”€β”€ extractor.py # Ekstraktor teks β†’ JSON (Regex + OCR)
179
+ β”‚ β”œβ”€β”€ classifier.py # Klasifikasi kategori produk
180
+ β”‚ β”œβ”€β”€ rule_engine.py # Core: pengecekan PASS/FAIL deterministik
181
+ β”‚ β”œβ”€β”€ rag_query.py # Semantic search ke ChromaDB
182
+ β”‚ β”œβ”€β”€ llm_narrator.py # Narasi penjelasan AI (Gemini)
183
+ β”‚ β”œβ”€β”€ report_generator.py # Generator laporan PDF & Markdown
184
+ β”‚ └── ingest.py # Ingest regulasi PDF ke vector DB
185
+ β”‚
186
+ β”œβ”€β”€ rules/ # Ambang batas BPOM (JSON)
187
+ β”‚ β”œβ”€β”€ microba_rules.json # PerBPOM No. 13/2019 β€” Cemaran Mikroba
188
+ β”‚ β”œβ”€β”€ logam_berat_rules.json # PerBPOM No. 9/2022 β€” Logam Berat
189
+ β”‚ └── cppob_rules.json # PerBPOM No. 22/2021 β€” CPPOB
190
+ β”‚
191
+ β”œβ”€β”€ data/regulations/ # PDF peraturan BPOM asli (dari JDIH)
192
+ β”‚ β”œβ”€β”€ SUPLEMEN/
193
+ β”‚ β”œβ”€β”€ DAIRY/
194
+ β”‚ β”œβ”€β”€ DAGING_OLAHAN/
195
+ β”‚ └── BUAH_SAYUR/
196
+ β”‚
197
+ β”œβ”€β”€ chroma_db/ # Vector database (auto-generated)
198
+ └── prompts/ # Template prompt untuk LLM
199
+ ```
200
+
201
+ ---
202
+
203
+ ## βš™οΈ Tech Stack
204
+
205
+ | Komponen | Teknologi |
206
+ |---|---|
207
+ | **UI / Frontend** | Gradio |
208
+ | **Generative AI** | Google Gemini 1.5 Flash |
209
+ | **Vector Database** | ChromaDB (Persistent) |
210
+ | **Embedding** | `sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2` |
211
+ | **Ekstraksi PDF** | pdfplumber + pytesseract (OCR fallback) |
212
+ | **Ekstraksi DOCX** | python-docx |
213
+ | **Laporan PDF** | FPDF2 |
214
+
215
+ ---
216
+
217
+ ## πŸ”’ Keamanan & Privasi Data
218
+
219
+ - **Proses Rule-Based** berjalan 100% lokal β€” data TIDAK dikirim ke server manapun
220
+ - **Proses AI (narasi)** mengirim ringkasan data ke Google Gemini API
221
+ - Untuk kebutuhan enterprise/rahasia: ganti Gemini dengan LLM open-source lokal (misal Llama 3)
222
+
223
+ ---
224
+
225
+ ## πŸ“– Dokumentasi Lengkap
226
+
227
+ Untuk memahami arsitektur, schema data, workflow tiap modul, dan cara menambahkan kategori produk baru, baca dokumentasi teknis lengkap di:
228
+
229
+ πŸ‘‰ [**blueprint.md**](./blueprint.md)
230
+
231
+ ---
232
+
233
+ ## πŸ“ Lisensi
234
+
235
+ Project ini dibuat untuk keperluan akademis Universitas Presiden (*President University*).
236
+
237
+ ---
238
+
239
+ <div align="center">
240
+
241
+ **Dibuat dengan ❀️ untuk keamanan pangan Indonesia**
242
+
243
+ *Seluruh aturan bersumber dari [JDIH BPOM](https://jdih.pom.go.id/) β€” Badan Pengawas Obat dan Makanan Republik Indonesia*
244
+
245
+ </div>