🦅 Pharma-Assist 2.0: A Sovereign Local AI Agent Network for Real-Time Pharmacy Audit
🏷️ Category Credentials
- Challenge Track: Build With Gemma 4
- Submission Tags:
#gemmachallenge,#ai,#opensource,#python,#privacy
🏛️ 1. The Real-World B2B Pain Point
In the pharmaceutical and logistics industries, administrative staff spend up to 70% of their working hours manually reconciling invoices, checking delivery sheets (albaranes), and calculating trade margins.
This causes three critical operational bottlenecks:
- The Margin Drain: Surcharges, cooperative rebate discrepancies, and minor billing errors from major distributors (e.g., Cofares, Hefame, Alliance) go unnoticed, draining thousands of euros annually.
- Legal Liability: Invoices containing sensitive patient data, sanitary cards, and proprietary pricing metrics are routinely uploaded to public SaaS clouds (like public ChatGPT wrappers) for quick parsing, resulting in catastrophic GDPR compliance breaches.
- API Tolls: Processing high-volume transactions via cloud-based LLM APIs results in heavy monthly recurring subscription fees.
🚀 2. Our Sovereign Solution: The Local AI Bunker
Pharma-Assist 2.0 is a fully open-source, self-contained Local AI Bunker running entirely on-premises inside the company's LAN network. Powered by local Gemma / Qwen model architectures via Ollama, it automates high-volume document auditing with zero cloud dependencies, zero API costs, and absolute data privacy.
🌟 Core Tech Features:
- 100% Secure Local Isolation: Financial audit, OCR parsing, and regular expression evaluations are processed entirely within the local GPU/VRAM memory.
- Dynamic Margin Audit Engine: Automatically cross-references distributor unit costs, discounts, and retail pricing, flagging any item falling below the mandatory 12% commercial margin.
- Glassmorphic Control Dashboard: An elite B2B web interface that acts as the command center, featuring model conmuting, real-time latency indicators, and an interactive "Fire Drill" simulation module.
🏗️ 3. System Architecture & Flow
graph TD
LAN[Red Local de Oficina - LAN] -->|HTTPS| Proxy[Nginx Reverse Proxy]
Proxy -->|REST API| Dashboard[Glassmorphic HTML5/JS Dashboard]
Proxy -->|REST API| Facilix[Facilix Orchestrator Server: Port 3002]
Facilix -->|JSON Payload| Ollama[Ollama Core Engine: Port 11434]
Ollama -->|GPU Infece| Models[Local Qwen2.5-Coder / Gemma 2B]
Facilix -->|Write Report| DB[error_reports.json Database]
⚙️ 4. Technical Implementation & Code Highlights
The brain of the system is the Local Invoice Auditor (agents/pharmacy_invoice_auditor.py), which executes high-speed mathematical auditing combined with local LLM semantic evaluation.
Here is how the core mathematical and compliance auditing logic is constructed:
# --- LÓGICA DE CONCILIACIÓN DE MÁRGENES (12% MÍNIMO) ---
net_cost = cost * (1.0 - (disc / 100.0))
if retail > 0:
margin = ((retail - net_cost) / retail) * 100
else:
margin = 0
if margin < 12.0:
loss = (net_cost - (retail * 0.88)) # Projected financial loss
if loss > 0:
total_loss += loss
errors.append(f"ALERTA_MARGEN: Margen comercial del {margin:.2f}% (Mínimo requerido: 12%).")
🧠 Semantic Error Parsing via Local Qwen:
For advanced textual anomalies, the auditor queries our offline Qwen/Gemma instance:
def call_local_qwen(prompt_text):
payload = {
"model": "qwen2.5-coder:7b",
"prompt": f"{SYSTEM_RULES}\nAnaliza la siguiente transacción:\n{prompt_text}",
"stream": False,
"format": "json"
}
r = requests.post("http://localhost:11434/api/generate", json=payload, timeout=8)
return json.loads(r.json().get("response", "{}"))
🖥️ 5. The Glassmorphic Interface & "Fire Drill" Simulator
To present this to corporate decision-makers (such as CEOs and Operations Managers of large Logistics and Real Estate firms), we built a stunning web-based dashboard:
- Model Selector Card: Switch on the fly with a single click between Local Qwen (high-speed local processing), Hybrid Gemini (optimized processing), and Cloud Claude (external fallback).
- The Live "Fire Drill" (Simulacro de Fuego Real): Allows users to select 5 real Madrid-based leads from a dropdown menu, loading their specific corporate profiles (e.g., TIBA Group, Walter Haus). Users can click the dotted drag-and-drop zone to run a mock document audit, trigger a live scanning animation, and render dynamic metrics (e.g., "$8,900 in financial risk protected" or "340 administrative minutes saved").
🏆 6. Why Gemma & Local Models Make B2B AI High-Ticket Viable
Deploying large cloud models for high-volume invoice and catalog sorting is a financial black hole. By running Gemma / Qwen locally, businesses can:
- Amortize Hardware Instantly: The cost of a dedicated local workstation (NVIDIA RTX 4090) is fully amortized within the first two months.
- Sovereign Compliance: Medical prescriptions and proprietary catalog prices remain strictly local, completely immune to internet outages, data leaks, or foreign server hacks.
📂 7. Repository & Installation
The complete open-source repository is available under the MIT License.
💻 Quick Start:
-
Clone the Repo & Install Dependencies:
git clone https://github.com/yourusername/pharma-assist-2.0.git cd pharma-assist-2.0 pip install requests -
Run the Background Service:
python facilix_service.py -
Run a Test Audit:
python agents/pharmacy_invoice_auditor.py Open the Console: Double-click
antigravity_core_dashboard.htmlin your browser to start conmuting models and running live document simulations on port 3002!
Created by Antigravity — Powering local, private, and high-performance AI bunkers for enterprise elite.
Top comments (0)