clearvoice-api / README.md
manan77709's picture
chore: add huggingface spaces configuration to README
321c4ec
|
Raw
History Blame Contribute Delete
8.55 kB
---
title: ClearVoice API
emoji: ๐Ÿ”ฌ
colorFrom: blue
colorTo: indigo
sdk: docker
pinned: false
---
# ๐Ÿ”ฌ ClearVoice โ€” AI-Powered Medical Misinformation Checker
<p align="center">
<b>Verify health claims using live peer-reviewed medical evidence.</b>
</p>
<p align="center">
<a href="https://clear-voice-five.vercel.app">๐ŸŒ Live Demo</a> โ€ข
<a href="https://manan77709-clearvoice-api.hf.space">โšก API</a>
</p>
---
## ๐Ÿ“– Overview
**ClearVoice** is an AI-powered medical misinformation checker that evaluates health claims against **live peer-reviewed PubMed research** using a multi-agent retrieval and reasoning pipeline.
Unlike traditional RAG systems that rely on a static vector database, ClearVoice searches **PubMed in real time**, retrieves the latest relevant studies, evaluates their quality, and generates an evidence-based verdict with transparent reasoning.
Every prediction includes:
- โœ… Final verdict
- ๐Ÿ“š Supporting research papers
- ๐Ÿงฌ Study types
- โญ Evidence quality scores
- โš–๏ธ Whether studies support or contradict the claim
- ๐Ÿ’ฌ Plain-English explanation
- ๐ŸŽฏ Practical takeaway
---
# โœจ Features
### ๐Ÿ” Live Medical Evidence Retrieval
- Searches PubMed in real time
- Uses the latest peer-reviewed studies
- No stale offline database
### ๐Ÿง  PubMedBERT Semantic Search
Medical-domain embeddings provide significantly better retrieval than generic embedding models.
- Model: **NeuML/pubmedbert-base-embeddings**
- 768-dimensional embeddings
---
### ๐Ÿค– Multi-Agent AI Pipeline
Instead of a single LLM prompt, ClearVoice uses specialized AI agents.
| Agent | Responsibility |
|---------|---------------|
| **Decomposer Agent** | Splits complex medical claims into simpler subclaims |
| **Verdict Agent** | Determines TRUE / FALSE / MISLEADING |
| **Judge Agent** | Scores evidence quality and determines stance |
| **Explainer Agent** | Produces easy-to-understand explanations |
---
### ๐Ÿ“Š Evidence Transparency
Every retrieved paper includes:
- Study Type
- Evidence Quality (1โ€“5)
- Supports / Contradicts / Neutral
- Confidence
Examples:
- Meta-analysis
- Systematic Review
- Randomized Controlled Trial
- Cohort Study
- Case-Control Study
---
### ๐Ÿงพ Plain English Explanations
Medical literature is translated into language that non-experts can understand.
Each response contains:
- Why the claim received its verdict
- What researchers found
- Practical takeaway
---
### โšก Multi-Model LLM Fallback
If one Groq model becomes unavailable or rate-limited, ClearVoice automatically switches to another model.
Fallback chain:
```
Llama-3.3-70B
โ†“
Llama-4-Scout
โ†“
GPT-OSS-120B
โ†“
Llama-3.1-8B
```
---
### ๐Ÿš€ Redis Caching
Repeated claims are cached for 24 hours.
Benefits:
- <100ms responses
- Reduced API cost
- Lower latency
---
# ๐Ÿ—๏ธ System Architecture
```
User Claim
โ”‚
โ–ผ
Redis Cache Lookup
โ”‚ โ”‚
Hit Miss
โ”‚ โ–ผ
Return Cached Decomposer Agent
Result โ”‚
โ–ผ
Live PubMed Retrieval
โ”‚
โ–ผ
PubMedBERT Embeddings
โ”‚
โ–ผ
Retrieve Top Papers
โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ–ผ โ–ผ
Verdict Agent Judge Agent
โ”‚ โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
Verdict Override Logic
(Mixed Evidence โ†’ MISLEADING)
โ”‚
โ–ผ
Explainer Agent
โ”‚
โ–ผ
Cache Response in Redis
โ”‚
โ–ผ
Return to Frontend
```
---
# ๐Ÿ“ˆ Performance
| Metric | Phase 1 | Phase 2 |
|----------|---------|----------|
| Accuracy | 60% | 90%+ |
| Embeddings | MiniLM (384d) | PubMedBERT (768d) |
| Retrieval | Pre-ingested DB | Live PubMed |
| Avg Response Time | 4.19s | ~10s |
| Cached Response | N/A | <100ms |
| MISLEADING Detection | 0% | 100% |
| Errors | 2/10 | 0/10 |
---
# ๐Ÿš€ Development Journey
## Phase 1 โ€” Baseline RAG
Implemented:
- FastAPI backend
- PubMed ingestion
- MiniLM embeddings
- Supabase pgvector
- Groq LLM
- Redis cache
- Streamlit frontend
Result:
- 60% benchmark accuracy
---
## Phase 2 โ€” Medical RAG
Major improvements:
- PubMedBERT embeddings
- Live PubMed retrieval
- Multi-agent reasoning
- Judge agent
- Decomposer
- Explainer
- Verdict override logic
- Multi-model fallback
Result:
- 90%+ benchmark accuracy
---
## Phase 3 โ€” Modern Frontend
Current version includes:
- React
- Vite
- Tailwind CSS
- Responsive UI
- Evidence cards
- Complex claim visualization
Deployment:
- Frontend โ†’ Vercel
- Backend โ†’ Hugging Face Spaces
---
## Phase 4 (Planned)
- ๐ŸŽค Whisper voice input
- ๐ŸŒ Chrome Extension
- ๐Ÿ“ฑ Mobile responsive improvements
- ๐Ÿ“Š 50+ benchmark dataset
- ๐Ÿ“ˆ User analytics dashboard
---
# ๐Ÿ›  Tech Stack
| Layer | Technology |
|---------|-------------|
| Frontend | React + Vite + Tailwind CSS |
| Backend | FastAPI |
| Deployment | Hugging Face Spaces + Vercel |
| Embeddings | PubMedBERT |
| Vector Database | Supabase pgvector |
| Retrieval | PubMed + Biopython Entrez |
| LLM | Groq API |
| Cache | Upstash Redis |
| Language | Python |
---
# ๐Ÿ“‚ Project Structure
```
ClearVoice
โ”‚
โ”œโ”€โ”€ backend
โ”‚ โ”œโ”€โ”€ main.py
โ”‚ โ”‚
โ”‚ โ””โ”€โ”€ app
โ”‚ โ”œโ”€โ”€ retrieval.py
โ”‚ โ”œโ”€โ”€ verify.py
โ”‚ โ”œโ”€โ”€ groq_client.py
โ”‚ โ”‚
โ”‚ โ””โ”€โ”€ agents
โ”‚ โ”œโ”€โ”€ decomposer.py
โ”‚ โ”œโ”€โ”€ judge.py
โ”‚ โ””โ”€โ”€ explainer.py
โ”‚
โ”œโ”€โ”€ frontend-react
โ”‚
โ”œโ”€โ”€ frontend
โ”‚
โ”œโ”€โ”€ benchmark.py
โ”‚
โ”œโ”€โ”€ accuracy.py
โ”‚
โ””โ”€โ”€ BENCHMARKS.md
```
---
# โš™๏ธ Installation
## Clone Repository
```bash
git clone https://github.com/MananBabbar07/ClearVoice.git
cd ClearVoice
```
---
## Create Virtual Environment
```bash
python -m venv venv
```
Windows
```bash
venv\Scripts\activate
```
Linux / macOS
```bash
source venv/bin/activate
```
---
## Install Dependencies
```bash
pip install -r requirements.txt
```
---
## Configure Environment Variables
Create a `.env` file.
```env
GROQ_API_KEY=your_key
DATABASE_URL=your_supabase_url
REDIS_URL=your_upstash_url
NCBI_EMAIL=your_email
```
---
## Run Backend
```bash
uvicorn backend.main:app --reload
```
---
## Run Frontend
```bash
cd frontend-react
npm install
npm run dev
```
---
# ๐Ÿงช Example Claim
Input:
> **"Vitamin C prevents the common cold."**
Output:
```
Verdict:
MISLEADING
Reason:
Vitamin C does not prevent colds in the general population,
although it may slightly reduce duration in certain individuals.
Evidence:
โœ“ Meta-analysis (Quality 5/5)
โœ“ Randomized Controlled Trial (4/5)
โœ— One contradictory cohort study
Overall Confidence:
High
```
```
screenshots/
โ”œโ”€โ”€ homepage.png
โ”œโ”€โ”€ result.png
โ”œโ”€โ”€ evidence_cards.png
โ””โ”€โ”€ decomposition.png
```
---
# ๐Ÿ”ฎ Future Work
- Voice-based medical verification
- Browser extension
- Larger benchmark dataset
- Medical citation export
- PDF report generation
- User authentication
- Saved history
- API rate limiting
---
# ๐Ÿ‘จโ€๐Ÿ’ป Author
**Manan Babbar**
GitHub:
https://github.com/MananBabbar07
---
# โญ If you found this project useful...
Please consider giving the repository a **Star โญ**.