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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: SmartDoc AI
|
| 3 |
+
colorFrom: blue
|
| 4 |
+
colorTo: indigo
|
| 5 |
+
sdk: gradio
|
| 6 |
+
sdk_version: "4.25.0"
|
| 7 |
+
app_file: main.py
|
| 8 |
+
pinned: false
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
# SmartDoc AI
|
| 12 |
+
|
| 13 |
+
SmartDoc AI is an advanced document analysis and question answering system, designed for source-grounded Q&A over complex business and scientific reports—especially where key evidence lives in tables and charts.
|
| 14 |
+
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
## Personal Research Update
|
| 18 |
+
|
| 19 |
+
**SmartDoc AI – Document Q&A + Selective Chart Understanding**
|
| 20 |
+
|
| 21 |
+
I’ve been developing SmartDoc AI as a technical experiment to improve question answering over complex business/scientific reports—especially where key evidence lives in tables and charts.
|
| 22 |
+
|
| 23 |
+
### Technical highlights:
|
| 24 |
+
|
| 25 |
+
- **Multi-format ingestion:** PDF, DOCX, TXT, Markdown
|
| 26 |
+
- **LLM-assisted query decomposition:** breaks complex prompts into clearer sub-questions for retrieval + answering
|
| 27 |
+
- **Selective chart pipeline (cost-aware):**
|
| 28 |
+
- Local OpenCV heuristics flag pages that likely contain charts
|
| 29 |
+
- Gemini Vision is invoked only for chart pages to generate structured chart analysis (reduces unnecessary vision calls)
|
| 30 |
+
- **Table extraction + robust PDF parsing:** pdfplumber strategies for bordered and borderless tables
|
| 31 |
+
- **Parallelized processing:** concurrent PDF parsing + chart detection; batch chart analysis where enabled
|
| 32 |
+
- **Hybrid retrieval:** BM25 + vector search combined via an ensemble retriever
|
| 33 |
+
- **Multi-agent answering:** answer drafting + verification pass, with retrieved context available for inspection (page/source metadata)
|
| 34 |
+
|
| 35 |
+
**Runtime note:** Large PDFs (many pages/charts) can take minutes depending on DPI, chart volume, and available memory/CPU (HF Spaces limits can be a factor).
|
| 36 |
+
|
| 37 |
+
---
|
| 38 |
+
|
| 39 |
+
## Demo Videos
|
| 40 |
+
|
| 41 |
+
- [SmartDoc AI technical demo #1](https://youtu.be/uVU_sLiJU4w)
|
| 42 |
+
- [SmartDoc AI technical demo #2](https://youtu.be/c8CF7-OaKmQ)
|
| 43 |
+
- [SmartDoc AI technical demo #3](https://youtu.be/P17SZSQJ6Wc)
|
| 44 |
+
|
| 45 |
+
---
|
| 46 |
+
|
| 47 |
+
## Repository
|
| 48 |
+
?? https://github.com/TilanTAB/Intelligent-Document-Analysis-SmartDoc-AI
|
| 49 |
+
|
| 50 |
+
---
|
| 51 |
+
|
| 52 |
+
## Use Cases
|
| 53 |
+
|
| 54 |
+
- Source-grounded Q&A for business/research documents
|
| 55 |
+
- Automated extraction and summarization from tables/charts
|
| 56 |
+
|
| 57 |
+
If you’re interested in architecture tradeoffs (cost, latency, memory limits, retrieval quality), feel free to connect.
|
| 58 |
+
|
| 59 |
+
---
|
| 60 |
+
|
| 61 |
+
## Features
|
| 62 |
+
|
| 63 |
+
- **Multi-format Document Support**: PDF, DOCX, TXT, and Markdown
|
| 64 |
+
- **Smart Chunking**: Configurable chunk size and overlap for optimal retrieval
|
| 65 |
+
- **Intelligent Caching**: Speeds up repeated queries
|
| 66 |
+
- **Chart Extraction**: Detects and analyzes charts using OpenCV and Gemini Vision
|
| 67 |
+
- **Hybrid Search**: Combines keyword and vector search for best results
|
| 68 |
+
- **Multi-Agent Workflow**: Relevance checking, research, and answer verification
|
| 69 |
+
- **Production Ready**: Structured logging, environment-based config, and test suite
|
| 70 |
+
- **Efficient**: Local chart detection saves up to 95% on API costs
|
| 71 |
+
|
| 72 |
+
---
|
| 73 |
+
|
| 74 |
+
## Quick Start
|
| 75 |
+
|
| 76 |
+
### Prerequisites
|
| 77 |
+
- Python 3.11 or higher
|
| 78 |
+
- Google API Key for Gemini models ([Get one here](https://ai.google.dev/))
|
| 79 |
+
|
| 80 |
+
### Installation
|
| 81 |
+
|
| 82 |
+
1. Clone the repository:
|
| 83 |
+
```bash
|
| 84 |
+
git clone https://github.com/TilanTAB/Intelligent-Document-Analysis-SmartDoc-AI.git
|
| 85 |
+
cd Intelligent-Document-Analysis-SmartDoc-AI
|
| 86 |
+
```
|
| 87 |
+
|
| 88 |
+
2. Activate the virtual environment:
|
| 89 |
+
```bash
|
| 90 |
+
# Windows PowerShell
|
| 91 |
+
.\activate_venv.ps1
|
| 92 |
+
# Windows Command Prompt
|
| 93 |
+
activate_venv.bat
|
| 94 |
+
# Or manually:
|
| 95 |
+
.\venv\Scripts\Activate.ps1
|
| 96 |
+
```
|
| 97 |
+
|
| 98 |
+
3. Install dependencies (if needed):
|
| 99 |
+
```bash
|
| 100 |
+
pip install -r requirements.txt
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
4. Configure environment variables:
|
| 104 |
+
```bash
|
| 105 |
+
cp .env.template .env
|
| 106 |
+
# Edit .env and set your API key
|
| 107 |
+
GOOGLE_API_KEY=your_api_key_here
|
| 108 |
+
```
|
| 109 |
+
|
| 110 |
+
5. (Optional) Verify installation:
|
| 111 |
+
```bash
|
| 112 |
+
python verify_environment.py
|
| 113 |
+
```
|
| 114 |
+
|
| 115 |
+
6. Run the application:
|
| 116 |
+
```bash
|
| 117 |
+
python main.py
|
| 118 |
+
```
|
| 119 |
+
|
| 120 |
+
7. Open your browser to [http://localhost:7860](http://localhost:7860)
|
| 121 |
+
|
| 122 |
+
---
|
| 123 |
+
|
| 124 |
+
## Configuration
|
| 125 |
+
|
| 126 |
+
All settings can be configured via environment variables or the `.env` file. Key options include:
|
| 127 |
+
- `GOOGLE_API_KEY`: Your Gemini API key (required)
|
| 128 |
+
- `CHUNK_SIZE`, `CHUNK_OVERLAP`: Document chunking
|
| 129 |
+
- `ENABLE_CHART_EXTRACTION`: Enable/disable chart detection
|
| 130 |
+
- `CHART_USE_LOCAL_DETECTION`: Use OpenCV for free chart detection
|
| 131 |
+
- `CHART_ENABLE_BATCH_ANALYSIS`: Batch process charts for speed
|
| 132 |
+
- `CHART_GEMINI_BATCH_SIZE`: Number of charts per Gemini API call
|
| 133 |
+
- `LOG_LEVEL`: Logging verbosity
|
| 134 |
+
- `GRADIO_SERVER_PORT`: Web interface port
|
| 135 |
+
|
| 136 |
+
---
|
| 137 |
+
|
| 138 |
+
## Project Structure
|
| 139 |
+
|
| 140 |
+
- `intelligence/` - Multi-agent system (relevance, research, verification)
|
| 141 |
+
- `configuration/` - App settings and logging
|
| 142 |
+
- `content_analyzer/` - Document and chart processing
|
| 143 |
+
- `search_engine/` - Hybrid retriever logic
|
| 144 |
+
- `core/` - Utilities and diagnostics
|
| 145 |
+
- `tests/` - Test suite
|
| 146 |
+
- `main.py` - Application entry point
|
| 147 |
+
|
| 148 |
+
---
|
| 149 |
+
|
| 150 |
+
## Troubleshooting
|
| 151 |
+
|
| 152 |
+
- **API Key Not Found**: Set `GOOGLE_API_KEY` in your `.env` file.
|
| 153 |
+
- **Python 3.13 Issues**: Use Python 3.11 or 3.12 for best compatibility.
|
| 154 |
+
- **Chart Detection Slow**: Lower `CHART_DPI` or `CHART_MAX_IMAGE_SIZE` in `.env`.
|
| 155 |
+
- **ChromaDB Lock Issues**: Stop all instances and remove lock files in `vector_store/`.
|
| 156 |
+
|
| 157 |
+
---
|
| 158 |
+
|
| 159 |
+
## Contributing
|
| 160 |
+
|
| 161 |
+
Contributions are welcome! Please fork the repository, create a feature branch, and submit a pull request with a clear description.
|
| 162 |
+
|
| 163 |
+
---
|
| 164 |
+
|
| 165 |
+
## License
|
| 166 |
+
|
| 167 |
+
This project is licensed under the MIT License.
|
| 168 |
+
|
| 169 |
+
---
|
| 170 |
+
|
| 171 |
+
SmartDoc AI is actively maintained and designed for real-world document analysis and Q&A. For updates and support, visit the [GitHub repository](https://github.com/TilanTAB/Intelligent-Document-Analysis-SmartDoc-AI).
|