--- title: CureMind emoji: ๐Ÿฉบ colorFrom: blue colorTo: indigo sdk: docker pinned: false --- # CureMind โ€” AI Medical Information Assistant An end-to-end **Retrieval-Augmented Generation (RAG)** medical chatbot built as part of a German MSc AI portfolio. It combines curated open biomedical datasets with user-uploaded documents to answer clinical questions with source citations. --- ## Architecture ``` User Question โ”‚ โ–ผ Streamlit UI โ”€โ”€โ–บ FastAPI Backend โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ–ผ โ–ผ Google GenAI Pinecone Vector DB Embeddings (768d) โ—„โ”€โ”€ (medicalindex) โ”‚ โ–ผ Top-5 Relevant Chunks โ”‚ โ–ผ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ LLM Router โ”‚ โ”‚ โ”œโ”€ Qwen-3.8-27B โ”‚ (fast queries) โ”‚ โ”œโ”€ GPT-OSS-120B โ”‚ (reasoning / "why/how") โ”‚ โ””โ”€ Groq-Compound โ”‚ (fallback) โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ (via Groq API) โ–ผ Answer + Source Citations ``` --- ## Tech Stack | Layer | Technology | |---|---| | Frontend | Streamlit | | Backend | FastAPI + Uvicorn | | Vector Store | Pinecone (768-dim, dotproduct) | | Embeddings | Google Generative AI (`embedding-001`) | | LLM Inference | Groq API (Qwen-3.8-27B ยท GPT-OSS-120B ยท Groq-Compound) | | RAG Framework | LangChain LCEL | | Datasets | HuggingFace Hub | | Config | Pydantic Settings | | Deployment | HuggingFace Spaces (Docker) | --- ## Knowledge Base โ€” Open Datasets | Dataset | Source | Size | License | |---|---|---|---| | PubMedQA | `qiaojin/PubMedQA` | 1 k (labeled) | MIT | | Mental Health Counseling | `Amod/mental_health_counseling_conversations` | 3.5 k | RAIL-D | | Medical Meadow MediQA | `medalpaca/medical_meadow_mediqa` | 2.2 k | Academic | | MedQA-USMLE | `GBaker/MedQA-USMLE-4-options-hf` | 12.7 k | CC-BY-SA-4.0 | Users can also upload their own PDF documents via the sidebar to extend the knowledge base. --- ## API Endpoints | Method | Path | Description | |---|---|---| | `GET` | `/health` | Service health check | | `POST` | `/ask/` | Submit a question, returns answer + sources | | `POST` | `/upload_pdfs/` | Upload PDF documents for indexing | | `GET` | `/hf_datasets/` | List available HuggingFace datasets | | `POST` | `/hf_datasets/load/` | Load a dataset into the vector store | Interactive docs available at `/docs` when running. --- ## Local Development ### 1. Clone and install ```bash git clone https://github.com/YOUR_USERNAME/curemind.git cd curemind ``` ### 2. Configure environment ```bash cp server/.env.example server/.env # Fill in your API keys in server/.env ``` Required keys: - `GOOGLE_API_KEY` โ€” [console.cloud.google.com](https://console.cloud.google.com) - `GROQ_API_KEY` โ€” [console.groq.com](https://console.groq.com) - `PINECONE_API_KEY` โ€” [app.pinecone.io](https://app.pinecone.io) - `HUGGINGFACE_HUB_TOKEN` โ€” [huggingface.co/settings/tokens](https://huggingface.co/settings/tokens) ### 3. Run backend ```bash cd server pip install -r requirements.txt uvicorn main:app --reload ``` ### 4. Run frontend ```bash cd client pip install -r requirements.txt streamlit run app.py ``` --- ## HuggingFace Spaces Deployment ### Environment Variables (set in Space Settings โ†’ Variables and Secrets) | Key | Type | |---|---| | `GOOGLE_API_KEY` | Secret | | `GROQ_API_KEY` | Secret | | `PINECONE_API_KEY` | Secret | | `HUGGINGFACE_HUB_TOKEN` | Secret | | `PINECONE_INDEX_NAME` | Variable โ€” `medicalindex` | | `PINECONE_REGION` | Variable โ€” `us-east-1` | The Docker container starts both FastAPI (port 8000, internal) and Streamlit (port 7860, public) automatically. --- ## Project Structure ``` curemind/ โ”œโ”€โ”€ Dockerfile # HF Spaces Docker build โ”œโ”€โ”€ docker-entrypoint.sh # Starts both services โ”œโ”€โ”€ render.yaml # Render.com alternative deployment โ”‚ โ”œโ”€โ”€ server/ # FastAPI backend โ”‚ โ”œโ”€โ”€ core/ โ”‚ โ”‚ โ”œโ”€โ”€ settings.py # Pydantic BaseSettings โ”‚ โ”‚ โ””โ”€โ”€ schemas.py # Request / response models โ”‚ โ”œโ”€โ”€ modules/ โ”‚ โ”‚ โ”œโ”€โ”€ llm.py # LangChain LCEL chain + model router โ”‚ โ”‚ โ”œโ”€โ”€ load_vectorstore.py # PDF ingestion pipeline โ”‚ โ”‚ โ””โ”€โ”€ hf_dataset_loader.py# HuggingFace dataset ingestion โ”‚ โ”œโ”€โ”€ routes/ โ”‚ โ”‚ โ”œโ”€โ”€ ask_question.py # POST /ask/ โ”‚ โ”‚ โ”œโ”€โ”€ upload_pdfs.py # POST /upload_pdfs/ โ”‚ โ”‚ โ””โ”€โ”€ load_hf_datasets.py # GET|POST /hf_datasets/ โ”‚ โ””โ”€โ”€ main.py โ”‚ โ””โ”€โ”€ client/ # Streamlit frontend โ”œโ”€โ”€ app.py # Entry point โ”œโ”€โ”€ components/ โ”‚ โ”œโ”€โ”€ chatUI.py โ”‚ โ”œโ”€โ”€ upload.py โ”‚ โ”œโ”€โ”€ hf_loader.py โ”‚ โ””โ”€โ”€ history_download.py โ””โ”€โ”€ utils/ โ””โ”€โ”€ api.py ```