Spaces:
Sleeping
Sleeping
File size: 9,148 Bytes
30fba05 06e2bcc 2e7cd2a 06e2bcc 2e7cd2a 06e2bcc 2e7cd2a 06e2bcc 2e7cd2a 06e2bcc 2e7cd2a 06e2bcc 131632b 2e7cd2a 06e2bcc 2e7cd2a bcad276 06e2bcc bcad276 06e2bcc bcad276 06e2bcc 2e7cd2a 06e2bcc | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | ---
title: Placebo AI
emoji: π§
colorFrom: blue
colorTo: indigo
sdk: docker
app_port: 7860
pinned: false
---
<div align="center">
# π§ Placebo AI
### Medical Intelligence Platform β Serverless RAG at LPU Speed
[](https://trinetralabs-placeboai.hf.space/)
[](#license)
[](#)
[](#)
[](https://groq.com/)
**Instant, medically-grounded answers backed by 1.3M+ medical text vectors β with zero local disk footprint.**
[Live Demo](https://trinetralabs-placeboai.hf.space/) Β· [Architecture](#-architecture) Β· [Setup](#%EF%B8%8F-installation--setup) Β· [Deployment](#-deployment)
</div>
---
## π Overview
**Placebo AI** is a cloud-native medical intelligence platform that combines retrieval-augmented generation (RAG) with a fully serverless data layer. Rather than shipping a multi-gigabyte vector index alongside the application, Placebo AI offloads all heavy assets β embeddings, document text, and images β to managed cloud services, leaving the application itself lightweight, stateless, and trivially deployable to any container platform.
The result is a system that can answer nuanced medical questions with grounded, source-backed context, streamed back to the user in near real-time thanks to Groq's LPU (Language Processing Unit) inference engine.
> **Disclaimer:** Placebo AI is an informational and educational tool. It is not a substitute for professional medical diagnosis, advice, or treatment. Always consult a qualified healthcare provider for medical concerns.
---
## ποΈ Architecture
Placebo AI's architecture was deliberately redesigned to eliminate the operational fragility of local, disk-resident datasets. The migration removed a 17GB vector store and an 88GB image corpus from the application's runtime footprint entirely, replacing them with serverless equivalents that scale independently of the app container.
```mermaid
flowchart LR
U[User Browser] -->|HTTPS| FE[Frontend<br/>Glassmorphic UI]
FE -->|JWT Auth| AUTH[Supabase Auth]
FE -->|Query| API[FastAPI Backend]
API -->|Keyword-Augmented<br/>Retrieval| ASTRA[(Astra DB<br/>Serverless Vector Search)]
API -->|Asset Fetch| HFDS[(HuggingFace Datasets<br/>Docs & Images)]
API -->|Grounded Prompt| GROQ[Groq LPU<br/>Llama-3.1-8b-instant]
ASTRA -->|Top-K Context| API
HFDS -->|Media/Refs| API
GROQ -->|Streamed Tokens| API
API -->|SSE Stream| FE
```
### Design Principles
| Principle | Implementation |
|---|---|
| **Zero local footprint** | All vector and asset data lives in managed cloud stores; the container ships with no bundled dataset. |
| **Stateless compute** | The FastAPI backend holds no persistent state, enabling horizontal scaling and instant cold starts. |
| **Grounded generation** | Retrieval context is injected into strict XML-bounded prompts to reduce hallucination and keep the model anchored to retrieved evidence. |
| **Fail-safe by design** | Because there's no local dataset to load into memory, the architecture is immune to out-of-memory (OOM) crashes that plagued the previous local-dataset version. |
---
## π§© Tech Stack
| Layer | Technology | Purpose |
|---|---|---|
| **Vector Database** | [DataStax Astra DB](https://astra.datastax.com/) | Serverless cloud-native vector search over 1.3M+ medical text embeddings |
| **LLM Inference** | [Groq](https://groq.com/) β Llama-3.1-8b-instant | Ultra-low-latency token streaming via custom LPU hardware |
| **Asset Storage** | [HuggingFace Datasets](https://huggingface.co/) | Serverless retrieval of source documents and images |
| **Backend Framework** | FastAPI (Python) | Async API layer, request validation, streaming responses |
| **Authentication** | Supabase Auth | JWT-based session management and identity verification |
| **Frontend** | HTML/CSS/JS (glassmorphism, custom animations) | Clinical, responsive UI optimized for accessibility and SEO |
| **Deployment** | Docker (HuggingFace Spaces, Render, Railway, Vercel-compatible) | Portable, serverless-friendly container |
---
## β‘ Key Features
- **Zero Local Footprint** β The former 17GB vector database and 88GB image archive have been fully migrated off-disk to Astra DB and HuggingFace Datasets respectively. The running application requires negligible local storage.
- **Lightning-Fast Inference** β Powered by Groq's LPU architecture, responses stream token-by-token with minimal latency compared to traditional GPU-based inference.
- **Keyword-Augmented RAG Retrieval** β A custom retriever layer blends semantic vector search with keyword-based re-ranking to improve relevance on medical terminology and abbreviations.
- **Strict XML Prompt Boundaries** β All retrieved context is wrapped in explicit XML tags before being passed to the LLM, reducing prompt injection risk and improving grounding fidelity.
- **Secure Authentication** β Supabase-issued JWTs are verified server-side on every protected request, ensuring session integrity without maintaining server-side session state.
- **Accessibility & Performance** β The frontend achieves perfect 100/100 Accessibility and SEO scores on Google Lighthouse, with a responsive, glassmorphic clinical interface.
- **Platform-Agnostic Deployment** β Being fully serverless on the data side, the same Docker image can be deployed to HuggingFace Spaces, Render, Railway, Vercel, or any container-compatible host without modification.
---
## π API Overview
> Update endpoint paths/names below to match your actual FastAPI routes β placeholders shown for structure.
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| `POST` | `/api/query` | Submit a medical question; returns a streamed, RAG-grounded response | β
|
| `GET` | `/api/health` | Service health check | β |
| `POST` | `/api/auth/session` | Validate Supabase JWT and establish a session context | β
|
| `GET` | `/api/sources/{doc_id}` | Retrieve a specific source document/image reference | β
|
---
## π οΈ Installation & Setup
### Prerequisites
- Python 3.10+
- A Groq API key
- A DataStax Astra DB instance (serverless vector-enabled)
- A Supabase project (for authentication)
### 1. Clone the repository
```bash
git clone https://github.com/labstrinetra/placebo.ai.git
cd placebo.ai
```
### 2. Install dependencies
```bash
pip install -r requirements.txt
```
### 3. Configure environment variables
Create a `.env` file in the project root:
```env
GROQ_API_KEY=your_groq_api_key
ASTRA_DB_API_ENDPOINT=your_astra_endpoint
ASTRA_DB_APPLICATION_TOKEN=your_astra_token
SUPABASE_URL=your_supabase_url
SUPABASE_ANON_KEY=your_supabase_key
```
### 4. Run the application
```bash
python src/app.py
```
The application will be available at `http://localhost:8000`.
---
## π¦ Deployment
Placebo AI is live in production on **HuggingFace Spaces**, running in a custom Docker container:
π **Live URL:** [https://trinetralabs-placeboai.hf.space/](https://trinetralabs-placeboai.hf.space/)
Because all heavy data lives off-container, the exact same repository can be deployed to any of the following without disk or memory tuning:
- **Render** β Docker web service, no persistent disk required
- **Railway** β one-click Docker deploy from GitHub
- **Vercel** β via Docker-compatible serverless functions (API routes)
- **HuggingFace Spaces** β current production host (Docker SDK)
### Deployment Checklist
- [ ] All environment variables set in the host platform's secrets manager (never commit `.env`)
- [ ] `app_port` matches the platform's expected port (7860 for HF Spaces, configurable elsewhere)
- [ ] Astra DB and Supabase projects are on production-tier plans if expecting sustained traffic
- [ ] Groq API rate limits reviewed for expected concurrent load
---
## π Security Notes
- JWTs issued by Supabase are verified server-side on every authenticated request; no session state is persisted in the application.
- API keys and database tokens are read exclusively from environment variables β never hardcoded or logged.
- Retrieved context is sandboxed within explicit XML boundaries before being passed to the LLM, limiting the blast radius of prompt-injection attempts embedded in source documents.
---
## πΊοΈ Roadmap
- [ ] Multi-turn conversational memory with session-scoped context windows
- [ ] Source citation UI (inline links to retrieved documents/images)
- [ ] Admin dashboard for corpus management and query analytics
- [ ] Rate limiting and usage quotas per authenticated user
---
## π€ Contributing
Contributions, issues, and feature requests are welcome. Please open an issue first to discuss significant changes before submitting a pull request.
---
## π License
Distributed under the MIT License. See `LICENSE` for details.
---
<div align="center">
*Developed by **Trinetra Labs***
</div>
|