Spaces:
Runtime error
Runtime error
Upload folder using huggingface_hub
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .env.example +3 -7
- .gitattributes +5 -0
- .gitignore +6 -0
- Dockerfile +4 -0
- README.md +219 -98
- api/constants/__init__.py +2 -8
- api/main.py +38 -55
- api/middlewares/Authenticate_middleware.py +26 -0
- api/middlewares/__init__.py +0 -0
- api/routes/__init__.py +0 -0
- api/routes/chat_router.py +59 -0
- api/routes/frontend_router.py +87 -0
- api/routes/ingest_docs_router.py +76 -0
- api/routes/load_conversation_router.py +20 -0
- api/routes/upload_router.py +41 -0
- api/routes/user_router.py +59 -0
- api/states/__init__.py +0 -0
- api/states/chat_state.py +4 -0
- api/states/upload_state.py +6 -0
- api/states/user_state.py +5 -0
- api/static/__init__.py +0 -0
- api/static/css/__init__.py +0 -0
- api/static/js/__init__.py +0 -0
- api/static/js/main.js +28 -0
- api/templates/__init__.py +0 -0
- api/templates/base.html +160 -0
- api/templates/chat.html +584 -0
- api/templates/home.html +150 -0
- api/templates/upload.html +570 -0
- data/Optical_Recognition.png +0 -0
- data/google.docx +3 -0
- data/growing_ai_tools.txt +1 -0
- exception/__init__.py +1 -4
- graph_visualization.png +0 -0
- logger/__init__.py +1 -1
- main.py +3 -20
- notebook/convert_to_pdf.ipynb +0 -0
- pyproject.toml +10 -1
- references/Screenshot from 2026-05-19 09-16-20.png +3 -0
- references/Screenshot from 2026-05-19 09-22-23.png +3 -0
- references/Screenshot from 2026-05-21 12-05-26.png +3 -0
- references/Screenshot from 2026-05-21 12-26-14.png +0 -0
- references/Screenshot from 2026-05-29 16-20-02.png +3 -0
- src/__init__.py +0 -0
- src/components/__init__.py +0 -0
- src/components/data_ingestion.py +47 -0
- src/components/data_transformation.py +35 -0
- src/components/run_graph.py +16 -0
- src/constants/__init__.py +18 -0
- src/entity/artifact_entity.py +23 -0
.env.example
CHANGED
|
@@ -1,15 +1,11 @@
|
|
| 1 |
-
GROQ_API_KEY=
|
| 2 |
AWS_ACCESS_KEY_ID=
|
| 3 |
-
AWS_SECRET_ACCESS_KEY=
|
| 4 |
AWS_DEFAULT_REGION=
|
|
|
|
|
|
|
| 5 |
HUGGINGFACEHUB_ACCESS_TOKEN=
|
| 6 |
-
PORT=
|
| 7 |
-
|
| 8 |
-
|
| 9 |
|
| 10 |
|
| 11 |
TAVILY_API_KEY=
|
| 12 |
-
Gemini_API_Key=
|
| 13 |
HF_TOKEN=
|
| 14 |
|
| 15 |
-
APP_API_KEY=
|
|
|
|
|
|
|
| 1 |
AWS_ACCESS_KEY_ID=
|
|
|
|
| 2 |
AWS_DEFAULT_REGION=
|
| 3 |
+
AWS_SECRET_ACCESS_KEY=
|
| 4 |
+
GROQ_API_KEY=
|
| 5 |
HUGGINGFACEHUB_ACCESS_TOKEN=
|
| 6 |
+
PORT=8000
|
|
|
|
|
|
|
| 7 |
|
| 8 |
|
| 9 |
TAVILY_API_KEY=
|
|
|
|
| 10 |
HF_TOKEN=
|
| 11 |
|
|
|
.gitattributes
CHANGED
|
@@ -46,3 +46,8 @@ images/ml_model_example.png filter=lfs diff=lfs merge=lfs -text
|
|
| 46 |
images/ml_workflow_diagram.png filter=lfs diff=lfs merge=lfs -text
|
| 47 |
images/transformer_application.png filter=lfs diff=lfs merge=lfs -text
|
| 48 |
images/transformer_architecture.png filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
images/ml_workflow_diagram.png filter=lfs diff=lfs merge=lfs -text
|
| 47 |
images/transformer_application.png filter=lfs diff=lfs merge=lfs -text
|
| 48 |
images/transformer_architecture.png filter=lfs diff=lfs merge=lfs -text
|
| 49 |
+
data/google.docx filter=lfs diff=lfs merge=lfs -text
|
| 50 |
+
references/Screenshot[[:space:]]from[[:space:]]2026-05-19[[:space:]]09-16-20.png filter=lfs diff=lfs merge=lfs -text
|
| 51 |
+
references/Screenshot[[:space:]]from[[:space:]]2026-05-19[[:space:]]09-22-23.png filter=lfs diff=lfs merge=lfs -text
|
| 52 |
+
references/Screenshot[[:space:]]from[[:space:]]2026-05-21[[:space:]]12-05-26.png filter=lfs diff=lfs merge=lfs -text
|
| 53 |
+
references/Screenshot[[:space:]]from[[:space:]]2026-05-29[[:space:]]16-20-02.png filter=lfs diff=lfs merge=lfs -text
|
.gitignore
CHANGED
|
@@ -213,4 +213,10 @@ api/public/
|
|
| 213 |
|
| 214 |
scratch/
|
| 215 |
docs/
|
|
|
|
| 216 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 213 |
|
| 214 |
scratch/
|
| 215 |
docs/
|
| 216 |
+
artifacts/
|
| 217 |
|
| 218 |
+
data/
|
| 219 |
+
|
| 220 |
+
api/public/
|
| 221 |
+
|
| 222 |
+
logs/
|
Dockerfile
CHANGED
|
@@ -1,4 +1,8 @@
|
|
| 1 |
FROM python:3.12-slim
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
WORKDIR /app
|
| 4 |
|
|
|
|
| 1 |
FROM python:3.12-slim
|
| 2 |
+
sudo apt-get update && sudo apt-get │ │
|
| 3 |
+
│ │ install -y tesseract-ocr │ │
|
| 4 |
+
│ │ libtesseract-dev poppler-utils │ │
|
| 5 |
+
│ │ libmagic-dev
|
| 6 |
|
| 7 |
WORKDIR /app
|
| 8 |
|
README.md
CHANGED
|
@@ -9,150 +9,271 @@ pinned: false
|
|
| 9 |
short_description: This is the Multi-Rag Agent
|
| 10 |
---
|
| 11 |
|
|
|
|
| 12 |
|
| 13 |
-
<
|
| 14 |
-
<
|
| 15 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
|
| 18 |
-
[](https://github.com/langchain-ai/langgraph)
|
| 19 |
-
[](https://fastapi.tiangolo.com/)
|
| 20 |
-
[](https://github.com/facebookresearch/faiss)
|
| 21 |
-
</div>
|
| 22 |
|
| 23 |
---
|
| 24 |
|
| 25 |
-
##
|
| 26 |
|
| 27 |
-
|
| 28 |
|
| 29 |
-
|
| 30 |
-
- **Intelligent Fan-out**: The orchestrator can trigger multiple workers in parallel to gather information from different sources.
|
| 31 |
-
- **Dynamic Routing**: Automatically detects file types and routes tasks to specialized loaders.
|
| 32 |
-
- **OCR Integration**: Built-in support for image processing and optical character recognition.
|
| 33 |
-
- **Web Search Fallback**: If local documents are insufficient, the agents can autonomously search the live web.
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
-
|
| 42 |
-
The main graph handles the interaction between the user, the orchestrator, and the final chat response.
|
| 43 |
-
|
| 44 |
-

|
| 45 |
|
| 46 |
-
##
|
| 47 |
-
The worker sub-graph is responsible for specialized information retrieval from various file formats.
|
| 48 |
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
---
|
| 52 |
|
| 53 |
-
##
|
| 54 |
-
|
| 55 |
-
- **📂 Multi-Format Support**:
|
| 56 |
-
- **PDF**: Deep document parsing.
|
| 57 |
-
- **DOCX**: Microsoft Word document integration.
|
| 58 |
-
- **TXT**: Plain text analysis.
|
| 59 |
-
- **Images (OCR)**: Extraction of text from PNG/JPG using specialized loaders.
|
| 60 |
-
- **🤖 Autonomous Orchestration**: Uses a Llama-3.3-70B model on **AWS Bedrock** with a manual JSON fallback mechanism for 100% reliable structured output.
|
| 61 |
-
- **🔍 Advanced Retrieval Pipeline**:
|
| 62 |
-
- **Hybrid Search**: Combines semantic vector search with keyword-based BM25 for maximum precision.
|
| 63 |
-
- **RRF (Reciprocal Rank Fusion)**: Merges multiple retrieval streams with mathematical rigor.
|
| 64 |
-
- **Reranking**: Uses `Flashrank` to re-score and filter the most relevant context before generation.
|
| 65 |
-
- **Multi-Query Expansion**: Generates multiple perspectives of a user query to capture hidden context.
|
| 66 |
-
- **🧠 Persistence & Memory**: Full multi-turn conversation support with LangGraph checkpointers.
|
| 67 |
-
- **⚡ Modern Tech Stack**: Built with `uv` for lightning-fast dependency management and `FastAPI` for a high-performance backend.
|
| 68 |
-
|
| 69 |
-
---
|
| 70 |
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
-
|
| 74 |
|
| 75 |
-
|
| 76 |
-
| :--- | :--- | :--- |
|
| 77 |
-
| **Hybrid Search** | Dual-path retrieval using **FAISS (Dense)** and **BM25 (Sparse)**. | Captures both deep semantic meaning and exact keyword matches. |
|
| 78 |
-
| **Multi-Query** | The Orchestrator decomposes complex queries into multiple specialized sub-tasks. | Ensures no part of a complex request is overlooked. |
|
| 79 |
-
| **RRF** | **Reciprocal Rank Fusion** algorithm to merge results from different retrievers. | Provides a unified, unbiased ranking of candidates. |
|
| 80 |
-
| **Reranker** | **Flashrank-based cross-encoding** to re-evaluate the top-K results. | Drastically reduces "hallucinations" by filtering out low-relevance noise. |
|
| 81 |
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
---
|
| 85 |
|
| 86 |
-
##
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
|
| 96 |
---
|
| 97 |
|
| 98 |
## 🚀 Getting Started
|
| 99 |
|
| 100 |
### Prerequisites
|
| 101 |
-
- Python 3.12+
|
| 102 |
-
- `uv` installed (`pip install uv`)
|
| 103 |
-
- AWS Credentials (for Bedrock access)
|
| 104 |
|
| 105 |
-
### 1. Installation
|
| 106 |
```bash
|
| 107 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
git clone https://github.com/VashuTheGreat/Multi-Rag.git
|
| 109 |
cd Multi-Rag
|
| 110 |
|
| 111 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
uv sync
|
| 113 |
```
|
| 114 |
|
| 115 |
-
###
|
| 116 |
-
|
| 117 |
-
```env
|
| 118 |
-
# AWS Bedrock Config
|
| 119 |
-
AWS_ACCESS_KEY_ID=your_access_key
|
| 120 |
-
AWS_SECRET_ACCESS_KEY=your_secret_key
|
| 121 |
-
AWS_REGION_NAME=us-east-1
|
| 122 |
|
| 123 |
-
|
| 124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
```
|
| 126 |
|
| 127 |
-
###
|
|
|
|
| 128 |
```bash
|
| 129 |
-
|
| 130 |
-
uv run main.py
|
| 131 |
```
|
| 132 |
-
|
|
|
|
| 133 |
|
| 134 |
---
|
| 135 |
|
| 136 |
-
##
|
| 137 |
|
| 138 |
```bash
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
├── src/
|
| 142 |
-
│ └── MultiRag/
|
| 143 |
-
│ ├── components/ # Core graph runners & embedders
|
| 144 |
-
│ ├── graph/ # LangGraph definitions (Main & Worker)
|
| 145 |
-
│ ├── models/ # Pydantic state & output schemas
|
| 146 |
-
│ ├── nodes/ # Individual graph node implementations
|
| 147 |
-
│ ├── prompts/ # LLM system prompts
|
| 148 |
-
│ └── utils/ # Ingestion & document processing utilities
|
| 149 |
-
├── static/ # Frontend assets (CSS, JS)
|
| 150 |
-
├── templates/ # Jinja2 HTML templates
|
| 151 |
-
└── db/ # Local FAISS index persistence
|
| 152 |
```
|
| 153 |
|
| 154 |
---
|
| 155 |
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
short_description: This is the Multi-Rag Agent
|
| 10 |
---
|
| 11 |
|
| 12 |
+
# 🧠 Multi-RAG — Advanced Multi-Modal Retrieval Augmented Generation
|
| 13 |
|
| 14 |
+
<p align="center">
|
| 15 |
+
<img src="https://img.shields.io/badge/Python-3.12-blue?style=for-the-badge&logo=python" />
|
| 16 |
+
<img src="https://img.shields.io/badge/FastAPI-0.135-green?style=for-the-badge&logo=fastapi" />
|
| 17 |
+
<img src="https://img.shields.io/badge/LangGraph-1.0-orange?style=for-the-badge" />
|
| 18 |
+
<img src="https://img.shields.io/badge/LangChain-1.2-yellow?style=for-the-badge" />
|
| 19 |
+
<img src="https://img.shields.io/badge/FAISS-CPU-red?style=for-the-badge" />
|
| 20 |
+
<img src="https://img.shields.io/badge/Groq-LLM-purple?style=for-the-badge" />
|
| 21 |
+
<img src="https://img.shields.io/badge/Docker-Ready-blue?style=for-the-badge&logo=docker" />
|
| 22 |
+
</p>
|
| 23 |
|
| 24 |
+
A production-grade, **session-aware multi-modal RAG system** built with LangGraph, FastAPI, and a hybrid retrieval pipeline. Upload PDFs, DOCX, TXT, or images — get intelligent, context-grounded answers powered by an adaptive agentic graph that decides when to search your documents, when to fall back to the web, and when to just chat.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
---
|
| 27 |
|
| 28 |
+
## 📸 Agent Graph
|
| 29 |
|
| 30 |
+
The LangGraph pipeline is fully visualized below — each node represents a stage in the decision-making workflow:
|
| 31 |
|
| 32 |
+

|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
+
| Node | Role |
|
| 35 |
+
|---|---|
|
| 36 |
+
| `orchastrator` | Routes query: DB search needed or direct chat? |
|
| 37 |
+
| `query_generation` | Generates semantically rich retrieval queries |
|
| 38 |
+
| `retreiver` | Hybrid FAISS + BM25 + FlashRank reranking |
|
| 39 |
+
| `relevance_checker` | Evaluates if retrieved docs are CORRECT / AMBIGUOUS / INCORRECT |
|
| 40 |
+
| `document_refiner` | Passes verified docs to context builder |
|
| 41 |
+
| `web_search` | Tavily-powered fallback when docs are insufficient |
|
| 42 |
+
| `context_builder` | Assembles multimodal context (text + tables + images) |
|
| 43 |
+
| `chat` | Generates final Markdown response |
|
| 44 |
|
| 45 |
+
---
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
+
## ✨ Features
|
|
|
|
| 48 |
|
| 49 |
+
- 🗂 **Multi-Format Ingestion** — PDF, DOCX, TXT, PNG/JPG/HEIF; all converted to a unified PDF pipeline
|
| 50 |
+
- 🔍 **Hybrid Retrieval** — FAISS (dense) + BM25 (sparse) via `EnsembleRetriever`, re-ranked with FlashRank
|
| 51 |
+
- 🧩 **Multimodal Chunks** — Extracts text, tables (HTML), and base64-encoded images from documents
|
| 52 |
+
- 🤖 **Agentic LangGraph Workflow** — Adaptive routing with conditional edges; not just a static RAG chain
|
| 53 |
+
- 🌐 **Web Search Fallback** — Tavily search kicks in when retrieved docs are insufficient
|
| 54 |
+
- 💾 **Session Persistence** — Per-user thread IDs with `InMemorySaver` checkpointing; conversation history preserved
|
| 55 |
+
- 🔐 **Auth Middleware** — Lightweight session-based authentication on every request
|
| 56 |
+
- 🖥 **Full Web UI** — Jinja2-rendered frontend with upload flow, chat interface, and document explorer
|
| 57 |
+
- 🐳 **Docker Ready** — Single `Dockerfile` for deployment; also supports Jenkins CI
|
| 58 |
+
- 📝 **Rotating Logs** — Timestamped rotating log files under `logs/`
|
| 59 |
|
| 60 |
---
|
| 61 |
|
| 62 |
+
## 🏗 Architecture
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
+
```
|
| 65 |
+
Multi-Rag/
|
| 66 |
+
├── main.py # Entrypoint — loads .env, starts FastAPI
|
| 67 |
+
├── api/
|
| 68 |
+
│ ├── main.py # FastAPI app, middleware, router registration
|
| 69 |
+
│ ├── routes/
|
| 70 |
+
│ │ ├── upload_router.py # File upload handling
|
| 71 |
+
│ │ ├── ingest_docs_router.py # Triggers vectorization pipeline
|
| 72 |
+
│ │ ├── chat_router.py # Chat endpoint → LangGraph invocation
|
| 73 |
+
│ │ ├── user_router.py # Session/thread management
|
| 74 |
+
│ │ ├── load_conversation_router.py # Restore chat history
|
| 75 |
+
│ │ └── frontend_router.py # Serves HTML pages
|
| 76 |
+
│ ├── middlewares/
|
| 77 |
+
│ │ └── Authenticate_middleware.py
|
| 78 |
+
│ ├── templates/ # Jinja2 HTML templates
|
| 79 |
+
│ └── static/ # CSS / JS assets
|
| 80 |
+
│
|
| 81 |
+
├── src/
|
| 82 |
+
│ ├── graphs/
|
| 83 |
+
│ │ └── builder.py # LangGraph StateGraph definition
|
| 84 |
+
│ ├── nodes/
|
| 85 |
+
│ │ └── main_nodes.py # All 8 node implementations
|
| 86 |
+
│ ├── states/
|
| 87 |
+
│ │ └── Main_State.py # LangGraph State + Pydantic output schemas
|
| 88 |
+
│ ├── pipeline/
|
| 89 |
+
│ │ ├── Vectiorizer_pipeline.py # Ingestion + Transformation orchestration
|
| 90 |
+
│ │ └── GraphRunner_pipeline.py # Graph execution wrapper
|
| 91 |
+
│ ├── components/
|
| 92 |
+
│ │ ├── data_ingestion.py # File-to-PDF conversion dispatch
|
| 93 |
+
│ │ ├── data_transformation.py # PDF → chunks → FAISS vector store
|
| 94 |
+
│ │ └── run_graph.py # graph.ainvoke() wrapper
|
| 95 |
+
│ ├── retrievers/
|
| 96 |
+
│ │ └── create_retreivers.py # Hybrid retriever + FlashRank compression
|
| 97 |
+
│ ├── prompts/
|
| 98 |
+
│ │ └── prompt_templates.py # All LLM prompt templates
|
| 99 |
+
│ ├── entity/
|
| 100 |
+
│ │ ├── config_entity.py # Dataclass configs
|
| 101 |
+
│ │ └── artifact_entity.py # Dataclass artifacts
|
| 102 |
+
│ ├── llm/
|
| 103 |
+
│ │ └── llm_loader.py # Groq ChatGroq instantiation
|
| 104 |
+
│ ├── memory/
|
| 105 |
+
│ │ └── __init__.py # InMemorySaver checkpointer
|
| 106 |
+
│ ├── tools/
|
| 107 |
+
│ │ └── __init__.py # Tavily web search StructuredTool
|
| 108 |
+
│ ├── constants/
|
| 109 |
+
│ │ └── __init__.py # Global constants
|
| 110 |
+
│ └── utils/
|
| 111 |
+
│ ├── ingestion_utils.py # image_to_pdf, text_to_pdf, docs_to_pdf
|
| 112 |
+
│ └── asyncHandler.py # Async decorator for uniform error handling
|
| 113 |
+
│
|
| 114 |
+
├── exception/
|
| 115 |
+
│ └── __init__.py # MyException with structured logging
|
| 116 |
+
├── logger/
|
| 117 |
+
│ └── __init__.py # RotatingFileHandler setup
|
| 118 |
+
├── Dockerfile
|
| 119 |
+
├── jenkins
|
| 120 |
+
└── pyproject.toml
|
| 121 |
+
```
|
| 122 |
|
| 123 |
+
---
|
| 124 |
|
| 125 |
+
## 🔄 RAG Pipeline Flow
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
|
| 127 |
+
```
|
| 128 |
+
User Uploads Files
|
| 129 |
+
│
|
| 130 |
+
▼
|
| 131 |
+
┌─────────────────────────────────────────────────┐
|
| 132 |
+
│ Vectorization Pipeline │
|
| 133 |
+
│ │
|
| 134 |
+
│ File → docs_to_pdf → partition_pdf (hi_res) │
|
| 135 |
+
│ → chunk_by_title → FAISS + Embeddings │
|
| 136 |
+
│ → saved per thread_id │
|
| 137 |
+
└─────────────────────────────────────────────────┘
|
| 138 |
+
│
|
| 139 |
+
▼
|
| 140 |
+
User Sends Chat Message
|
| 141 |
+
│
|
| 142 |
+
▼
|
| 143 |
+
┌─────────────────────────────────────────────────┐
|
| 144 |
+
│ LangGraph Agent │
|
| 145 |
+
│ │
|
| 146 |
+
│ Orchestrator ──→ Query Generation │
|
| 147 |
+
│ │ │
|
| 148 |
+
│ Retriever (Hybrid) │
|
| 149 |
+
│ │ │
|
| 150 |
+
│ Relevance Checker │
|
| 151 |
+
│ ┌─────────┴────────┐ │
|
| 152 |
+
│ CORRECT/ INCORRECT │
|
| 153 |
+
│ AMBIGUOUS │ │
|
| 154 |
+
│ │ Web Search │
|
| 155 |
+
│ Document │ │
|
| 156 |
+
│ Refiner │ │
|
| 157 |
+
│ └────────┬─────────┘ │
|
| 158 |
+
│ Context Builder │
|
| 159 |
+
│ │ │
|
| 160 |
+
│ Chat │
|
| 161 |
+
└─────────────────────────────────────────────────┘
|
| 162 |
+
```
|
| 163 |
|
| 164 |
---
|
| 165 |
|
| 166 |
+
## ⚙️ Tech Stack
|
| 167 |
+
|
| 168 |
+
| Layer | Technology |
|
| 169 |
+
|---|---|
|
| 170 |
+
| **LLM** | Groq (`llama-3.x` / configurable) |
|
| 171 |
+
| **Embeddings** | `sentence-transformers/all-MiniLM-L6-v2` via HuggingFace |
|
| 172 |
+
| **Vector Store** | FAISS (CPU) |
|
| 173 |
+
| **Sparse Retrieval** | BM25 (`rank-bm25`) |
|
| 174 |
+
| **Reranking** | FlashRank |
|
| 175 |
+
| **Web Search** | Tavily (`langchain-tavily`) |
|
| 176 |
+
| **Agent Framework** | LangGraph 1.x (`StateGraph`) |
|
| 177 |
+
| **Orchestration** | LangChain 1.x |
|
| 178 |
+
| **Document Parsing** | `unstructured[all-docs]` + `pdfminer-six` + `pdf2image` |
|
| 179 |
+
| **OCR** | EasyOCR + Tesseract |
|
| 180 |
+
| **API** | FastAPI + Uvicorn |
|
| 181 |
+
| **Frontend** | Jinja2 + Vanilla JS |
|
| 182 |
+
| **Memory** | LangGraph `InMemorySaver` |
|
| 183 |
+
| **Packaging** | `uv` + `pyproject.toml` |
|
| 184 |
|
| 185 |
---
|
| 186 |
|
| 187 |
## 🚀 Getting Started
|
| 188 |
|
| 189 |
### Prerequisites
|
|
|
|
|
|
|
|
|
|
| 190 |
|
|
|
|
| 191 |
```bash
|
| 192 |
+
# System dependencies (Ubuntu/Debian)
|
| 193 |
+
sudo apt-get install -y \
|
| 194 |
+
tesseract-ocr \
|
| 195 |
+
libtesseract-dev \
|
| 196 |
+
poppler-utils \
|
| 197 |
+
libmagic-dev
|
| 198 |
+
```
|
| 199 |
+
|
| 200 |
+
### Installation
|
| 201 |
+
|
| 202 |
+
```bash
|
| 203 |
+
# Clone the repo
|
| 204 |
git clone https://github.com/VashuTheGreat/Multi-Rag.git
|
| 205 |
cd Multi-Rag
|
| 206 |
|
| 207 |
+
# Create virtual environment with uv
|
| 208 |
+
pip install uv
|
| 209 |
+
uv venv
|
| 210 |
+
source .venv/bin/activate
|
| 211 |
+
|
| 212 |
+
# Install all dependencies
|
| 213 |
uv sync
|
| 214 |
```
|
| 215 |
|
| 216 |
+
### Environment Variables
|
| 217 |
+
|
| 218 |
+
Copy `.env.example` to `.env` and fill in your keys:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 219 |
|
| 220 |
+
```bash
|
| 221 |
+
cp .env.example .env
|
| 222 |
+
```
|
| 223 |
+
|
| 224 |
+
```env
|
| 225 |
+
GROQ_API_KEY=your_groq_api_key
|
| 226 |
+
TAVILY_API_KEY=your_tavily_api_key
|
| 227 |
```
|
| 228 |
|
| 229 |
+
### Run
|
| 230 |
+
|
| 231 |
```bash
|
| 232 |
+
uvicorn main:app --host 0.0.0.0 --port 8000 --reload
|
|
|
|
| 233 |
```
|
| 234 |
+
|
| 235 |
+
Navigate to `http://localhost:8000`
|
| 236 |
|
| 237 |
---
|
| 238 |
|
| 239 |
+
## 🐳 Docker
|
| 240 |
|
| 241 |
```bash
|
| 242 |
+
docker build -t multi-rag .
|
| 243 |
+
docker run -p 7860:7860 --env-file .env multi-rag
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 244 |
```
|
| 245 |
|
| 246 |
---
|
| 247 |
|
| 248 |
+
## 📁 Supported File Types
|
| 249 |
+
|
| 250 |
+
| Format | Conversion Path |
|
| 251 |
+
|---|---|
|
| 252 |
+
| `.pdf` | Used directly by `unstructured` |
|
| 253 |
+
| `.docx` | `python-docx` → `fpdf2` → PDF |
|
| 254 |
+
| `.txt` | `fpdf2` → PDF |
|
| 255 |
+
| `.png / .jpg / .heif` | `Pillow` → PDF |
|
| 256 |
+
|
| 257 |
+
---
|
| 258 |
+
|
| 259 |
+
## 🧩 Key Design Decisions
|
| 260 |
+
|
| 261 |
+
- **Adaptive Routing** — The orchestrator decides per-query whether vector search is needed, avoiding unnecessary DB calls for greetings/small talk.
|
| 262 |
+
- **Hybrid Retrieval** — FAISS (70%) + BM25 (30%) ensemble captures both semantic and keyword relevance; FlashRank re-ranks the top results.
|
| 263 |
+
- **Relevance Gating** — A dedicated LLM call classifies retrieved docs as `CORRECT`, `AMBIGUOUS`, or `INCORRECT` before deciding whether to use them or fall back to web search.
|
| 264 |
+
- **Per-Thread Isolation** — Each user session gets its own `thread_id`; vector stores and artifacts are namespaced by thread to prevent cross-user data leakage.
|
| 265 |
+
- **Multimodal Context** — The `context_builder` node assembles text, HTML tables, and base64 images extracted from document chunks into a rich multimodal prompt.
|
| 266 |
+
|
| 267 |
+
---
|
| 268 |
+
|
| 269 |
+
## 📜 License
|
| 270 |
+
|
| 271 |
+
[MIT](LICENSE)
|
| 272 |
+
|
| 273 |
+
---
|
| 274 |
+
|
| 275 |
+
## 👤 Author
|
| 276 |
+
|
| 277 |
+
**VashuTheGreat (Vansh Sharma)**
|
| 278 |
+
|
| 279 |
+
> Built with ☕ and an unhealthy obsession with RAG pipelines.
|
api/constants/__init__.py
CHANGED
|
@@ -1,8 +1,2 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
DB_FOLDER_PATH="db"
|
| 4 |
-
|
| 5 |
-
AVAILABLE_ANALYSIS=['pdf','txt','docs','docx','png','url']
|
| 6 |
-
|
| 7 |
-
USER_CONTENT_FILE_NAME="USER_CONTENT.yml"
|
| 8 |
-
|
|
|
|
| 1 |
+
PUBLIC_FOLDER_FILE_PATH:str="api/public"
|
| 2 |
+
DEFAULT_COOKIE_MAX_AGE_SECONDS=60*5
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
api/main.py
CHANGED
|
@@ -1,55 +1,38 @@
|
|
| 1 |
-
from fastapi import FastAPI
|
| 2 |
-
from fastapi.
|
| 3 |
-
from
|
| 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 |
-
app.include_router(
|
| 34 |
-
app.include_router(prefix="/api/v1/
|
| 35 |
-
app.include_router(prefix="/api/v1/
|
| 36 |
-
app.include_router(prefix="/api/v1/
|
| 37 |
-
app.include_router(prefix="/api/v1/
|
| 38 |
-
app.include_router(prefix="/api/v1/conversation"
|
| 39 |
-
app.include_router(prefix="/api/v1/file_formats", router=get_available_file_fomates_route.router)
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
# # -------------------- Web -------------------------------
|
| 45 |
-
# app.include_router(page_route_web.router)
|
| 46 |
-
# app.include_router(prefix="/web",router=web_talk_routes.router)
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
# # ------------ Blog --------------------
|
| 53 |
-
# app.include_router(page_route_blog.router)
|
| 54 |
-
# app.include_router(prefix="/blog",router=blog_router.router)
|
| 55 |
-
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
+
from fastapi.staticfiles import StaticFiles
|
| 4 |
+
from api.middlewares.Authenticate_middleware import AuthenticateMiddleware
|
| 5 |
+
|
| 6 |
+
from api.routes.upload_router import router as upload_router
|
| 7 |
+
from api.routes.user_router import router as user_router
|
| 8 |
+
from api.routes.ingest_docs_router import router as ingest_router
|
| 9 |
+
from api.routes.chat_router import router as chat_router
|
| 10 |
+
from api.routes.load_conversation_router import router as load_conversation_router
|
| 11 |
+
from api.routes.frontend_router import router as frontend_router
|
| 12 |
+
app = FastAPI(
|
| 13 |
+
description="This is a MultiRag App",
|
| 14 |
+
title="Multi-Rag App",
|
| 15 |
+
version="0.0.1",
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
app.add_middleware(
|
| 19 |
+
CORSMiddleware,
|
| 20 |
+
allow_origins=["*"],
|
| 21 |
+
allow_credentials=True,
|
| 22 |
+
allow_methods=["*"],
|
| 23 |
+
allow_headers=["*"],
|
| 24 |
+
)
|
| 25 |
+
app.add_middleware(AuthenticateMiddleware)
|
| 26 |
+
|
| 27 |
+
app.mount("/static", StaticFiles(directory="api/static"), name="static")
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
app.include_router(frontend_router,prefix="")
|
| 34 |
+
app.include_router(upload_router,prefix="/api/v1/upload")
|
| 35 |
+
app.include_router(user_router,prefix="/api/v1/user")
|
| 36 |
+
app.include_router(ingest_router,prefix="/api/v1/ingest")
|
| 37 |
+
app.include_router(chat_router,prefix="/api/v1/chat")
|
| 38 |
+
app.include_router(load_conversation_router,prefix="/api/v1/conversation")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
api/middlewares/Authenticate_middleware.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import Request
|
| 2 |
+
from starlette.middleware.base import BaseHTTPMiddleware
|
| 3 |
+
from starlette.responses import JSONResponse
|
| 4 |
+
from api.states.user_state import User
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class AuthenticateMiddleware(BaseHTTPMiddleware):
|
| 8 |
+
async def dispatch(self, request: Request, call_next):
|
| 9 |
+
path = request.url.path
|
| 10 |
+
|
| 11 |
+
# ── Non-API paths (frontend pages, static assets, favicon) ──────────
|
| 12 |
+
# Never block these — anyone can browse the UI freely.
|
| 13 |
+
if not path.startswith("/api/v1/"):
|
| 14 |
+
return await call_next(request)
|
| 15 |
+
|
| 16 |
+
# ── Public API endpoints (no cookie needed) ──────────────────────────
|
| 17 |
+
if path.startswith("/api/v1/user/login"):
|
| 18 |
+
return await call_next(request)
|
| 19 |
+
|
| 20 |
+
# ── Protected API endpoints — cookie required ────────────────────────
|
| 21 |
+
thread_id = request.cookies.get("thread_id")
|
| 22 |
+
if not thread_id:
|
| 23 |
+
return JSONResponse({"error": "pls login"}, status_code=401)
|
| 24 |
+
|
| 25 |
+
request.scope["user"] = User(thread_id=thread_id)
|
| 26 |
+
return await call_next(request)
|
api/middlewares/__init__.py
ADDED
|
File without changes
|
api/routes/__init__.py
ADDED
|
File without changes
|
api/routes/chat_router.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import APIRouter, Request
|
| 2 |
+
from fastapi.responses import JSONResponse
|
| 3 |
+
import logging
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
from api.states.chat_state import ChatRequest
|
| 7 |
+
from src.pipeline.GraphRunner_pipeline import RunGraphPipeline
|
| 8 |
+
from langchain_core.messages import HumanMessage
|
| 9 |
+
from src.constants import ARTIFACT_DIR, TRANSFORMATION_FOLDER_NAME
|
| 10 |
+
|
| 11 |
+
router = APIRouter()
|
| 12 |
+
|
| 13 |
+
@router.post("", tags=['Chat'])
|
| 14 |
+
async def chat_endpoint(request: Request, chat_request: ChatRequest):
|
| 15 |
+
try:
|
| 16 |
+
user = request.scope.get("user")
|
| 17 |
+
if not user:
|
| 18 |
+
return JSONResponse(content={"error": "pls login"}, status_code=401)
|
| 19 |
+
|
| 20 |
+
thread_id = user.thread_id
|
| 21 |
+
user_artifact_dir = os.path.join(ARTIFACT_DIR, thread_id)
|
| 22 |
+
if not os.path.exists(user_artifact_dir):
|
| 23 |
+
return JSONResponse(content={"error": "first ingest the data and then chat"}, status_code=400)
|
| 24 |
+
|
| 25 |
+
vector_store_base = os.path.join(user_artifact_dir, TRANSFORMATION_FOLDER_NAME)
|
| 26 |
+
if not os.path.exists(vector_store_base):
|
| 27 |
+
return JSONResponse(content={"error": "first ingest the data and then chat"}, status_code=400)
|
| 28 |
+
|
| 29 |
+
vector_store_paths = []
|
| 30 |
+
for d in os.listdir(vector_store_base):
|
| 31 |
+
path = os.path.join(vector_store_base, d)
|
| 32 |
+
if os.path.isdir(path):
|
| 33 |
+
vector_store_paths.append(path)
|
| 34 |
+
|
| 35 |
+
if not vector_store_paths:
|
| 36 |
+
return JSONResponse(content={"error": "no vector stores found, please ingest data"}, status_code=400)
|
| 37 |
+
|
| 38 |
+
initial_state = {
|
| 39 |
+
"messages": [HumanMessage(content=chat_request.message)],
|
| 40 |
+
"vector_store_file_paths": vector_store_paths,
|
| 41 |
+
"queries": [],
|
| 42 |
+
"retreived_results": [],
|
| 43 |
+
"ai_response": ""
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
graph_pipeline = RunGraphPipeline()
|
| 47 |
+
graph_result = await graph_pipeline.run_graph(initial_state, config={"configurable": {"thread_id": thread_id}})
|
| 48 |
+
logging.info(f"Graph execution result: {graph_result}")
|
| 49 |
+
|
| 50 |
+
return JSONResponse(
|
| 51 |
+
content={
|
| 52 |
+
"response": graph_result.get("ai_response", "No response generated"),
|
| 53 |
+
"user": user.dict()
|
| 54 |
+
},
|
| 55 |
+
status_code=200
|
| 56 |
+
)
|
| 57 |
+
except Exception as e:
|
| 58 |
+
logging.error(f"Error during chat: {e}")
|
| 59 |
+
return JSONResponse(content={"error": str(e)}, status_code=500)
|
api/routes/frontend_router.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import APIRouter, Request
|
| 2 |
+
from fastapi.templating import Jinja2Templates
|
| 3 |
+
|
| 4 |
+
template = Jinja2Templates(directory="api/templates")
|
| 5 |
+
router = APIRouter()
|
| 6 |
+
|
| 7 |
+
# ─────────────────────────────────────────────────────────────────
|
| 8 |
+
# JINJA CONTEXT CONSTANTS
|
| 9 |
+
# Change values here — templates pick them up automatically.
|
| 10 |
+
# ─────────────────────────────────────────────────────────────────
|
| 11 |
+
|
| 12 |
+
# Session time-duration options shown on the upload page.
|
| 13 |
+
# Each dict must have: label, description, icon, seconds (int).
|
| 14 |
+
TIME_OPTIONS = [
|
| 15 |
+
{
|
| 16 |
+
"label": "1 Minute",
|
| 17 |
+
"description": "Quick demo or sanity check",
|
| 18 |
+
"icon": "⚡",
|
| 19 |
+
"seconds": 60,
|
| 20 |
+
},
|
| 21 |
+
{
|
| 22 |
+
"label": "2 Minutes",
|
| 23 |
+
"description": "Standard exploration session",
|
| 24 |
+
"icon": "🧪",
|
| 25 |
+
"seconds": 120,
|
| 26 |
+
},
|
| 27 |
+
{
|
| 28 |
+
"label": "3 Minutes",
|
| 29 |
+
"description": "Deep-dive knowledge session",
|
| 30 |
+
"icon": "🔬",
|
| 31 |
+
"seconds": 180,
|
| 32 |
+
},
|
| 33 |
+
{
|
| 34 |
+
"label": "10 Minutes",
|
| 35 |
+
"description": "Very Deep-dive knowledge session",
|
| 36 |
+
"icon": "🔬",
|
| 37 |
+
"seconds": 300,
|
| 38 |
+
}
|
| 39 |
+
]
|
| 40 |
+
|
| 41 |
+
# All backend API URLs consumed by upload.html JavaScript.
|
| 42 |
+
UPLOAD_PAGE_URLS = {
|
| 43 |
+
"login_base": "/api/v1/user/login",
|
| 44 |
+
"upload": "/api/v1/upload",
|
| 45 |
+
"ingest": "/api/v1/ingest",
|
| 46 |
+
"chat_page": "/chat",
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
# API URLs for chat.html
|
| 50 |
+
CHAT_PAGE_URLS = {
|
| 51 |
+
"chat": "/api/v1/chat",
|
| 52 |
+
"load_conversation": "/api/v1/conversation",
|
| 53 |
+
"ingest": "/api/v1/ingest",
|
| 54 |
+
"upload_page": "/upload",
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
# ─────────────────────────────────────────────────────────────────
|
| 59 |
+
# ROUTES
|
| 60 |
+
# ─────────────────────────────────────────────────────────────────
|
| 61 |
+
|
| 62 |
+
@router.get("/", tags=["frontend"])
|
| 63 |
+
async def home_route(request: Request):
|
| 64 |
+
return template.TemplateResponse("home.html", {"request": request})
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
@router.get("/upload", tags=["frontend"])
|
| 68 |
+
async def upload_route(request: Request):
|
| 69 |
+
return template.TemplateResponse(
|
| 70 |
+
"upload.html",
|
| 71 |
+
{
|
| 72 |
+
"request": request,
|
| 73 |
+
"time_options": TIME_OPTIONS,
|
| 74 |
+
"urls": UPLOAD_PAGE_URLS,
|
| 75 |
+
},
|
| 76 |
+
)
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
@router.get("/chat", tags=["frontend"])
|
| 80 |
+
async def chat_route(request: Request):
|
| 81 |
+
return template.TemplateResponse(
|
| 82 |
+
"chat.html",
|
| 83 |
+
{
|
| 84 |
+
"request": request,
|
| 85 |
+
"urls": CHAT_PAGE_URLS,
|
| 86 |
+
},
|
| 87 |
+
)
|
api/routes/ingest_docs_router.py
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import APIRouter, Request
|
| 2 |
+
from fastapi.responses import JSONResponse
|
| 3 |
+
import logging
|
| 4 |
+
from api.constants import PUBLIC_FOLDER_FILE_PATH
|
| 5 |
+
import os
|
| 6 |
+
|
| 7 |
+
from src.pipeline.Vectiorizer_pipeline import VectiorizerPipeline
|
| 8 |
+
from src.entity.config_entity import (
|
| 9 |
+
DataIngestionConfig,
|
| 10 |
+
ContentEmbedderConfig,
|
| 11 |
+
DataTransformationConfig,
|
| 12 |
+
ContentTransformationConfig,
|
| 13 |
+
RetreiverConfig
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
from src.constants import ARTIFACT_DIR, INGESTION_FOLDER_NAME, TRANSFORMATION_FOLDER_NAME
|
| 17 |
+
from src.retrievers.create_retreivers import Retreiver
|
| 18 |
+
router = APIRouter()
|
| 19 |
+
|
| 20 |
+
@router.get("", tags=['File'])
|
| 21 |
+
async def ingest_docs(request: Request):
|
| 22 |
+
try:
|
| 23 |
+
user = request.scope.get("user")
|
| 24 |
+
if not user:
|
| 25 |
+
return JSONResponse({"error": "pls login"}, status_code=401)
|
| 26 |
+
|
| 27 |
+
thread_id = user.thread_id
|
| 28 |
+
folder_path = os.path.join(PUBLIC_FOLDER_FILE_PATH, thread_id)
|
| 29 |
+
|
| 30 |
+
if not os.path.exists(folder_path):
|
| 31 |
+
return JSONResponse({"error": "No files found for this user"}, status_code=404)
|
| 32 |
+
|
| 33 |
+
files = [f for f in os.listdir(folder_path) if os.path.isfile(os.path.join(folder_path, f))]
|
| 34 |
+
if not files:
|
| 35 |
+
return JSONResponse({"error": "No files to ingest"}, status_code=400)
|
| 36 |
+
|
| 37 |
+
ingestion_configs = [
|
| 38 |
+
DataIngestionConfig(
|
| 39 |
+
input_file_path=os.path.join(folder_path, file_name),
|
| 40 |
+
save_file_path=f"{ARTIFACT_DIR}/{thread_id}/{INGESTION_FOLDER_NAME}/{file_name}.pdf"
|
| 41 |
+
)
|
| 42 |
+
for file_name in files
|
| 43 |
+
]
|
| 44 |
+
|
| 45 |
+
content_embedder_config = ContentEmbedderConfig(data_ingestion_configs=ingestion_configs)
|
| 46 |
+
|
| 47 |
+
transformation_configs = [
|
| 48 |
+
DataTransformationConfig(vector_store_path=f"{ARTIFACT_DIR}/{thread_id}/{TRANSFORMATION_FOLDER_NAME}/{file_name}")
|
| 49 |
+
for file_name in files
|
| 50 |
+
]
|
| 51 |
+
|
| 52 |
+
content_transformation_config = ContentTransformationConfig(data_transformation_configs=transformation_configs)
|
| 53 |
+
|
| 54 |
+
vectorizer_pipeline = VectiorizerPipeline(
|
| 55 |
+
content_embedder_config=content_embedder_config,
|
| 56 |
+
content_transformation_config=content_transformation_config
|
| 57 |
+
)
|
| 58 |
+
|
| 59 |
+
result = await vectorizer_pipeline.initiate(thread_id=thread_id)
|
| 60 |
+
logging.info(f"Vectorizer Pipeline Result: {result}")
|
| 61 |
+
vector_store_paths = [art.vector_store_path for art in result.data_transformation_artifacts]
|
| 62 |
+
|
| 63 |
+
retreiver_config = RetreiverConfig()
|
| 64 |
+
retreiver = Retreiver(retreiver_config=retreiver_config)
|
| 65 |
+
all_docs = await retreiver.get_all_documents(vector_store_paths)
|
| 66 |
+
return JSONResponse(
|
| 67 |
+
content={
|
| 68 |
+
"message": "Ingestion completed successfully",
|
| 69 |
+
"files_processed": len(files),
|
| 70 |
+
"all_docs":all_docs
|
| 71 |
+
},
|
| 72 |
+
status_code=200
|
| 73 |
+
)
|
| 74 |
+
except Exception as e:
|
| 75 |
+
logging.error(f"Error during ingestion: {e}")
|
| 76 |
+
return JSONResponse({"error": str(e)}, status_code=500)
|
api/routes/load_conversation_router.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import APIRouter, Request
|
| 2 |
+
from fastapi.responses import JSONResponse
|
| 3 |
+
import logging
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
from src.graphs.builder import load_conversation as GraphConversationLoader
|
| 7 |
+
router = APIRouter()
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
@router.get("", tags=['Conversation'])
|
| 12 |
+
async def load_conversation(request: Request):
|
| 13 |
+
try:
|
| 14 |
+
thread_id = request.scope['user'].thread_id
|
| 15 |
+
messages = await GraphConversationLoader(thread_id)
|
| 16 |
+
return JSONResponse(content={"messages": messages},status_code=200)
|
| 17 |
+
|
| 18 |
+
except Exception as e:
|
| 19 |
+
logging.error(f"Error loading conversation: {e}")
|
| 20 |
+
return JSONResponse(content={"error": "Failed to load conversation."}, status_code=500)
|
api/routes/upload_router.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import APIRouter, Request, UploadFile, File
|
| 2 |
+
from fastapi.responses import JSONResponse
|
| 3 |
+
import uuid
|
| 4 |
+
import os
|
| 5 |
+
import logging
|
| 6 |
+
from api.constants import PUBLIC_FOLDER_FILE_PATH
|
| 7 |
+
|
| 8 |
+
router = APIRouter()
|
| 9 |
+
|
| 10 |
+
@router.post("", tags=["File"])
|
| 11 |
+
async def upload_file(request: Request, file: UploadFile = File(...)):
|
| 12 |
+
try:
|
| 13 |
+
user = request.scope.get("user")
|
| 14 |
+
if not user:
|
| 15 |
+
return JSONResponse(content={"error": "pls login"}, status_code=401)
|
| 16 |
+
|
| 17 |
+
thread_id = user.thread_id
|
| 18 |
+
unique_filename = f"{uuid.uuid4()}_{file.filename}"
|
| 19 |
+
file_location = os.path.join(PUBLIC_FOLDER_FILE_PATH, thread_id, unique_filename)
|
| 20 |
+
|
| 21 |
+
os.makedirs(os.path.dirname(file_location), exist_ok=True)
|
| 22 |
+
|
| 23 |
+
with open(file_location, "wb") as f:
|
| 24 |
+
content = await file.read()
|
| 25 |
+
f.write(content)
|
| 26 |
+
|
| 27 |
+
logging.info(f"File '{file.filename}' uploaded successfully for thread '{thread_id}'.")
|
| 28 |
+
|
| 29 |
+
return JSONResponse(
|
| 30 |
+
content={
|
| 31 |
+
"message": "File uploaded successfully",
|
| 32 |
+
"filename": unique_filename,
|
| 33 |
+
"thread_id": thread_id
|
| 34 |
+
},
|
| 35 |
+
status_code=200
|
| 36 |
+
)
|
| 37 |
+
except Exception as e:
|
| 38 |
+
logging.error(f"Error occurred while saving the file: {e}")
|
| 39 |
+
return JSONResponse(content={"error": "Failed to upload the file."}, status_code=500)
|
| 40 |
+
finally:
|
| 41 |
+
await file.close()
|
api/routes/user_router.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import logging
|
| 2 |
+
|
| 3 |
+
from fastapi import APIRouter,BackgroundTasks
|
| 4 |
+
from fastapi import Request
|
| 5 |
+
import uuid
|
| 6 |
+
from fastapi.responses import JSONResponse
|
| 7 |
+
from api.constants import DEFAULT_COOKIE_MAX_AGE_SECONDS,PUBLIC_FOLDER_FILE_PATH
|
| 8 |
+
import os
|
| 9 |
+
import shutil
|
| 10 |
+
from src.graphs.builder import deleteThread as GraphThreadDeletor
|
| 11 |
+
from src.constants import ARTIFACT_DIR
|
| 12 |
+
router = APIRouter()
|
| 13 |
+
|
| 14 |
+
import asyncio
|
| 15 |
+
|
| 16 |
+
async def delete_thread(thread_id: str, delay_seconds: int):
|
| 17 |
+
"""Utility function to delete a thread after a specific delay."""
|
| 18 |
+
if delay_seconds > 0:
|
| 19 |
+
logging.info(f"Waiting {delay_seconds} seconds before deleting thread: {thread_id}")
|
| 20 |
+
await asyncio.sleep(delay_seconds)
|
| 21 |
+
|
| 22 |
+
logging.info(f"Starting deletion of thread data for thread_id: {thread_id}")
|
| 23 |
+
|
| 24 |
+
try:
|
| 25 |
+
path1 = os.path.join(ARTIFACT_DIR, thread_id)
|
| 26 |
+
path2 = os.path.join(PUBLIC_FOLDER_FILE_PATH, thread_id)
|
| 27 |
+
|
| 28 |
+
if os.path.exists(path1):
|
| 29 |
+
shutil.rmtree(path1)
|
| 30 |
+
logging.info(f"Deleted artifact data for path: {path1}")
|
| 31 |
+
if os.path.exists(path2):
|
| 32 |
+
shutil.rmtree(path2)
|
| 33 |
+
logging.info(f"Deleted public folder data for path: {path2}")
|
| 34 |
+
try:
|
| 35 |
+
GraphThreadDeletor(thread_id)
|
| 36 |
+
except Exception as e:
|
| 37 |
+
logging.error(f"Error during graph thread deletion for thread_id {thread_id}: {e}")
|
| 38 |
+
logging.info(f"Completed deletion of thread data for thread_id: {thread_id}")
|
| 39 |
+
except Exception as e:
|
| 40 |
+
logging.error(f"Error deleting thread data for thread_id {thread_id}: {e}")
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
@router.get("/login/{seconds}", tags=["User"])
|
| 44 |
+
async def login(request: Request, seconds: int, background_tasks: BackgroundTasks):
|
| 45 |
+
"""Endpoint to handle user login. Sets a cookie and schedules data deletion."""
|
| 46 |
+
|
| 47 |
+
thread_id = str(uuid.uuid4())
|
| 48 |
+
|
| 49 |
+
response = JSONResponse(content={"message": "Login successful.","thread_id": thread_id}, status_code=200)
|
| 50 |
+
response.set_cookie(
|
| 51 |
+
key="thread_id",
|
| 52 |
+
value=thread_id,
|
| 53 |
+
httponly=True,
|
| 54 |
+
max_age=DEFAULT_COOKIE_MAX_AGE_SECONDS
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
background_tasks.add_task(delete_thread, thread_id=thread_id, delay_seconds=seconds)
|
| 58 |
+
|
| 59 |
+
return response
|
api/states/__init__.py
ADDED
|
File without changes
|
api/states/chat_state.py
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pydantic import BaseModel
|
| 2 |
+
|
| 3 |
+
class ChatRequest(BaseModel):
|
| 4 |
+
message: str
|
api/states/upload_state.py
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import File, UploadFile,File
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
class UploadState(BaseModel):
|
| 6 |
+
uploaded_file:UploadFile=File(...)
|
api/states/user_state.py
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pydantic import BaseModel
|
| 2 |
+
|
| 3 |
+
class User(BaseModel):
|
| 4 |
+
thread_id:str
|
| 5 |
+
|
api/static/__init__.py
ADDED
|
File without changes
|
api/static/css/__init__.py
ADDED
|
File without changes
|
api/static/js/__init__.py
ADDED
|
File without changes
|
api/static/js/main.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
tailwind.config = {
|
| 2 |
+
theme: {
|
| 3 |
+
extend: {
|
| 4 |
+
fontFamily: {
|
| 5 |
+
sans: ['"Plus Jakarta Sans"', 'Outfit', 'sans-serif'],
|
| 6 |
+
},
|
| 7 |
+
keyframes: {
|
| 8 |
+
'spin-orbit-x': {
|
| 9 |
+
'0%': { transform: 'rotateX(75deg) rotateY(15deg) rotateZ(0deg)' },
|
| 10 |
+
'100%': { transform: 'rotateX(75deg) rotateY(15deg) rotateZ(360deg)' },
|
| 11 |
+
},
|
| 12 |
+
'spin-orbit-y': {
|
| 13 |
+
'0%': { transform: 'rotateX(75deg) rotateY(-15deg) rotateZ(120deg)' },
|
| 14 |
+
'100%': { transform: 'rotateX(75deg) rotateY(-15deg) rotateZ(480deg)' },
|
| 15 |
+
},
|
| 16 |
+
'spin-orbit-z': {
|
| 17 |
+
'0%': { transform: 'rotateX(60deg) rotateY(45deg) rotateZ(240deg)' },
|
| 18 |
+
'100%': { transform: 'rotateX(60deg) rotateY(45deg) rotateZ(600deg)' },
|
| 19 |
+
}
|
| 20 |
+
},
|
| 21 |
+
animation: {
|
| 22 |
+
'orbit-x': 'spin-orbit-x 8s linear infinite',
|
| 23 |
+
'orbit-y': 'spin-orbit-y 6s linear infinite',
|
| 24 |
+
'orbit-z': 'spin-orbit-z 10s linear infinite',
|
| 25 |
+
}
|
| 26 |
+
}
|
| 27 |
+
}
|
| 28 |
+
}
|
api/templates/__init__.py
ADDED
|
File without changes
|
api/templates/base.html
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en" class="dark">
|
| 3 |
+
|
| 4 |
+
<head>
|
| 5 |
+
<meta charset="UTF-8">
|
| 6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 7 |
+
<title>{% block title %}Multi-RAG Studio{% endblock %}</title>
|
| 8 |
+
<link href="https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700;800&family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&display=swap" rel="stylesheet">
|
| 9 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 10 |
+
<script src="{{ url_for('static', path='/js/main.js') }}"></script>
|
| 11 |
+
{% block extra_head %}{% endblock %}
|
| 12 |
+
</head>
|
| 13 |
+
|
| 14 |
+
<body class="bg-slate-950 text-slate-100 flex flex-col min-h-screen relative overflow-x-hidden selection:bg-indigo-600 selection:text-white">
|
| 15 |
+
|
| 16 |
+
<!-- Ambient background glows -->
|
| 17 |
+
<div class="absolute top-0 left-1/4 w-[500px] h-[500px] bg-indigo-900/20 rounded-full blur-[120px] pointer-events-none -z-10 animate-pulse" style="animation-duration: 10s;"></div>
|
| 18 |
+
<div class="absolute bottom-0 right-1/4 w-[600px] h-[600px] bg-purple-900/10 rounded-full blur-[150px] pointer-events-none -z-10 animate-pulse" style="animation-duration: 15s;"></div>
|
| 19 |
+
|
| 20 |
+
<!-- Grid Overlay (Radial Dots grid using Tailwind-friendly inline styles) -->
|
| 21 |
+
<div class="absolute inset-0 pointer-events-none -z-20 opacity-20" style="background-image: radial-gradient(rgba(255,255,255,0.15) 1px, transparent 1px); background-size: 24px 24px;"></div>
|
| 22 |
+
|
| 23 |
+
<nav class="sticky top-0 z-50 bg-slate-950/45 backdrop-blur-md border-b border-white/5 shadow-lg">
|
| 24 |
+
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
|
| 25 |
+
<div class="flex items-center justify-between h-16">
|
| 26 |
+
<div class="flex items-center space-x-3 cursor-pointer group">
|
| 27 |
+
<div class="relative">
|
| 28 |
+
<div class="absolute inset-0 bg-indigo-500 rounded-lg blur-md opacity-70 group-hover:opacity-100 transition-opacity"></div>
|
| 29 |
+
<div class="relative bg-gradient-to-tr from-indigo-600 to-purple-600 p-2 rounded-lg text-white font-extrabold tracking-wider text-sm shadow-lg">
|
| 30 |
+
M-RAG
|
| 31 |
+
</div>
|
| 32 |
+
</div>
|
| 33 |
+
<span class="font-extrabold text-xl bg-gradient-to-r from-white via-slate-200 to-slate-400 bg-clip-text text-transparent group-hover:to-white transition-all">
|
| 34 |
+
Multi-RAG <span class="text-xs font-bold text-indigo-400 uppercase tracking-widest ml-1 bg-indigo-500/10 px-2 py-0.5 rounded-full border border-indigo-500/20">Studio</span>
|
| 35 |
+
</span>
|
| 36 |
+
</div>
|
| 37 |
+
|
| 38 |
+
<div class="hidden md:flex space-x-8 text-sm font-semibold">
|
| 39 |
+
<a href="/" class="text-indigo-400 border-b-2 border-indigo-500 px-1 py-5 transition-all">Home</a>
|
| 40 |
+
<a href="#" class="text-slate-400 hover:text-white transition duration-200 px-1 py-5">Knowledge Base</a>
|
| 41 |
+
<a href="#" class="text-slate-400 hover:text-white transition duration-200 px-1 py-5">Analytics</a>
|
| 42 |
+
<a href="#" class="text-slate-400 hover:text-white transition duration-200 px-1 py-5">Settings</a>
|
| 43 |
+
</div>
|
| 44 |
+
|
| 45 |
+
<div class="flex items-center space-x-4">
|
| 46 |
+
<a href="#" class="text-slate-400 hover:text-white transition text-sm font-semibold hidden sm:inline-block">Docs</a>
|
| 47 |
+
|
| 48 |
+
<!-- Global session countdown timer (hidden until a session starts) -->
|
| 49 |
+
<div id="global-timer-wrapper" class="hidden">
|
| 50 |
+
<div id="global-timer-badge"
|
| 51 |
+
class="inline-flex items-center space-x-1.5 px-3 py-1.5 rounded-lg bg-indigo-500/20 border border-indigo-500/30 text-indigo-400 text-sm font-extrabold tabular-nums tracking-wide">
|
| 52 |
+
<svg class="w-3.5 h-3.5 shrink-0" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2.5">
|
| 53 |
+
<circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/>
|
| 54 |
+
</svg>
|
| 55 |
+
<span>--:--</span>
|
| 56 |
+
</div>
|
| 57 |
+
</div>
|
| 58 |
+
|
| 59 |
+
<button class="relative group overflow-hidden bg-gradient-to-r from-indigo-600 to-purple-600 hover:from-indigo-500 hover:to-purple-500 text-white px-5 py-2 rounded-lg text-sm font-bold shadow-lg shadow-indigo-500/25 transition-all duration-300">
|
| 60 |
+
<span class="relative z-10">New Chat</span>
|
| 61 |
+
<div class="absolute inset-0 bg-white/10 opacity-0 group-hover:opacity-100 transition-opacity"></div>
|
| 62 |
+
</button>
|
| 63 |
+
</div>
|
| 64 |
+
</div>
|
| 65 |
+
</div>
|
| 66 |
+
</nav>
|
| 67 |
+
|
| 68 |
+
<main class="flex-grow max-w-7xl w-full mx-auto px-4 sm:px-6 lg:px-8 py-10 relative z-10">
|
| 69 |
+
{% block main %}
|
| 70 |
+
I am the main body
|
| 71 |
+
{% endblock %}
|
| 72 |
+
</main>
|
| 73 |
+
|
| 74 |
+
<footer class="bg-slate-950/45 backdrop-blur-md border-t border-white/5 py-8 text-sm text-slate-500 mt-auto">
|
| 75 |
+
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 flex flex-col sm:flex-row items-center justify-between space-y-4 sm:space-y-0">
|
| 76 |
+
<div class="flex items-center space-x-2">
|
| 77 |
+
<span class="font-bold text-slate-400">Multi-RAG Studio</span>
|
| 78 |
+
<span class="text-slate-600">|</span>
|
| 79 |
+
<span>© 2026. All rights reserved.</span>
|
| 80 |
+
</div>
|
| 81 |
+
|
| 82 |
+
<div class="flex space-x-6 text-slate-400 font-medium">
|
| 83 |
+
<a href="#" class="hover:text-indigo-400 transition duration-150">Documentation</a>
|
| 84 |
+
<a href="#" class="hover:text-indigo-400 transition duration-150">API Reference</a>
|
| 85 |
+
<a href="#" class="hover:text-indigo-400 transition duration-150">Privacy Policy</a>
|
| 86 |
+
</div>
|
| 87 |
+
</div>
|
| 88 |
+
</footer>
|
| 89 |
+
|
| 90 |
+
{% block extra_scripts %}{% endblock %}
|
| 91 |
+
|
| 92 |
+
<!-- ═══════════════════════════════════════════════════════
|
| 93 |
+
GLOBAL SESSION TIMER — runs on every page
|
| 94 |
+
Reads from localStorage so it survives navigation.
|
| 95 |
+
Upload page saves: multirag_session_start (epoch ms)
|
| 96 |
+
multirag_session_duration (seconds)
|
| 97 |
+
══════════════════════════════════════════════════════════ -->
|
| 98 |
+
<script>
|
| 99 |
+
(function () {
|
| 100 |
+
const STORAGE_START = 'multirag_session_start'; // epoch ms when login happened
|
| 101 |
+
const STORAGE_DURATION = 'multirag_session_duration'; // total session seconds
|
| 102 |
+
|
| 103 |
+
const wrapper = document.getElementById('global-timer-wrapper');
|
| 104 |
+
const badge = document.getElementById('global-timer-badge');
|
| 105 |
+
const badgeSpan = badge ? badge.querySelector('span') : null;
|
| 106 |
+
|
| 107 |
+
function fmtTime(s) {
|
| 108 |
+
if (s <= 0) return '00:00';
|
| 109 |
+
const h = Math.floor(s / 3600);
|
| 110 |
+
const m = Math.floor((s % 3600) / 60);
|
| 111 |
+
const sec = s % 60;
|
| 112 |
+
if (h > 0)
|
| 113 |
+
return h + ':' + String(m).padStart(2,'0') + ':' + String(sec).padStart(2,'0');
|
| 114 |
+
return String(m).padStart(2,'0') + ':' + String(sec).padStart(2,'0');
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
function startNavTimer() {
|
| 118 |
+
const start = parseInt(localStorage.getItem(STORAGE_START), 10);
|
| 119 |
+
const duration = parseInt(localStorage.getItem(STORAGE_DURATION), 10);
|
| 120 |
+
if (!start || !duration) return; // no session saved yet
|
| 121 |
+
|
| 122 |
+
const expiresAt = start + duration * 1000; // epoch ms
|
| 123 |
+
|
| 124 |
+
if (wrapper) wrapper.classList.remove('hidden');
|
| 125 |
+
|
| 126 |
+
let interval;
|
| 127 |
+
|
| 128 |
+
function tick() {
|
| 129 |
+
const remaining = Math.max(0, Math.round((expiresAt - Date.now()) / 1000));
|
| 130 |
+
if (badgeSpan) badgeSpan.textContent = fmtTime(remaining);
|
| 131 |
+
|
| 132 |
+
if (remaining <= 60) {
|
| 133 |
+
badge.classList.remove('bg-indigo-500/20','text-indigo-400','border-indigo-500/30');
|
| 134 |
+
badge.classList.add('bg-red-500/20','text-red-400','border-red-500/40');
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
if (remaining <= 0) {
|
| 138 |
+
clearInterval(interval);
|
| 139 |
+
if (badgeSpan) badgeSpan.textContent = 'EXPIRED';
|
| 140 |
+
badge.classList.add('opacity-60');
|
| 141 |
+
// clean up storage so timer doesn't haunt the next session
|
| 142 |
+
localStorage.removeItem(STORAGE_START);
|
| 143 |
+
localStorage.removeItem(STORAGE_DURATION);
|
| 144 |
+
}
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
tick();
|
| 148 |
+
interval = setInterval(tick, 1000);
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
// Auto-start on every page as soon as DOM is ready
|
| 152 |
+
startNavTimer();
|
| 153 |
+
|
| 154 |
+
// Also expose so upload.html can call it after saving to localStorage
|
| 155 |
+
window.__startNavTimer = startNavTimer;
|
| 156 |
+
})();
|
| 157 |
+
</script>
|
| 158 |
+
</body>
|
| 159 |
+
|
| 160 |
+
</html>
|
api/templates/chat.html
ADDED
|
@@ -0,0 +1,584 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% extends "base.html" %}
|
| 2 |
+
{% block title %}Chat — Multi-RAG Studio{% endblock %}
|
| 3 |
+
|
| 4 |
+
{% block extra_head %}
|
| 5 |
+
<style>
|
| 6 |
+
/* ── layout ── */
|
| 7 |
+
#chat-page { height: calc(100vh - 8rem); display:flex; flex-direction:column; }
|
| 8 |
+
|
| 9 |
+
/* ── tab bar ── */
|
| 10 |
+
.tab-btn { transition: all .2s; }
|
| 11 |
+
.tab-btn.active {
|
| 12 |
+
background: rgba(99,102,241,.15);
|
| 13 |
+
border-color: rgba(99,102,241,.6);
|
| 14 |
+
color: #a5b4fc;
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
/* ── message bubbles ── */
|
| 18 |
+
.msg-user { animation: slideR .22s ease both; }
|
| 19 |
+
.msg-ai { animation: slideL .22s ease both; }
|
| 20 |
+
@keyframes slideR { from{opacity:0;transform:translateX(12px)} to{opacity:1;transform:none} }
|
| 21 |
+
@keyframes slideL { from{opacity:0;transform:translateX(-12px)} to{opacity:1;transform:none} }
|
| 22 |
+
|
| 23 |
+
/* ── AI markdown rendering ── */
|
| 24 |
+
.ai-content h1,h2,h3 { color:#e2e8f0; font-weight:700; margin:.5em 0 .25em; }
|
| 25 |
+
.ai-content p { margin:.35em 0; line-height:1.65; }
|
| 26 |
+
.ai-content ul,ol { padding-left:1.4em; margin:.3em 0; }
|
| 27 |
+
.ai-content li { margin:.2em 0; }
|
| 28 |
+
.ai-content code {
|
| 29 |
+
background:rgba(99,102,241,.15); color:#c7d2fe;
|
| 30 |
+
padding:.1em .35em; border-radius:.3em; font-size:.82em;
|
| 31 |
+
}
|
| 32 |
+
.ai-content pre { background:#0f1221; border:1px solid rgba(255,255,255,.07);
|
| 33 |
+
border-radius:.75em; padding:1em; overflow-x:auto; margin:.5em 0; }
|
| 34 |
+
.ai-content pre code { background:none; color:#94a3b8; }
|
| 35 |
+
.ai-content table { width:100%; border-collapse:collapse; margin:.5em 0; font-size:.82em; }
|
| 36 |
+
.ai-content th { background:rgba(99,102,241,.2); color:#c7d2fe; padding:.4em .7em; text-align:left; }
|
| 37 |
+
.ai-content td { border-top:1px solid rgba(255,255,255,.06); padding:.4em .7em; color:#94a3b8; }
|
| 38 |
+
|
| 39 |
+
/* ── typing dots ── */
|
| 40 |
+
.typing-dot { animation: blink 1.2s infinite; }
|
| 41 |
+
.typing-dot:nth-child(2) { animation-delay:.2s; }
|
| 42 |
+
.typing-dot:nth-child(3) { animation-delay:.4s; }
|
| 43 |
+
@keyframes blink { 0%,80%,100%{opacity:.2} 40%{opacity:1} }
|
| 44 |
+
|
| 45 |
+
/* ── doc card ── */
|
| 46 |
+
.doc-card { animation: fadeUp .25s ease both; }
|
| 47 |
+
@keyframes fadeUp { from{opacity:0;transform:translateY(8px)} to{opacity:1;transform:none} }
|
| 48 |
+
.doc-card img { max-width:100%; border-radius:.5em; margin:.5em 0; border:1px solid rgba(255,255,255,.06); }
|
| 49 |
+
|
| 50 |
+
/* ── scroll bars ── */
|
| 51 |
+
::-webkit-scrollbar { width:4px; height:4px; }
|
| 52 |
+
::-webkit-scrollbar-track { background:transparent; }
|
| 53 |
+
::-webkit-scrollbar-thumb { background:rgba(99,102,241,.35); border-radius:99px; }
|
| 54 |
+
|
| 55 |
+
/* ── textarea auto-grow ── */
|
| 56 |
+
#chat-input { resize:none; min-height:44px; max-height:160px; overflow-y:auto; }
|
| 57 |
+
</style>
|
| 58 |
+
{% endblock %}
|
| 59 |
+
|
| 60 |
+
{% block main %}
|
| 61 |
+
<div id="chat-page" class="max-w-5xl mx-auto w-full">
|
| 62 |
+
|
| 63 |
+
{# ── Tab Bar ── #}
|
| 64 |
+
<div class="flex items-center gap-3 mb-4 pt-2">
|
| 65 |
+
<button id="tab-chat" class="tab-btn active flex items-center gap-2 px-5 py-2 rounded-xl border border-white/10 text-slate-300 text-sm font-bold" onclick="switchTab('chat')">
|
| 66 |
+
💬 Chat
|
| 67 |
+
</button>
|
| 68 |
+
<button id="tab-docs" class="tab-btn flex items-center gap-2 px-5 py-2 rounded-xl border border-white/10 text-slate-400 text-sm font-bold" onclick="switchTab('docs')">
|
| 69 |
+
📄 View Ingested Docs
|
| 70 |
+
</button>
|
| 71 |
+
<div class="flex-1"></div>
|
| 72 |
+
<a href="{{ urls.upload_page }}" class="text-xs text-slate-500 hover:text-indigo-400 transition font-semibold">← Upload more</a>
|
| 73 |
+
</div>
|
| 74 |
+
|
| 75 |
+
{# ══════════════════════════════════════════════
|
| 76 |
+
PANEL 1 — CHAT
|
| 77 |
+
══════════════════════════════════════════════ #}
|
| 78 |
+
<div id="panel-chat" class="flex flex-col flex-1 min-h-0" style="height:calc(100vh - 11rem)">
|
| 79 |
+
|
| 80 |
+
{# Message list #}
|
| 81 |
+
<div id="msg-list" class="flex-1 overflow-y-auto space-y-5 pr-1 pb-4">
|
| 82 |
+
{# welcome stub #}
|
| 83 |
+
<div id="welcome-stub" class="flex flex-col items-center justify-center h-full text-center space-y-4 py-16">
|
| 84 |
+
<div class="w-16 h-16 rounded-2xl bg-indigo-500/10 border border-indigo-500/20 flex items-center justify-center text-3xl">🧠</div>
|
| 85 |
+
<p class="text-white font-extrabold text-xl">Knowledge base is ready</p>
|
| 86 |
+
<p class="text-slate-500 text-sm max-w-xs">Ask anything about the documents you ingested. The graph-powered RAG will find the answer.</p>
|
| 87 |
+
</div>
|
| 88 |
+
</div>
|
| 89 |
+
|
| 90 |
+
{# Input bar #}
|
| 91 |
+
<div class="border-t border-white/5 pt-4 pb-1">
|
| 92 |
+
<div class="flex items-end gap-3 bg-slate-900/60 border border-white/8 rounded-2xl px-4 py-3">
|
| 93 |
+
<textarea
|
| 94 |
+
id="chat-input"
|
| 95 |
+
rows="1"
|
| 96 |
+
placeholder="Ask your knowledge base…"
|
| 97 |
+
class="flex-1 bg-transparent text-slate-100 text-sm placeholder-slate-600 outline-none leading-relaxed"
|
| 98 |
+
></textarea>
|
| 99 |
+
<button id="btn-send"
|
| 100 |
+
class="shrink-0 w-10 h-10 rounded-xl bg-gradient-to-br from-indigo-600 to-purple-600 hover:from-indigo-500 hover:to-purple-500 flex items-center justify-center text-white shadow-lg shadow-indigo-500/25 transition-all disabled:opacity-40 disabled:cursor-not-allowed"
|
| 101 |
+
title="Send (Enter)">
|
| 102 |
+
<svg class="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2.5">
|
| 103 |
+
<path stroke-linecap="round" stroke-linejoin="round" d="M6 12L3.269 3.126A59.768 59.768 0 0121.485 12 59.77 59.77 0 013.27 20.876L5.999 12zm0 0h7.5"/>
|
| 104 |
+
</svg>
|
| 105 |
+
</button>
|
| 106 |
+
</div>
|
| 107 |
+
<p class="text-slate-700 text-xs mt-1.5 ml-1">Enter to send · Shift+Enter for newline</p>
|
| 108 |
+
</div>
|
| 109 |
+
</div>
|
| 110 |
+
|
| 111 |
+
{# ══════════════════════════════════════════════
|
| 112 |
+
PANEL 2 — VIEW INGESTED DOCS
|
| 113 |
+
══════════════════════════════════════════════ #}
|
| 114 |
+
<div id="panel-docs" class="hidden flex-col" style="height:calc(100vh - 11rem)">
|
| 115 |
+
|
| 116 |
+
{# Toolbar #}
|
| 117 |
+
<div class="flex items-center gap-3 mb-4">
|
| 118 |
+
<input id="doc-search" type="text" placeholder="Search documents…"
|
| 119 |
+
class="flex-1 bg-slate-900/60 border border-white/8 rounded-xl px-4 py-2 text-sm text-slate-300 placeholder-slate-600 outline-none focus:border-indigo-500/50 transition"/>
|
| 120 |
+
<button id="btn-reload-docs"
|
| 121 |
+
class="px-4 py-2 rounded-xl bg-indigo-500/10 border border-indigo-500/20 text-indigo-400 text-sm font-bold hover:bg-indigo-500/20 transition flex items-center gap-2">
|
| 122 |
+
<svg class="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
| 123 |
+
<path stroke-linecap="round" stroke-linejoin="round" d="M4 4v5h.582m0 0A8.001 8.001 0 0112 4c4.418 0 8 3.582 8 8h-2m-2 5.418A8.001 8.001 0 014 12H2"/>
|
| 124 |
+
</svg>
|
| 125 |
+
Reload
|
| 126 |
+
</button>
|
| 127 |
+
<span id="doc-count" class="text-xs text-slate-600 font-semibold"></span>
|
| 128 |
+
</div>
|
| 129 |
+
|
| 130 |
+
{# Doc grid #}
|
| 131 |
+
<div id="doc-grid" class="flex-1 overflow-y-auto space-y-3 pr-1"></div>
|
| 132 |
+
|
| 133 |
+
{# Doc loading states #}
|
| 134 |
+
<div id="docs-loading" class="hidden flex-1 flex items-center justify-center">
|
| 135 |
+
<div class="flex flex-col items-center gap-3 text-slate-500">
|
| 136 |
+
<svg class="animate-spin w-8 h-8 text-indigo-500" fill="none" viewBox="0 0 24 24">
|
| 137 |
+
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"/>
|
| 138 |
+
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8v8z"/>
|
| 139 |
+
</svg>
|
| 140 |
+
<p class="text-sm">Loading ingested documents…</p>
|
| 141 |
+
</div>
|
| 142 |
+
</div>
|
| 143 |
+
<div id="docs-empty" class="hidden flex-1 flex items-center justify-center text-slate-600 text-sm">
|
| 144 |
+
No documents found. Go back and ingest files first.
|
| 145 |
+
</div>
|
| 146 |
+
</div>
|
| 147 |
+
|
| 148 |
+
</div>
|
| 149 |
+
|
| 150 |
+
{# ── Doc detail modal ── #}
|
| 151 |
+
<div id="doc-modal" class="hidden fixed inset-0 z-50 flex items-center justify-center p-4" style="background:rgba(0,0,0,.75); backdrop-filter:blur(8px)">
|
| 152 |
+
<div class="relative w-full max-w-3xl max-h-[90vh] flex flex-col bg-slate-900 border border-white/10 rounded-2xl overflow-hidden shadow-2xl">
|
| 153 |
+
<div class="flex items-center justify-between px-6 py-4 border-b border-white/5 shrink-0">
|
| 154 |
+
<h3 id="modal-title" class="text-white font-extrabold text-base truncate max-w-[80%]"></h3>
|
| 155 |
+
<button onclick="closeModal()" class="text-slate-500 hover:text-white transition text-2xl leading-none">×</button>
|
| 156 |
+
</div>
|
| 157 |
+
<div id="modal-body" class="overflow-y-auto flex-1 p-6 space-y-5 text-sm text-slate-300"></div>
|
| 158 |
+
</div>
|
| 159 |
+
</div>
|
| 160 |
+
{% endblock %}
|
| 161 |
+
|
| 162 |
+
{% block extra_scripts %}
|
| 163 |
+
<script>
|
| 164 |
+
/* ── Jinja constants ── */
|
| 165 |
+
const URLS = {
|
| 166 |
+
chat: "{{ urls.chat }}",
|
| 167 |
+
load_conversation: "{{ urls.load_conversation }}",
|
| 168 |
+
ingest: "{{ urls.ingest }}",
|
| 169 |
+
upload_page: "{{ urls.upload_page }}"
|
| 170 |
+
};
|
| 171 |
+
|
| 172 |
+
/* ══════════════════════════════════════════
|
| 173 |
+
TABS
|
| 174 |
+
══════════════════════════════════════════ */
|
| 175 |
+
function switchTab(tab) {
|
| 176 |
+
const isChat = tab === 'chat';
|
| 177 |
+
document.getElementById('panel-chat').classList.toggle('hidden', !isChat);
|
| 178 |
+
document.getElementById('panel-docs').classList.toggle('hidden', isChat);
|
| 179 |
+
document.getElementById('tab-chat').classList.toggle('active', isChat);
|
| 180 |
+
document.getElementById('tab-docs').classList.toggle('active', !isChat);
|
| 181 |
+
if (!isChat && !docsLoaded) loadDocs();
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
/* ══════════════════════════════════════════
|
| 185 |
+
CHAT
|
| 186 |
+
══════════════════════════════════════════ */
|
| 187 |
+
let messages = []; // {role:'user'|'ai', text:string}
|
| 188 |
+
let waiting = false;
|
| 189 |
+
|
| 190 |
+
const msgList = document.getElementById('msg-list');
|
| 191 |
+
const input = document.getElementById('chat-input');
|
| 192 |
+
const btnSend = document.getElementById('btn-send');
|
| 193 |
+
const welcome = document.getElementById('welcome-stub');
|
| 194 |
+
|
| 195 |
+
/* auto-grow textarea */
|
| 196 |
+
input.addEventListener('input', () => {
|
| 197 |
+
input.style.height = 'auto';
|
| 198 |
+
input.style.height = Math.min(input.scrollHeight, 160) + 'px';
|
| 199 |
+
});
|
| 200 |
+
|
| 201 |
+
input.addEventListener('keydown', e => {
|
| 202 |
+
if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); sendMessage(); }
|
| 203 |
+
});
|
| 204 |
+
btnSend.addEventListener('click', sendMessage);
|
| 205 |
+
|
| 206 |
+
function appendBubble(role, html) {
|
| 207 |
+
welcome.style.display = 'none';
|
| 208 |
+
const isUser = role === 'user';
|
| 209 |
+
const wrap = document.createElement('div');
|
| 210 |
+
wrap.className = isUser
|
| 211 |
+
? 'msg-user flex justify-end'
|
| 212 |
+
: 'msg-ai flex justify-start items-start gap-3';
|
| 213 |
+
|
| 214 |
+
if (!isUser) {
|
| 215 |
+
wrap.innerHTML = `
|
| 216 |
+
<div class="w-8 h-8 rounded-xl bg-gradient-to-br from-indigo-600 to-purple-600 flex items-center justify-center text-sm shrink-0 mt-0.5">🧠</div>
|
| 217 |
+
<div class="ai-content max-w-[82%] bg-slate-900/60 border border-white/8 rounded-2xl rounded-tl-sm px-5 py-4 text-slate-300 text-sm leading-relaxed">${html}</div>`;
|
| 218 |
+
} else {
|
| 219 |
+
wrap.innerHTML = `
|
| 220 |
+
<div class="max-w-[75%] bg-gradient-to-br from-indigo-600/80 to-purple-700/80 border border-indigo-500/30 rounded-2xl rounded-tr-sm px-5 py-3 text-white text-sm">${escHtml(html)}</div>`;
|
| 221 |
+
}
|
| 222 |
+
msgList.appendChild(wrap);
|
| 223 |
+
msgList.scrollTop = msgList.scrollHeight;
|
| 224 |
+
return wrap;
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
function showTyping() {
|
| 228 |
+
const wrap = document.createElement('div');
|
| 229 |
+
wrap.id = 'typing-indicator';
|
| 230 |
+
wrap.className = 'msg-ai flex justify-start items-center gap-3';
|
| 231 |
+
wrap.innerHTML = `
|
| 232 |
+
<div class="w-8 h-8 rounded-xl bg-gradient-to-br from-indigo-600 to-purple-600 flex items-center justify-center text-sm shrink-0">🧠</div>
|
| 233 |
+
<div class="bg-slate-900/60 border border-white/8 rounded-2xl rounded-tl-sm px-5 py-3 flex items-center gap-1.5">
|
| 234 |
+
<span class="typing-dot w-2 h-2 rounded-full bg-indigo-400 inline-block"></span>
|
| 235 |
+
<span class="typing-dot w-2 h-2 rounded-full bg-indigo-400 inline-block"></span>
|
| 236 |
+
<span class="typing-dot w-2 h-2 rounded-full bg-indigo-400 inline-block"></span>
|
| 237 |
+
</div>`;
|
| 238 |
+
msgList.appendChild(wrap);
|
| 239 |
+
msgList.scrollTop = msgList.scrollHeight;
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
function removeTyping() {
|
| 243 |
+
const t = document.getElementById('typing-indicator');
|
| 244 |
+
if (t) t.remove();
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
async function sendMessage() {
|
| 248 |
+
const text = input.value.trim();
|
| 249 |
+
if (!text || waiting) return;
|
| 250 |
+
waiting = true;
|
| 251 |
+
btnSend.disabled = true;
|
| 252 |
+
input.value = '';
|
| 253 |
+
input.style.height = 'auto';
|
| 254 |
+
|
| 255 |
+
appendBubble('user', text);
|
| 256 |
+
showTyping();
|
| 257 |
+
|
| 258 |
+
try {
|
| 259 |
+
const res = await fetch(URLS.chat, {
|
| 260 |
+
method: 'POST',
|
| 261 |
+
credentials: 'include',
|
| 262 |
+
headers: { 'Content-Type': 'application/json' },
|
| 263 |
+
body: JSON.stringify({ message: text })
|
| 264 |
+
});
|
| 265 |
+
const data = await res.json();
|
| 266 |
+
removeTyping();
|
| 267 |
+
|
| 268 |
+
if (!res.ok) {
|
| 269 |
+
appendBubble('ai', `<span class="text-red-400">❌ ${data.error || 'Something went wrong'}</span>`);
|
| 270 |
+
} else {
|
| 271 |
+
appendBubble('ai', renderMarkdown(data.response || 'No response.'));
|
| 272 |
+
}
|
| 273 |
+
} catch (err) {
|
| 274 |
+
removeTyping();
|
| 275 |
+
appendBubble('ai', `<span class="text-red-400">❌ Network error: ${escHtml(err.message)}</span>`);
|
| 276 |
+
}
|
| 277 |
+
|
| 278 |
+
waiting = false;
|
| 279 |
+
btnSend.disabled = false;
|
| 280 |
+
input.focus();
|
| 281 |
+
}
|
| 282 |
+
|
| 283 |
+
/* ══════════════════════════════════════════
|
| 284 |
+
VIEW DOCS
|
| 285 |
+
══════════════════════════════════════════ */
|
| 286 |
+
let docsLoaded = false;
|
| 287 |
+
let allDocs = [];
|
| 288 |
+
|
| 289 |
+
async function loadDocs() {
|
| 290 |
+
const grid = document.getElementById('doc-grid');
|
| 291 |
+
const loading = document.getElementById('docs-loading');
|
| 292 |
+
const empty = document.getElementById('docs-empty');
|
| 293 |
+
|
| 294 |
+
grid.innerHTML = '';
|
| 295 |
+
loading.classList.remove('hidden');
|
| 296 |
+
loading.classList.add('flex');
|
| 297 |
+
empty.classList.add('hidden');
|
| 298 |
+
|
| 299 |
+
try {
|
| 300 |
+
const res = await fetch(URLS.ingest, { method: 'GET', credentials: 'include' });
|
| 301 |
+
const data = await res.json();
|
| 302 |
+
loading.classList.add('hidden');
|
| 303 |
+
loading.classList.remove('flex');
|
| 304 |
+
|
| 305 |
+
if (!res.ok || !Array.isArray(data.all_docs) || data.all_docs.length === 0) {
|
| 306 |
+
empty.classList.remove('hidden');
|
| 307 |
+
return;
|
| 308 |
+
}
|
| 309 |
+
|
| 310 |
+
allDocs = data.all_docs;
|
| 311 |
+
docsLoaded = true;
|
| 312 |
+
renderDocGrid(allDocs);
|
| 313 |
+
|
| 314 |
+
} catch (err) {
|
| 315 |
+
loading.classList.add('hidden');
|
| 316 |
+
loading.classList.remove('flex');
|
| 317 |
+
empty.textContent = '⚠️ Failed to load docs: ' + err.message;
|
| 318 |
+
empty.classList.remove('hidden');
|
| 319 |
+
}
|
| 320 |
+
}
|
| 321 |
+
|
| 322 |
+
function renderDocGrid(docs) {
|
| 323 |
+
const grid = document.getElementById('doc-grid');
|
| 324 |
+
grid.innerHTML = '';
|
| 325 |
+
document.getElementById('doc-count').textContent = `${docs.length} chunk${docs.length !== 1 ? 's' : ''}`;
|
| 326 |
+
|
| 327 |
+
docs.forEach((doc, idx) => {
|
| 328 |
+
const meta = doc.metadata || {};
|
| 329 |
+
const content = doc.page_content || doc.content || '';
|
| 330 |
+
const source = meta.source || meta.file_name || `Document ${idx + 1}`;
|
| 331 |
+
const page = meta.page !== undefined ? `p.${meta.page + 1}` : '';
|
| 332 |
+
const types = String(meta.types || meta.type || meta.content_type || 'text');
|
| 333 |
+
|
| 334 |
+
/* detect from metadata fields the pipeline actually sets */
|
| 335 |
+
const hasImage = meta.has_images === true || meta.has_images === 'true'
|
| 336 |
+
|| !!(meta.images && String(meta.images).length > 50)
|
| 337 |
+
|| types.includes('image');
|
| 338 |
+
const hasTable = !!(meta.tables && String(meta.tables).trim().length > 0)
|
| 339 |
+
|| types.includes('table');
|
| 340 |
+
|
| 341 |
+
/* build a small image thumbnail preview for cards */
|
| 342 |
+
const imgSrc = buildImgSrc(meta.images || meta.image_path || '');
|
| 343 |
+
|
| 344 |
+
const card = document.createElement('div');
|
| 345 |
+
card.className = 'doc-card bg-slate-900/50 border border-white/6 rounded-2xl p-5 hover:border-indigo-500/30 transition-all cursor-pointer group';
|
| 346 |
+
card.innerHTML = `
|
| 347 |
+
<div class="flex items-start justify-between gap-3 mb-3">
|
| 348 |
+
<div class="flex items-center gap-2 min-w-0">
|
| 349 |
+
<span class="text-xl shrink-0">${hasImage ? '🖼️' : hasTable ? '📊' : '📄'}</span>
|
| 350 |
+
<div class="min-w-0">
|
| 351 |
+
<p class="text-white font-bold text-sm truncate">${escHtml(source)}</p>
|
| 352 |
+
<p class="text-slate-600 text-xs">${escHtml(page)} ${types ? '· ' + escHtml(types) : ''}</p>
|
| 353 |
+
</div>
|
| 354 |
+
</div>
|
| 355 |
+
<div class="flex gap-1.5 shrink-0 flex-wrap justify-end">
|
| 356 |
+
${hasTable ? '<span class="text-xs px-2 py-0.5 rounded-full bg-yellow-500/10 text-yellow-400 border border-yellow-500/20 font-semibold">TABLE</span>' : ''}
|
| 357 |
+
${hasImage ? '<span class="text-xs px-2 py-0.5 rounded-full bg-pink-500/10 text-pink-400 border border-pink-500/20 font-semibold">IMAGE</span>' : ''}
|
| 358 |
+
<span class="text-xs px-2 py-0.5 rounded-full bg-indigo-500/10 text-indigo-400 border border-indigo-500/20 font-semibold">CHUNK ${idx + 1}</span>
|
| 359 |
+
</div>
|
| 360 |
+
</div>
|
| 361 |
+
|
| 362 |
+
${imgSrc ? `<img src="${imgSrc}" alt="chunk image" class="w-full max-h-40 object-contain rounded-xl border border-white/8 mb-3 bg-slate-950/40"/>` : ''}
|
| 363 |
+
|
| 364 |
+
<p class="text-slate-500 text-xs leading-relaxed line-clamp-3 font-mono">${escHtml(content.slice(0, 280))}${content.length > 280 ? '…' : ''}</p>
|
| 365 |
+
<div class="mt-3 flex items-center justify-between">
|
| 366 |
+
<div class="flex flex-wrap gap-2">
|
| 367 |
+
${Object.entries(meta)
|
| 368 |
+
.filter(([k]) => !['images','tables','image_path'].includes(k))
|
| 369 |
+
.slice(0, 4)
|
| 370 |
+
.map(([k, v]) =>
|
| 371 |
+
`<span class="text-xs text-slate-600 bg-slate-800/60 border border-white/5 px-2 py-0.5 rounded-lg font-mono"><b class="text-slate-500">${escHtml(k)}:</b> ${escHtml(String(v).slice(0, 30))}</span>`
|
| 372 |
+
).join('')}
|
| 373 |
+
</div>
|
| 374 |
+
<span class="text-indigo-400 text-xs font-bold opacity-0 group-hover:opacity-100 transition ml-3 shrink-0">View full →</span>
|
| 375 |
+
</div>`;
|
| 376 |
+
|
| 377 |
+
card.addEventListener('click', () => openModal(doc, idx));
|
| 378 |
+
grid.appendChild(card);
|
| 379 |
+
});
|
| 380 |
+
}
|
| 381 |
+
|
| 382 |
+
/* search */
|
| 383 |
+
document.getElementById('doc-search').addEventListener('input', function () {
|
| 384 |
+
const q = this.value.toLowerCase();
|
| 385 |
+
if (!q) { renderDocGrid(allDocs); return; }
|
| 386 |
+
renderDocGrid(allDocs.filter(d => {
|
| 387 |
+
const text = (d.page_content || d.content || '') + JSON.stringify(d.metadata || {});
|
| 388 |
+
return text.toLowerCase().includes(q);
|
| 389 |
+
}));
|
| 390 |
+
});
|
| 391 |
+
|
| 392 |
+
document.getElementById('btn-reload-docs').addEventListener('click', () => {
|
| 393 |
+
docsLoaded = false;
|
| 394 |
+
loadDocs();
|
| 395 |
+
});
|
| 396 |
+
|
| 397 |
+
/* ── helpers ── */
|
| 398 |
+
|
| 399 |
+
/**
|
| 400 |
+
* Given a value from meta.images or meta.image_path,
|
| 401 |
+
* return a usable src string (data URI or URL).
|
| 402 |
+
* The pipeline encodes images as base64 strings.
|
| 403 |
+
*/
|
| 404 |
+
function buildImgSrc(raw) {
|
| 405 |
+
if (!raw) return '';
|
| 406 |
+
const s = String(raw).trim();
|
| 407 |
+
if (!s || s.length < 20) return '';
|
| 408 |
+
/* already a data URI */
|
| 409 |
+
if (s.startsWith('data:')) return s;
|
| 410 |
+
/* plain base64 — guess JPEG (most common for extracted images) */
|
| 411 |
+
if (/^[A-Za-z0-9+/=]{20,}$/.test(s.replace(/\s/g,''))) {
|
| 412 |
+
return 'data:image/jpeg;base64,' + s.replace(/\s/g,'');
|
| 413 |
+
}
|
| 414 |
+
/* URL path */
|
| 415 |
+
return s;
|
| 416 |
+
}
|
| 417 |
+
|
| 418 |
+
/**
|
| 419 |
+
* Try to render a table value:
|
| 420 |
+
* - HTML string → inject directly
|
| 421 |
+
* - JSON array of arrays / objects → build <table>
|
| 422 |
+
* - CSV-ish text → build <table>
|
| 423 |
+
*/
|
| 424 |
+
function renderTableValue(raw) {
|
| 425 |
+
if (!raw) return '';
|
| 426 |
+
const s = String(raw).trim();
|
| 427 |
+
if (!s) return '';
|
| 428 |
+
|
| 429 |
+
/* HTML table already */
|
| 430 |
+
if (/<table/i.test(s)) return s;
|
| 431 |
+
|
| 432 |
+
/* Try JSON */
|
| 433 |
+
try {
|
| 434 |
+
const parsed = JSON.parse(s);
|
| 435 |
+
if (Array.isArray(parsed) && parsed.length) {
|
| 436 |
+
const isObjArray = typeof parsed[0] === 'object' && !Array.isArray(parsed[0]);
|
| 437 |
+
if (isObjArray) {
|
| 438 |
+
const keys = Object.keys(parsed[0]);
|
| 439 |
+
return `<table class="ai-content">
|
| 440 |
+
<thead><tr>${keys.map(k => `<th>${escHtml(k)}</th>`).join('')}</tr></thead>
|
| 441 |
+
<tbody>${parsed.map(row =>
|
| 442 |
+
`<tr>${keys.map(k => `<td>${escHtml(String(row[k] ?? ''))}</td>`).join('')}</tr>`
|
| 443 |
+
).join('')}</tbody></table>`;
|
| 444 |
+
}
|
| 445 |
+
if (Array.isArray(parsed[0])) {
|
| 446 |
+
const [head, ...rows] = parsed;
|
| 447 |
+
return `<table class="ai-content">
|
| 448 |
+
<thead><tr>${head.map(h => `<th>${escHtml(String(h))}</th>`).join('')}</tr></thead>
|
| 449 |
+
<tbody>${rows.map(r =>
|
| 450 |
+
`<tr>${r.map(c => `<td>${escHtml(String(c ?? ''))}</td>`).join('')}</tr>`
|
| 451 |
+
).join('')}</tbody></table>`;
|
| 452 |
+
}
|
| 453 |
+
}
|
| 454 |
+
} catch { /* not JSON */ }
|
| 455 |
+
|
| 456 |
+
/* Fallback: render as preformatted */
|
| 457 |
+
return `<pre class="text-slate-400 text-xs whitespace-pre-wrap">${escHtml(s)}</pre>`;
|
| 458 |
+
}
|
| 459 |
+
|
| 460 |
+
function openModal(doc, idx) {
|
| 461 |
+
const meta = doc.metadata || {};
|
| 462 |
+
const content = doc.page_content || doc.content || '';
|
| 463 |
+
const source = meta.source || meta.file_name || `Document ${idx + 1}`;
|
| 464 |
+
|
| 465 |
+
document.getElementById('modal-title').textContent = source + ` — Chunk ${idx + 1}`;
|
| 466 |
+
|
| 467 |
+
let body = '';
|
| 468 |
+
|
| 469 |
+
/* ── Metadata table (skip raw images/tables keys) ── */
|
| 470 |
+
const SKIP_KEYS = new Set(['images', 'tables', 'image_path']);
|
| 471 |
+
const metaEntries = Object.entries(meta).filter(([k]) => !SKIP_KEYS.has(k));
|
| 472 |
+
if (metaEntries.length) {
|
| 473 |
+
body += `<div>
|
| 474 |
+
<p class="text-xs font-bold uppercase tracking-wider text-slate-500 mb-2">Metadata</p>
|
| 475 |
+
<table class="w-full text-xs border-collapse">
|
| 476 |
+
<thead><tr>
|
| 477 |
+
<th class="text-left px-3 py-2 bg-slate-800/60 text-slate-400 font-semibold w-1/3">Key</th>
|
| 478 |
+
<th class="text-left px-3 py-2 bg-slate-800/60 text-slate-400 font-semibold">Value</th>
|
| 479 |
+
</tr></thead>
|
| 480 |
+
<tbody>
|
| 481 |
+
${metaEntries.map(([k, v]) => `
|
| 482 |
+
<tr class="border-t border-white/5">
|
| 483 |
+
<td class="px-3 py-2 text-slate-500 font-mono">${escHtml(k)}</td>
|
| 484 |
+
<td class="px-3 py-2 text-slate-300 font-mono break-all">${escHtml(String(v))}</td>
|
| 485 |
+
</tr>`).join('')}
|
| 486 |
+
</tbody>
|
| 487 |
+
</table>
|
| 488 |
+
</div>`;
|
| 489 |
+
}
|
| 490 |
+
|
| 491 |
+
/* ── Images (decode base64 or use path) ── */
|
| 492 |
+
const imgRaw = meta.images || meta.image_path || '';
|
| 493 |
+
const imgSrc = buildImgSrc(imgRaw);
|
| 494 |
+
if (imgSrc) {
|
| 495 |
+
body += `<div>
|
| 496 |
+
<p class="text-xs font-bold uppercase tracking-wider text-slate-500 mb-2">🖼️ Embedded Image</p>
|
| 497 |
+
<img src="${imgSrc}" alt="Embedded image"
|
| 498 |
+
class="rounded-xl border border-white/8 max-h-80 w-full object-contain bg-slate-950/40"
|
| 499 |
+
onerror="this.parentElement.innerHTML='<p class=text-slate-600 text-xs>Image could not be displayed.</p>'"/>
|
| 500 |
+
</div>`;
|
| 501 |
+
}
|
| 502 |
+
|
| 503 |
+
/* ── Tables ── */
|
| 504 |
+
const tableRaw = meta.tables || '';
|
| 505 |
+
if (tableRaw && String(tableRaw).trim().length > 0) {
|
| 506 |
+
body += `<div>
|
| 507 |
+
<p class="text-xs font-bold uppercase tracking-wider text-slate-500 mb-2">📊 Embedded Table</p>
|
| 508 |
+
<div class="overflow-x-auto rounded-xl border border-white/6 bg-slate-950/40 p-3">
|
| 509 |
+
${renderTableValue(tableRaw)}
|
| 510 |
+
</div>
|
| 511 |
+
</div>`;
|
| 512 |
+
}
|
| 513 |
+
|
| 514 |
+
/* ── Content ── */
|
| 515 |
+
body += `<div>
|
| 516 |
+
<p class="text-xs font-bold uppercase tracking-wider text-slate-500 mb-2">Content</p>
|
| 517 |
+
<div class="bg-slate-950/60 border border-white/6 rounded-xl p-4 text-slate-300 text-xs font-mono leading-relaxed whitespace-pre-wrap max-h-64 overflow-y-auto">${escHtml(content)}</div>
|
| 518 |
+
</div>`;
|
| 519 |
+
|
| 520 |
+
document.getElementById('modal-body').innerHTML = body;
|
| 521 |
+
document.getElementById('doc-modal').classList.remove('hidden');
|
| 522 |
+
}
|
| 523 |
+
|
| 524 |
+
function closeModal() {
|
| 525 |
+
document.getElementById('doc-modal').classList.add('hidden');
|
| 526 |
+
}
|
| 527 |
+
|
| 528 |
+
/* close on backdrop click */
|
| 529 |
+
document.getElementById('doc-modal').addEventListener('click', function (e) {
|
| 530 |
+
if (e.target === this) closeModal();
|
| 531 |
+
});
|
| 532 |
+
|
| 533 |
+
/* ══════════════════════════════════════════
|
| 534 |
+
HELPERS
|
| 535 |
+
══════════════════════════════════════════ */
|
| 536 |
+
function escHtml(str) {
|
| 537 |
+
return String(str)
|
| 538 |
+
.replace(/&/g, '&')
|
| 539 |
+
.replace(/</g, '<')
|
| 540 |
+
.replace(/>/g, '>')
|
| 541 |
+
.replace(/"/g, '"');
|
| 542 |
+
}
|
| 543 |
+
|
| 544 |
+
/* Very lightweight markdown → HTML (no deps) */
|
| 545 |
+
function renderMarkdown(md) {
|
| 546 |
+
return md
|
| 547 |
+
/* code blocks */
|
| 548 |
+
.replace(/```(\w*)\n?([\s\S]*?)```/g, (_, lang, code) =>
|
| 549 |
+
`<pre><code class="lang-${lang}">${escHtml(code.trim())}</code></pre>`)
|
| 550 |
+
/* inline code */
|
| 551 |
+
.replace(/`([^`]+)`/g, '<code>$1</code>')
|
| 552 |
+
/* bold */
|
| 553 |
+
.replace(/\*\*(.+?)\*\*/g, '<b>$1</b>')
|
| 554 |
+
/* italic */
|
| 555 |
+
.replace(/\*(.+?)\*/g, '<em>$1</em>')
|
| 556 |
+
/* headings */
|
| 557 |
+
.replace(/^### (.+)$/gm, '<h3>$1</h3>')
|
| 558 |
+
.replace(/^## (.+)$/gm, '<h2>$1</h2>')
|
| 559 |
+
.replace(/^# (.+)$/gm, '<h1>$1</h1>')
|
| 560 |
+
/* unordered list */
|
| 561 |
+
.replace(/^\s*[-*] (.+)$/gm, '<li>$1</li>')
|
| 562 |
+
.replace(/(<li>[\s\S]+?<\/li>)/g, '<ul>$1</ul>')
|
| 563 |
+
/* line breaks */
|
| 564 |
+
.replace(/\n\n/g, '</p><p>')
|
| 565 |
+
.replace(/^(?!<[hup])/gm, '')
|
| 566 |
+
.replace(/(.+)/gs, s => s.startsWith('<') ? s : `<p>${s}</p>`);
|
| 567 |
+
}
|
| 568 |
+
|
| 569 |
+
/* Load history on page open */
|
| 570 |
+
(async function loadHistory() {
|
| 571 |
+
try {
|
| 572 |
+
const res = await fetch(URLS.load_conversation, { credentials: 'include' });
|
| 573 |
+
const data = await res.json();
|
| 574 |
+
if (!res.ok || !Array.isArray(data.messages)) return;
|
| 575 |
+
data.messages.forEach(m => {
|
| 576 |
+
if (m.type === 'human' || m.role === 'user')
|
| 577 |
+
appendBubble('user', m.content || m.text || '');
|
| 578 |
+
else if (m.type === 'ai' || m.role === 'assistant')
|
| 579 |
+
appendBubble('ai', renderMarkdown(m.content || m.text || ''));
|
| 580 |
+
});
|
| 581 |
+
} catch { /* fresh session, no history */ }
|
| 582 |
+
})();
|
| 583 |
+
</script>
|
| 584 |
+
{% endblock %}
|
api/templates/home.html
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% extends "base.html" %}
|
| 2 |
+
|
| 3 |
+
{% block main %}
|
| 4 |
+
<div class="relative min-h-[calc(100vh-12rem)] flex flex-col justify-center py-6 sm:py-12">
|
| 5 |
+
<!-- Hero Section Grid -->
|
| 6 |
+
<div class="grid grid-cols-1 lg:grid-cols-12 gap-12 lg:gap-8 items-center">
|
| 7 |
+
|
| 8 |
+
<!-- Left Side: Interactive Copy -->
|
| 9 |
+
<div class="lg:col-span-7 space-y-8 text-left">
|
| 10 |
+
<!-- Awesome badges -->
|
| 11 |
+
<div class="inline-flex items-center space-x-2 bg-indigo-500/10 text-indigo-400 px-4 py-1.5 rounded-full text-xs font-bold tracking-wider uppercase border border-indigo-500/20">
|
| 12 |
+
<span>⚡ Next-Gen Multi-Modal Agentic RAG</span>
|
| 13 |
+
</div>
|
| 14 |
+
|
| 15 |
+
<!-- Title -->
|
| 16 |
+
<h1 class="text-4xl sm:text-5xl lg:text-6xl font-black tracking-tight text-white leading-none">
|
| 17 |
+
Make RAG Great Again. <br>
|
| 18 |
+
<span class="bg-gradient-to-r from-indigo-400 via-purple-400 to-pink-500 bg-clip-text text-transparent">
|
| 19 |
+
Vectorize Everything.
|
| 20 |
+
</span>
|
| 21 |
+
</h1>
|
| 22 |
+
|
| 23 |
+
<!-- Description -->
|
| 24 |
+
<p class="text-base sm:text-lg text-slate-400 leading-relaxed max-w-xl">
|
| 25 |
+
Upload PDFs, clinical datasets, brain scans, audio logs, or your deepest existential thoughts.
|
| 26 |
+
Our AI vectorizes them into neat 384-dimensional math, builds a mind-bending knowledge graph,
|
| 27 |
+
and lets you chat with it.
|
| 28 |
+
<span class="text-slate-500 italic block mt-2 text-xs">
|
| 29 |
+
*Disclaimer: We are not responsible if the LLM starts giving life advice or questioning your queries.
|
| 30 |
+
</span>
|
| 31 |
+
</p>
|
| 32 |
+
|
| 33 |
+
<!-- Action Buttons -->
|
| 34 |
+
<div class="flex flex-col sm:flex-row gap-4">
|
| 35 |
+
<a href="/upload" class="inline-flex items-center justify-center px-6 py-3.5 bg-gradient-to-r from-indigo-600 to-purple-600 hover:from-indigo-500 hover:to-purple-500 text-white font-extrabold rounded-xl shadow-lg shadow-indigo-500/30 hover:shadow-indigo-500/50 transition-all duration-300 transform hover:-translate-y-0.5 active:translate-y-0 text-center">
|
| 36 |
+
Start Your First RAG 🚀
|
| 37 |
+
</a>
|
| 38 |
+
<a href="#features" class="inline-flex items-center justify-center px-6 py-3.5 bg-slate-900/60 hover:bg-slate-800/80 text-slate-300 hover:text-white font-bold rounded-xl border border-white/10 hover:border-white/20 backdrop-blur-sm transition-all duration-200 text-center">
|
| 39 |
+
How it works (or magic?)
|
| 40 |
+
</a>
|
| 41 |
+
</div>
|
| 42 |
+
|
| 43 |
+
<!-- Quick stats banner -->
|
| 44 |
+
<div class="pt-6 border-t border-white/5 flex flex-wrap gap-8 text-sm">
|
| 45 |
+
<div>
|
| 46 |
+
<span class="block text-2xl font-extrabold text-indigo-400">0.04ms</span>
|
| 47 |
+
<span class="text-slate-500 font-semibold">Average Retrieval Latency</span>
|
| 48 |
+
</div>
|
| 49 |
+
<div>
|
| 50 |
+
<span class="block text-2xl font-extrabold text-pink-400">100%</span>
|
| 51 |
+
<span class="text-slate-500 font-semibold">Hallucination Mitigation*</span>
|
| 52 |
+
</div>
|
| 53 |
+
<div>
|
| 54 |
+
<span class="block text-2xl font-extrabold text-purple-400">Multi</span>
|
| 55 |
+
<span class="text-slate-500 font-semibold">Modal Support</span>
|
| 56 |
+
</div>
|
| 57 |
+
</div>
|
| 58 |
+
</div>
|
| 59 |
+
|
| 60 |
+
<!-- Right Side: Beautiful 3D AI Atom Orbit Animation -->
|
| 61 |
+
<div class="lg:col-span-5 flex items-center justify-center py-8 lg:py-0 relative">
|
| 62 |
+
<!-- Background Glow Circle -->
|
| 63 |
+
<div class="absolute w-72 h-72 rounded-full bg-purple-500/10 blur-3xl -z-10 animate-pulse"></div>
|
| 64 |
+
|
| 65 |
+
<!-- Atom Container with 3D Perspective -->
|
| 66 |
+
<div class="relative w-80 h-80 flex items-center justify-center" style="perspective: 1000px; transform-style: preserve-3d;">
|
| 67 |
+
|
| 68 |
+
<!-- Central Nucleus: Glowing Core containing "AI" -->
|
| 69 |
+
<div class="relative z-10 w-24 h-24 rounded-full bg-gradient-to-tr from-indigo-500 via-purple-500 to-pink-500 flex items-center justify-center border border-white/20 shadow-[0_0_60px_rgba(99,102,241,0.7)] select-none">
|
| 70 |
+
<div class="absolute inset-1 rounded-full bg-slate-950/80 backdrop-blur-sm flex items-center justify-center">
|
| 71 |
+
<span class="text-transparent bg-clip-text bg-gradient-to-r from-white via-indigo-200 to-purple-400 font-black text-3xl tracking-wider animate-pulse">
|
| 72 |
+
AI
|
| 73 |
+
</span>
|
| 74 |
+
</div>
|
| 75 |
+
<!-- Outer orbit rotation accent -->
|
| 76 |
+
<div class="absolute inset-0.5 rounded-full border border-white/10 animate-spin" style="animation-duration: 3s;"></div>
|
| 77 |
+
</div>
|
| 78 |
+
|
| 79 |
+
<!-- Orbit Ring 1 (X Axis) -->
|
| 80 |
+
<div class="absolute w-72 h-72 border border-indigo-400/20 rounded-full animate-orbit-x flex items-center justify-center" style="transform-style: preserve-3d;">
|
| 81 |
+
<!-- Orbiting Electron -->
|
| 82 |
+
<div class="absolute top-0 w-4.5 h-4.5 rounded-full bg-indigo-400 shadow-[0_0_15px_#818cf8] border border-white/30">
|
| 83 |
+
<div class="w-full h-full rounded-full bg-white animate-ping opacity-60"></div>
|
| 84 |
+
</div>
|
| 85 |
+
</div>
|
| 86 |
+
|
| 87 |
+
<!-- Orbit Ring 2 (Y Axis) -->
|
| 88 |
+
<div class="absolute w-72 h-72 border border-pink-400/20 rounded-full animate-orbit-y flex items-center justify-center" style="transform-style: preserve-3d;">
|
| 89 |
+
<!-- Orbiting Electron -->
|
| 90 |
+
<div class="absolute top-0 w-4.5 h-4.5 rounded-full bg-pink-400 shadow-[0_0_15px_#f472b6] border border-white/30">
|
| 91 |
+
<div class="w-full h-full rounded-full bg-white animate-ping opacity-60"></div>
|
| 92 |
+
</div>
|
| 93 |
+
</div>
|
| 94 |
+
|
| 95 |
+
<!-- Orbit Ring 3 (Z Axis) -->
|
| 96 |
+
<div class="absolute w-72 h-72 border border-purple-400/20 rounded-full animate-orbit-z flex items-center justify-center" style="transform-style: preserve-3d;">
|
| 97 |
+
<!-- Orbiting Electron -->
|
| 98 |
+
<div class="absolute top-0 w-4.5 h-4.5 rounded-full bg-purple-400 shadow-[0_0_15px_#c084fc] border border-white/30">
|
| 99 |
+
<div class="w-full h-full rounded-full bg-white animate-ping opacity-60"></div>
|
| 100 |
+
</div>
|
| 101 |
+
</div>
|
| 102 |
+
</div>
|
| 103 |
+
</div>
|
| 104 |
+
|
| 105 |
+
</div>
|
| 106 |
+
|
| 107 |
+
<!-- Feature Grid Section -->
|
| 108 |
+
<div id="features" class="mt-24 pt-16 border-t border-white/5 space-y-12">
|
| 109 |
+
<div class="text-center max-w-2xl mx-auto space-y-4">
|
| 110 |
+
<h2 class="text-3xl font-extrabold text-white">How The Magic Works</h2>
|
| 111 |
+
<p class="text-slate-400 text-sm sm:text-base">We took the boring parts of Retrieval-Augmented Generation, sprinkled some high-speed agentic loops, and wrapped it in code.</p>
|
| 112 |
+
</div>
|
| 113 |
+
|
| 114 |
+
<div class="grid grid-cols-1 md:grid-cols-3 gap-8">
|
| 115 |
+
<!-- Feature 1 -->
|
| 116 |
+
<div class="p-6 rounded-2xl bg-slate-900/40 border border-white/5 hover:border-indigo-500/30 transition-all duration-300 group hover:-translate-y-1">
|
| 117 |
+
<div class="w-12 h-12 rounded-xl bg-indigo-500/10 text-indigo-400 flex items-center justify-center mb-6 font-black text-xl group-hover:scale-110 transition-transform">
|
| 118 |
+
📥
|
| 119 |
+
</div>
|
| 120 |
+
<h3 class="text-lg font-bold text-white mb-2">Ingest & Chunk</h3>
|
| 121 |
+
<p class="text-sm text-slate-400 leading-relaxed">
|
| 122 |
+
Upload clinical CSVs, images, or standard PDFs. Our pipeline ingests and chunks them, ready to feed the vectors.
|
| 123 |
+
</p>
|
| 124 |
+
</div>
|
| 125 |
+
|
| 126 |
+
<!-- Feature 2 -->
|
| 127 |
+
<div class="p-6 rounded-2xl bg-slate-900/40 border border-white/5 hover:border-purple-500/30 transition-all duration-300 group hover:-translate-y-1">
|
| 128 |
+
<div class="w-12 h-12 rounded-xl bg-purple-500/10 text-purple-400 flex items-center justify-center mb-6 font-black text-xl group-hover:scale-110 transition-transform">
|
| 129 |
+
🧠
|
| 130 |
+
</div>
|
| 131 |
+
<h3 class="text-lg font-bold text-white mb-2">Vectorize & Connect</h3>
|
| 132 |
+
<p class="text-sm text-slate-400 leading-relaxed">
|
| 133 |
+
Powered by all-MiniLM-L6-v2, converting unstructured text into dense math vectors, establishing links instantly.
|
| 134 |
+
</p>
|
| 135 |
+
</div>
|
| 136 |
+
|
| 137 |
+
<!-- Feature 3 -->
|
| 138 |
+
<div class="p-6 rounded-2xl bg-slate-900/40 border border-white/5 hover:border-pink-500/30 transition-all duration-300 group hover:-translate-y-1">
|
| 139 |
+
<div class="w-12 h-12 rounded-xl bg-pink-500/10 text-pink-400 flex items-center justify-center mb-6 font-black text-xl group-hover:scale-110 transition-transform">
|
| 140 |
+
💬
|
| 141 |
+
</div>
|
| 142 |
+
<h3 class="text-lg font-bold text-white mb-2">Graph Retrieval Chat</h3>
|
| 143 |
+
<p class="text-sm text-slate-400 leading-relaxed">
|
| 144 |
+
Query your agent. Using stateful LangGraph chains, the system navigates nodes to fetch context and streams back accurate answers.
|
| 145 |
+
</p>
|
| 146 |
+
</div>
|
| 147 |
+
</div>
|
| 148 |
+
</div>
|
| 149 |
+
</div>
|
| 150 |
+
{% endblock %}
|
api/templates/upload.html
ADDED
|
@@ -0,0 +1,570 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% extends "base.html" %}
|
| 2 |
+
|
| 3 |
+
{% block title %}Upload Files — Multi-RAG Studio{% endblock %}
|
| 4 |
+
|
| 5 |
+
{% block extra_head %}
|
| 6 |
+
<style>
|
| 7 |
+
/* ── Drop Zone ── */
|
| 8 |
+
#drop-zone {
|
| 9 |
+
border: 2px dashed rgba(99,102,241,0.35);
|
| 10 |
+
transition: border-color 0.25s, background 0.25s, transform 0.2s;
|
| 11 |
+
}
|
| 12 |
+
#drop-zone.drag-over {
|
| 13 |
+
border-color: rgba(99,102,241,0.9);
|
| 14 |
+
background: rgba(99,102,241,0.06);
|
| 15 |
+
transform: scale(1.01);
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
/* ── File chip ── */
|
| 19 |
+
.file-chip {
|
| 20 |
+
animation: chipIn 0.25s cubic-bezier(0.34,1.56,0.64,1) both;
|
| 21 |
+
}
|
| 22 |
+
@keyframes chipIn {
|
| 23 |
+
from { opacity:0; transform:scale(0.7) translateY(6px); }
|
| 24 |
+
to { opacity:1; transform:scale(1) translateY(0); }
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
/* ── Progress bar shimmer ── */
|
| 28 |
+
.shimmer {
|
| 29 |
+
background: linear-gradient(90deg,
|
| 30 |
+
rgba(99,102,241,0.0) 0%,
|
| 31 |
+
rgba(99,102,241,0.6) 50%,
|
| 32 |
+
rgba(99,102,241,0.0) 100%);
|
| 33 |
+
background-size: 200% 100%;
|
| 34 |
+
animation: shimmer 1.5s infinite;
|
| 35 |
+
}
|
| 36 |
+
@keyframes shimmer {
|
| 37 |
+
0% { background-position: -200% 0; }
|
| 38 |
+
100% { background-position: 200% 0; }
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
/* ── Step pill ── */
|
| 42 |
+
.step-pill {
|
| 43 |
+
transition: background 0.3s, color 0.3s, border-color 0.3s;
|
| 44 |
+
}
|
| 45 |
+
.step-pill.active { background:rgba(99,102,241,0.18); border-color:rgba(99,102,241,0.6); color:#a5b4fc; }
|
| 46 |
+
.step-pill.done { background:rgba(34,197,94,0.12); border-color:rgba(34,197,94,0.4); color:#86efac; }
|
| 47 |
+
|
| 48 |
+
/* ── Ingestion log line ── */
|
| 49 |
+
.log-line { animation: logIn 0.2s ease both; }
|
| 50 |
+
@keyframes logIn {
|
| 51 |
+
from { opacity:0; transform:translateX(-8px); }
|
| 52 |
+
to { opacity:1; transform:translateX(0); }
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
/* ── Pulsing dot ── */
|
| 56 |
+
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0.2} }
|
| 57 |
+
.blink { animation: blink 1s step-end infinite; }
|
| 58 |
+
|
| 59 |
+
/* ── Timer badge ── */
|
| 60 |
+
#global-timer-badge {
|
| 61 |
+
font-variant-numeric: tabular-nums;
|
| 62 |
+
min-width: 80px;
|
| 63 |
+
}
|
| 64 |
+
</style>
|
| 65 |
+
{% endblock %}
|
| 66 |
+
|
| 67 |
+
{% block main %}
|
| 68 |
+
|
| 69 |
+
{# ─── PHASE 1 : Login / Time Selection ──────────────────────────────────── #}
|
| 70 |
+
<section id="phase-login" class="flex items-center justify-center min-h-[calc(100vh-12rem)]">
|
| 71 |
+
<div class="w-full max-w-md space-y-8">
|
| 72 |
+
|
| 73 |
+
<div class="text-center space-y-2">
|
| 74 |
+
<div class="inline-flex items-center space-x-2 bg-indigo-500/10 text-indigo-400 px-4 py-1.5 rounded-full text-xs font-bold tracking-wider uppercase border border-indigo-500/20">
|
| 75 |
+
<span>⏱ Session Setup</span>
|
| 76 |
+
</div>
|
| 77 |
+
<h1 class="text-3xl font-black text-white tracking-tight">How long do you need?</h1>
|
| 78 |
+
<p class="text-slate-400 text-sm">Your session — and all its data — will be auto-wiped after the timer ends.</p>
|
| 79 |
+
</div>
|
| 80 |
+
|
| 81 |
+
{# Time options injected by Jinja from Python constants #}
|
| 82 |
+
<div class="grid gap-3" id="time-options">
|
| 83 |
+
{% for opt in time_options %}
|
| 84 |
+
<button
|
| 85 |
+
class="time-btn group relative w-full flex items-center justify-between px-6 py-4 rounded-2xl bg-slate-900/50 border border-white/8 hover:border-indigo-500/50 hover:bg-slate-800/60 transition-all duration-200 text-left"
|
| 86 |
+
data-seconds="{{ opt.seconds }}">
|
| 87 |
+
<div class="flex items-center space-x-4">
|
| 88 |
+
<div class="w-10 h-10 rounded-xl bg-indigo-500/10 text-indigo-400 flex items-center justify-center text-lg font-extrabold group-hover:scale-110 transition-transform">
|
| 89 |
+
{{ opt.icon }}
|
| 90 |
+
</div>
|
| 91 |
+
<div>
|
| 92 |
+
<p class="text-white font-bold text-sm">{{ opt.label }}</p>
|
| 93 |
+
<p class="text-slate-500 text-xs">{{ opt.description }}</p>
|
| 94 |
+
</div>
|
| 95 |
+
</div>
|
| 96 |
+
<span class="text-indigo-400 font-black text-lg opacity-0 group-hover:opacity-100 transition-opacity">→</span>
|
| 97 |
+
</button>
|
| 98 |
+
{% endfor %}
|
| 99 |
+
</div>
|
| 100 |
+
|
| 101 |
+
<div id="login-status" class="hidden text-center space-y-2">
|
| 102 |
+
<div class="inline-flex items-center space-x-2 text-indigo-400 text-sm font-semibold">
|
| 103 |
+
<svg class="animate-spin w-4 h-4" fill="none" viewBox="0 0 24 24">
|
| 104 |
+
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"/>
|
| 105 |
+
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8v8z"/>
|
| 106 |
+
</svg>
|
| 107 |
+
<span>Starting your session…</span>
|
| 108 |
+
</div>
|
| 109 |
+
</div>
|
| 110 |
+
|
| 111 |
+
</div>
|
| 112 |
+
</section>
|
| 113 |
+
|
| 114 |
+
{# ─── PHASE 2 : File Upload ──────────────────────────────────────────────── #}
|
| 115 |
+
<section id="phase-upload" class="hidden min-h-[calc(100vh-12rem)] flex flex-col justify-center py-10">
|
| 116 |
+
<div class="max-w-2xl mx-auto w-full space-y-8">
|
| 117 |
+
|
| 118 |
+
{# Steps indicator #}
|
| 119 |
+
<div class="flex items-center space-x-2 text-xs font-bold">
|
| 120 |
+
<span class="step-pill active px-3 py-1 rounded-full border" id="step-upload-pill">1. Upload</span>
|
| 121 |
+
<span class="flex-1 h-px bg-white/10"></span>
|
| 122 |
+
<span class="step-pill px-3 py-1 rounded-full border border-white/10 text-slate-500" id="step-ingest-pill">2. Ingest</span>
|
| 123 |
+
<span class="flex-1 h-px bg-white/10"></span>
|
| 124 |
+
<span class="step-pill px-3 py-1 rounded-full border border-white/10 text-slate-500" id="step-chat-pill">3. Chat</span>
|
| 125 |
+
</div>
|
| 126 |
+
|
| 127 |
+
<div class="space-y-2">
|
| 128 |
+
<h2 class="text-2xl font-extrabold text-white">Upload your files</h2>
|
| 129 |
+
<p class="text-slate-400 text-sm">PDFs, CSVs, text, images — any format, any quantity.</p>
|
| 130 |
+
</div>
|
| 131 |
+
|
| 132 |
+
{# Drop zone #}
|
| 133 |
+
<div
|
| 134 |
+
id="drop-zone"
|
| 135 |
+
class="relative rounded-2xl p-12 flex flex-col items-center justify-center space-y-4 cursor-pointer bg-slate-900/30 text-center select-none">
|
| 136 |
+
<input type="file" id="file-input" multiple class="absolute inset-0 w-full h-full opacity-0 cursor-pointer z-10" />
|
| 137 |
+
<div class="w-16 h-16 rounded-2xl bg-indigo-500/10 border border-indigo-500/20 flex items-center justify-center text-3xl pointer-events-none">
|
| 138 |
+
📂
|
| 139 |
+
</div>
|
| 140 |
+
<div class="pointer-events-none">
|
| 141 |
+
<p class="text-white font-bold text-base">Drag & drop files here</p>
|
| 142 |
+
<p class="text-slate-500 text-xs mt-1">or click anywhere in this box to browse</p>
|
| 143 |
+
</div>
|
| 144 |
+
<div class="pointer-events-none text-xs text-slate-600 border border-white/5 px-3 py-1 rounded-full bg-slate-900/40">
|
| 145 |
+
All file types · No size limit
|
| 146 |
+
</div>
|
| 147 |
+
</div>
|
| 148 |
+
|
| 149 |
+
{# File list #}
|
| 150 |
+
<div id="file-list" class="space-y-2 hidden">
|
| 151 |
+
<p class="text-slate-400 text-xs font-semibold uppercase tracking-wider">Queued files</p>
|
| 152 |
+
<div id="file-chips" class="space-y-2 max-h-56 overflow-y-auto pr-1"></div>
|
| 153 |
+
</div>
|
| 154 |
+
|
| 155 |
+
{# Upload progress #}
|
| 156 |
+
<div id="upload-progress-wrapper" class="hidden space-y-2">
|
| 157 |
+
<div class="flex items-center justify-between text-xs text-slate-400">
|
| 158 |
+
<span id="upload-progress-label">Uploading…</span>
|
| 159 |
+
<span id="upload-progress-pct">0%</span>
|
| 160 |
+
</div>
|
| 161 |
+
<div class="w-full h-1.5 rounded-full bg-slate-800 overflow-hidden">
|
| 162 |
+
<div id="upload-progress-bar" class="h-full rounded-full bg-gradient-to-r from-indigo-500 to-purple-500 transition-all duration-300" style="width:0%"></div>
|
| 163 |
+
</div>
|
| 164 |
+
</div>
|
| 165 |
+
|
| 166 |
+
{# Action buttons #}
|
| 167 |
+
<div class="flex gap-3">
|
| 168 |
+
<button id="btn-clear" class="hidden px-4 py-2.5 rounded-xl bg-slate-800 hover:bg-slate-700 text-slate-400 hover:text-white text-sm font-semibold transition-all duration-200 border border-white/5">
|
| 169 |
+
Clear all
|
| 170 |
+
</button>
|
| 171 |
+
<button id="btn-continue-upload"
|
| 172 |
+
class="flex-1 inline-flex items-center justify-center px-6 py-3.5 rounded-xl bg-gradient-to-r from-indigo-600 to-purple-600 hover:from-indigo-500 hover:to-purple-500 text-white font-extrabold shadow-lg shadow-indigo-500/30 transition-all duration-300 disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:from-indigo-600 disabled:hover:to-purple-600"
|
| 173 |
+
disabled>
|
| 174 |
+
Continue →
|
| 175 |
+
</button>
|
| 176 |
+
</div>
|
| 177 |
+
|
| 178 |
+
</div>
|
| 179 |
+
</section>
|
| 180 |
+
|
| 181 |
+
{# ─── PHASE 3 : Ingestion ───────────────────────────────────────────────── #}
|
| 182 |
+
<section id="phase-ingest" class="hidden min-h-[calc(100vh-12rem)] flex flex-col justify-center py-10">
|
| 183 |
+
<div class="max-w-2xl mx-auto w-full space-y-8">
|
| 184 |
+
|
| 185 |
+
{# Steps indicator #}
|
| 186 |
+
<div class="flex items-center space-x-2 text-xs font-bold">
|
| 187 |
+
<span class="step-pill done px-3 py-1 rounded-full border" id="step-upload-pill2">✓ Upload</span>
|
| 188 |
+
<span class="flex-1 h-px bg-white/10"></span>
|
| 189 |
+
<span class="step-pill active px-3 py-1 rounded-full border" id="step-ingest-pill2">2. Ingesting</span>
|
| 190 |
+
<span class="flex-1 h-px bg-white/10"></span>
|
| 191 |
+
<span class="step-pill px-3 py-1 rounded-full border border-white/10 text-slate-500">3. Chat</span>
|
| 192 |
+
</div>
|
| 193 |
+
|
| 194 |
+
<div class="space-y-2">
|
| 195 |
+
<h2 class="text-2xl font-extrabold text-white flex items-center gap-3">
|
| 196 |
+
<span id="ingest-title">Data Ingestion Starting…</span>
|
| 197 |
+
<span id="ingest-spinner" class="inline-flex">
|
| 198 |
+
<svg class="animate-spin w-5 h-5 text-indigo-400" fill="none" viewBox="0 0 24 24">
|
| 199 |
+
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"/>
|
| 200 |
+
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8v8z"/>
|
| 201 |
+
</svg>
|
| 202 |
+
</span>
|
| 203 |
+
</h2>
|
| 204 |
+
<p class="text-slate-400 text-sm">Vectorizing, embedding, building knowledge graph… grab a chai ☕</p>
|
| 205 |
+
</div>
|
| 206 |
+
|
| 207 |
+
{# Big animated status orb #}
|
| 208 |
+
<div class="flex justify-center py-4">
|
| 209 |
+
<div class="relative w-32 h-32 flex items-center justify-center">
|
| 210 |
+
<div class="absolute inset-0 rounded-full bg-indigo-500/10 animate-ping" style="animation-duration:2s;"></div>
|
| 211 |
+
<div class="absolute inset-2 rounded-full bg-indigo-500/15 animate-ping" style="animation-duration:2.5s; animation-delay:0.5s;"></div>
|
| 212 |
+
<div class="relative w-20 h-20 rounded-full bg-gradient-to-tr from-indigo-600 via-purple-600 to-pink-500 flex items-center justify-center shadow-[0_0_40px_rgba(99,102,241,0.6)]">
|
| 213 |
+
<span id="ingest-orb-icon" class="text-3xl">🧠</span>
|
| 214 |
+
</div>
|
| 215 |
+
</div>
|
| 216 |
+
</div>
|
| 217 |
+
|
| 218 |
+
{# Live log terminal #}
|
| 219 |
+
<div class="rounded-2xl bg-slate-950/70 border border-white/8 p-5 space-y-3 font-mono text-xs">
|
| 220 |
+
<div class="flex items-center space-x-2 pb-2 border-b border-white/5">
|
| 221 |
+
<div class="w-3 h-3 rounded-full bg-red-500/60"></div>
|
| 222 |
+
<div class="w-3 h-3 rounded-full bg-yellow-500/60"></div>
|
| 223 |
+
<div class="w-3 h-3 rounded-full bg-green-500/60"></div>
|
| 224 |
+
<span class="text-slate-600 ml-2">ingestion.log</span>
|
| 225 |
+
<span id="live-dot" class="ml-auto text-green-400 blink">●</span>
|
| 226 |
+
</div>
|
| 227 |
+
<div id="ingest-log" class="space-y-1 min-h-[80px] max-h-48 overflow-y-auto"></div>
|
| 228 |
+
</div>
|
| 229 |
+
|
| 230 |
+
{# Stats row #}
|
| 231 |
+
<div id="ingest-stats" class="hidden grid grid-cols-3 gap-4">
|
| 232 |
+
<div class="rounded-xl bg-slate-900/50 border border-white/5 p-4 text-center space-y-1">
|
| 233 |
+
<p class="text-slate-500 text-xs font-semibold uppercase tracking-wider">Files</p>
|
| 234 |
+
<p id="stat-files" class="text-2xl font-black text-white">—</p>
|
| 235 |
+
</div>
|
| 236 |
+
<div class="rounded-xl bg-slate-900/50 border border-white/5 p-4 text-center space-y-1">
|
| 237 |
+
<p class="text-slate-500 text-xs font-semibold uppercase tracking-wider">Docs</p>
|
| 238 |
+
<p id="stat-docs" class="text-2xl font-black text-indigo-400">—</p>
|
| 239 |
+
</div>
|
| 240 |
+
<div class="rounded-xl bg-slate-900/50 border border-white/5 p-4 text-center space-y-1">
|
| 241 |
+
<p class="text-slate-500 text-xs font-semibold uppercase tracking-wider">Status</p>
|
| 242 |
+
<p id="stat-status" class="text-2xl font-black text-yellow-400">⚙️</p>
|
| 243 |
+
</div>
|
| 244 |
+
</div>
|
| 245 |
+
|
| 246 |
+
{# Continue to chat #}
|
| 247 |
+
<button id="btn-go-chat"
|
| 248 |
+
class="hidden w-full inline-flex items-center justify-center px-6 py-4 rounded-xl bg-gradient-to-r from-green-600 to-emerald-600 hover:from-green-500 hover:to-emerald-500 text-white font-extrabold shadow-lg shadow-green-500/30 transition-all duration-300 text-lg"
|
| 249 |
+
>
|
| 250 |
+
🚀 Continue to Chat
|
| 251 |
+
</button>
|
| 252 |
+
|
| 253 |
+
</div>
|
| 254 |
+
</section>
|
| 255 |
+
|
| 256 |
+
{% endblock %}
|
| 257 |
+
|
| 258 |
+
|
| 259 |
+
{% block extra_scripts %}
|
| 260 |
+
<script>
|
| 261 |
+
/* ════════════════════════════════════════════════════════
|
| 262 |
+
CONSTANTS — injected by Jinja (never hard-code URLs here)
|
| 263 |
+
════════════════════════════════════════════════════════ */
|
| 264 |
+
const URLS = {
|
| 265 |
+
login : "{{ urls.login_base }}", /* /api/v1/user/login/{seconds} */
|
| 266 |
+
upload : "{{ urls.upload }}", /* /api/v1/upload */
|
| 267 |
+
ingest : "{{ urls.ingest }}", /* /api/v1/ingest */
|
| 268 |
+
chat : "{{ urls.chat_page }}" /* /chat */
|
| 269 |
+
};
|
| 270 |
+
|
| 271 |
+
/* ════════════════════════════════════════════════════════
|
| 272 |
+
STATE
|
| 273 |
+
════════════════════════════════════════════════════════ */
|
| 274 |
+
let selectedFiles = []; /* FileList → Array */
|
| 275 |
+
let sessionSeconds = 0;
|
| 276 |
+
let timerInterval = null;
|
| 277 |
+
|
| 278 |
+
/* ════════════════════════════════════════════════════════
|
| 279 |
+
HELPERS
|
| 280 |
+
════════════════════════════════════════════════════════ */
|
| 281 |
+
const $ = id => document.getElementById(id);
|
| 282 |
+
|
| 283 |
+
function showPhase(phase) {
|
| 284 |
+
["phase-login","phase-upload","phase-ingest"].forEach(p => {
|
| 285 |
+
$(p).classList.toggle("hidden", p !== phase);
|
| 286 |
+
});
|
| 287 |
+
}
|
| 288 |
+
|
| 289 |
+
function fmtBytes(b) {
|
| 290 |
+
if (b < 1024) return b + " B";
|
| 291 |
+
if (b < 1048576) return (b/1024).toFixed(1) + " KB";
|
| 292 |
+
return (b/1048576).toFixed(1) + " MB";
|
| 293 |
+
}
|
| 294 |
+
|
| 295 |
+
function fmtTime(s) {
|
| 296 |
+
const h = Math.floor(s/3600), m = Math.floor((s%3600)/60), sec = s%60;
|
| 297 |
+
if (h > 0) return `${h}:${String(m).padStart(2,"0")}:${String(sec).padStart(2,"0")}`;
|
| 298 |
+
return `${String(m).padStart(2,"0")}:${String(sec).padStart(2,"0")}`;
|
| 299 |
+
}
|
| 300 |
+
|
| 301 |
+
function appendLog(msg, color="text-slate-400") {
|
| 302 |
+
const log = $("ingest-log");
|
| 303 |
+
const line = document.createElement("div");
|
| 304 |
+
line.className = `log-line flex items-start space-x-2 ${color}`;
|
| 305 |
+
line.innerHTML = `<span class="text-slate-600 select-none">${new Date().toLocaleTimeString()}</span><span>${msg}</span>`;
|
| 306 |
+
log.appendChild(line);
|
| 307 |
+
log.scrollTop = log.scrollHeight;
|
| 308 |
+
}
|
| 309 |
+
|
| 310 |
+
/* ════════════════════════════════════════════════════════
|
| 311 |
+
GLOBAL TIMER (navbar badge)
|
| 312 |
+
════════════════════════════════════════════════════════ */
|
| 313 |
+
function startGlobalTimer(totalSeconds) {
|
| 314 |
+
sessionSeconds = totalSeconds;
|
| 315 |
+
let remaining = totalSeconds;
|
| 316 |
+
|
| 317 |
+
/* reveal the badge wrapper in the navbar */
|
| 318 |
+
const wrapper = document.getElementById("global-timer-wrapper");
|
| 319 |
+
if (wrapper) wrapper.classList.remove("hidden");
|
| 320 |
+
|
| 321 |
+
const badge = document.getElementById("global-timer-badge");
|
| 322 |
+
/* target just the text <span>, not the whole div (which contains an SVG) */
|
| 323 |
+
const badgeSpan = badge ? badge.querySelector("span") : null;
|
| 324 |
+
|
| 325 |
+
function tick() {
|
| 326 |
+
const txt = fmtTime(remaining);
|
| 327 |
+
if (badgeSpan) badgeSpan.textContent = txt;
|
| 328 |
+
if (remaining <= 60) {
|
| 329 |
+
badge.classList.remove("bg-indigo-500/20","text-indigo-400","border-indigo-500/30");
|
| 330 |
+
badge.classList.add("bg-red-500/20","text-red-400","border-red-500/40");
|
| 331 |
+
}
|
| 332 |
+
if (remaining <= 0) {
|
| 333 |
+
clearInterval(timerInterval);
|
| 334 |
+
if (badgeSpan) badgeSpan.textContent = "EXPIRED";
|
| 335 |
+
badge.classList.add("opacity-60");
|
| 336 |
+
}
|
| 337 |
+
remaining--;
|
| 338 |
+
}
|
| 339 |
+
tick();
|
| 340 |
+
timerInterval = setInterval(tick, 1000);
|
| 341 |
+
}
|
| 342 |
+
|
| 343 |
+
/* ════════════════════════════════════════════════════════
|
| 344 |
+
PHASE 1 — Login
|
| 345 |
+
════════════════════════════════════════════════════════ */
|
| 346 |
+
document.querySelectorAll(".time-btn").forEach(btn => {
|
| 347 |
+
btn.addEventListener("click", async () => {
|
| 348 |
+
const secs = parseInt(btn.dataset.seconds, 10);
|
| 349 |
+
|
| 350 |
+
/* dim all buttons, show spinner */
|
| 351 |
+
document.querySelectorAll(".time-btn").forEach(b => b.disabled = true);
|
| 352 |
+
$("login-status").classList.remove("hidden");
|
| 353 |
+
|
| 354 |
+
try {
|
| 355 |
+
const res = await fetch(`${URLS.login}/${secs}`, { method:"GET", credentials:"include" });
|
| 356 |
+
const data = await res.json();
|
| 357 |
+
|
| 358 |
+
if (!res.ok) throw new Error(data.error || "Login failed");
|
| 359 |
+
|
| 360 |
+
/* ✅ session started — persist for all pages via localStorage */
|
| 361 |
+
localStorage.setItem('multirag_session_start', Date.now().toString());
|
| 362 |
+
localStorage.setItem('multirag_session_duration', secs.toString());
|
| 363 |
+
|
| 364 |
+
/* kick the global navbar timer (already attached by base.html) */
|
| 365 |
+
if (window.__startNavTimer) window.__startNavTimer();
|
| 366 |
+
|
| 367 |
+
showPhase("phase-upload");
|
| 368 |
+
|
| 369 |
+
} catch(err) {
|
| 370 |
+
$("login-status").innerHTML = `<p class="text-red-400 text-sm font-semibold">❌ ${err.message}</p>`;
|
| 371 |
+
document.querySelectorAll(".time-btn").forEach(b => b.disabled = false);
|
| 372 |
+
}
|
| 373 |
+
});
|
| 374 |
+
});
|
| 375 |
+
|
| 376 |
+
/* ════════════════════════════════════════════════════════
|
| 377 |
+
PHASE 2 — File Upload
|
| 378 |
+
════════════════════════════════════════════════════════ */
|
| 379 |
+
const dropZone = $("drop-zone");
|
| 380 |
+
const fileInput = $("file-input");
|
| 381 |
+
|
| 382 |
+
/* Drag & Drop events */
|
| 383 |
+
["dragenter","dragover"].forEach(evt =>
|
| 384 |
+
dropZone.addEventListener(evt, e => { e.preventDefault(); dropZone.classList.add("drag-over"); })
|
| 385 |
+
);
|
| 386 |
+
["dragleave","drop"].forEach(evt =>
|
| 387 |
+
dropZone.addEventListener(evt, e => { e.preventDefault(); dropZone.classList.remove("drag-over"); })
|
| 388 |
+
);
|
| 389 |
+
dropZone.addEventListener("drop", e => addFiles(e.dataTransfer.files));
|
| 390 |
+
fileInput.addEventListener("change", () => addFiles(fileInput.files));
|
| 391 |
+
|
| 392 |
+
function addFiles(fileList) {
|
| 393 |
+
Array.from(fileList).forEach(f => {
|
| 394 |
+
if (!selectedFiles.find(s => s.name === f.name && s.size === f.size))
|
| 395 |
+
selectedFiles.push(f);
|
| 396 |
+
});
|
| 397 |
+
renderFileList();
|
| 398 |
+
}
|
| 399 |
+
|
| 400 |
+
function renderFileList() {
|
| 401 |
+
const chips = $("file-chips");
|
| 402 |
+
chips.innerHTML = "";
|
| 403 |
+
selectedFiles.forEach((f, i) => {
|
| 404 |
+
const chip = document.createElement("div");
|
| 405 |
+
chip.className = "file-chip flex items-center justify-between bg-slate-900/60 border border-white/8 rounded-xl px-4 py-2.5";
|
| 406 |
+
chip.innerHTML = `
|
| 407 |
+
<div class="flex items-center space-x-3 min-w-0">
|
| 408 |
+
<span class="text-lg shrink-0">${fileIcon(f.name)}</span>
|
| 409 |
+
<div class="min-w-0">
|
| 410 |
+
<p class="text-sm text-white font-semibold truncate max-w-[260px]">${f.name}</p>
|
| 411 |
+
<p class="text-xs text-slate-500">${fmtBytes(f.size)}</p>
|
| 412 |
+
</div>
|
| 413 |
+
</div>
|
| 414 |
+
<button class="ml-3 text-slate-600 hover:text-red-400 transition-colors shrink-0 text-lg" data-idx="${i}">×</button>`;
|
| 415 |
+
chip.querySelector("button").addEventListener("click", () => {
|
| 416 |
+
selectedFiles.splice(i, 1);
|
| 417 |
+
renderFileList();
|
| 418 |
+
});
|
| 419 |
+
chips.appendChild(chip);
|
| 420 |
+
});
|
| 421 |
+
|
| 422 |
+
const hasFiles = selectedFiles.length > 0;
|
| 423 |
+
$("file-list").classList.toggle("hidden", !hasFiles);
|
| 424 |
+
$("btn-clear").classList.toggle("hidden", !hasFiles);
|
| 425 |
+
$("btn-continue-upload").disabled = !hasFiles;
|
| 426 |
+
}
|
| 427 |
+
|
| 428 |
+
function fileIcon(name) {
|
| 429 |
+
const ext = name.split(".").pop().toLowerCase();
|
| 430 |
+
const map = { pdf:"📄", csv:"📊", xlsx:"📊", xls:"📊", png:"🖼️", jpg:"🖼️", jpeg:"🖼️", gif:"🖼️",
|
| 431 |
+
mp3:"🎵", wav:"🎵", mp4:"🎬", txt:"📝", json:"🗂️", zip:"📦", tar:"📦", gz:"📦" };
|
| 432 |
+
return map[ext] || "📎";
|
| 433 |
+
}
|
| 434 |
+
|
| 435 |
+
$("btn-clear").addEventListener("click", () => {
|
| 436 |
+
selectedFiles = [];
|
| 437 |
+
fileInput.value = "";
|
| 438 |
+
renderFileList();
|
| 439 |
+
});
|
| 440 |
+
|
| 441 |
+
/* Upload all files sequentially then trigger ingest */
|
| 442 |
+
$("btn-continue-upload").addEventListener("click", async () => {
|
| 443 |
+
if (!selectedFiles.length) return;
|
| 444 |
+
|
| 445 |
+
$("btn-continue-upload").disabled = true;
|
| 446 |
+
$("btn-clear").disabled = true;
|
| 447 |
+
$("file-input").disabled = true;
|
| 448 |
+
|
| 449 |
+
const wrapper = $("upload-progress-wrapper");
|
| 450 |
+
const bar = $("upload-progress-bar");
|
| 451 |
+
const pct = $("upload-progress-pct");
|
| 452 |
+
const label = $("upload-progress-label");
|
| 453 |
+
wrapper.classList.remove("hidden");
|
| 454 |
+
|
| 455 |
+
let done = 0;
|
| 456 |
+
let allOk = true;
|
| 457 |
+
|
| 458 |
+
for (const file of selectedFiles) {
|
| 459 |
+
label.textContent = `Uploading ${file.name}…`;
|
| 460 |
+
const fd = new FormData();
|
| 461 |
+
fd.append("file", file);
|
| 462 |
+
try {
|
| 463 |
+
const res = await fetch(URLS.upload, { method:"POST", body:fd, credentials:"include" });
|
| 464 |
+
if (!res.ok) { allOk = false; }
|
| 465 |
+
} catch { allOk = false; }
|
| 466 |
+
|
| 467 |
+
done++;
|
| 468 |
+
const p = Math.round((done / selectedFiles.length) * 100);
|
| 469 |
+
bar.style.width = p + "%";
|
| 470 |
+
pct.textContent = p + "%";
|
| 471 |
+
}
|
| 472 |
+
|
| 473 |
+
if (!allOk) {
|
| 474 |
+
label.textContent = "⚠️ Some files failed. Continuing anyway…";
|
| 475 |
+
label.classList.add("text-yellow-400");
|
| 476 |
+
} else {
|
| 477 |
+
label.textContent = "✅ All files uploaded!";
|
| 478 |
+
label.classList.add("text-green-400");
|
| 479 |
+
}
|
| 480 |
+
|
| 481 |
+
/* short pause so user can read the status */
|
| 482 |
+
await new Promise(r => setTimeout(r, 800));
|
| 483 |
+
|
| 484 |
+
/* → Move to ingestion phase */
|
| 485 |
+
showPhase("phase-ingest");
|
| 486 |
+
startIngestion();
|
| 487 |
+
});
|
| 488 |
+
|
| 489 |
+
/* ════════════════════════════════════════════════════════
|
| 490 |
+
PHASE 3 — Ingestion
|
| 491 |
+
════════════════════════════════════════════════════════ */
|
| 492 |
+
async function startIngestion() {
|
| 493 |
+
const FAKE_LOGS = [
|
| 494 |
+
["🔍 Scanning uploaded files…", "text-slate-300"],
|
| 495 |
+
["📦 Chunking documents into passages…", "text-slate-300"],
|
| 496 |
+
["🧬 Embedding with all-MiniLM-L6-v2…", "text-indigo-300"],
|
| 497 |
+
["🕸️ Building knowledge graph edges…", "text-purple-300"],
|
| 498 |
+
["🗄️ Persisting vector store to disk…", "text-slate-300"],
|
| 499 |
+
["⚡ Optimising HNSW index…", "text-yellow-300"],
|
| 500 |
+
];
|
| 501 |
+
|
| 502 |
+
$("ingest-log").innerHTML = "";
|
| 503 |
+
$("ingest-stats").classList.add("hidden");
|
| 504 |
+
$("btn-go-chat").classList.add("hidden");
|
| 505 |
+
$("ingest-title").textContent = "Data Ingestion Starting…";
|
| 506 |
+
|
| 507 |
+
/* drip fake progress logs while waiting for real response */
|
| 508 |
+
let logIdx = 0;
|
| 509 |
+
const dripInterval = setInterval(() => {
|
| 510 |
+
if (logIdx < FAKE_LOGS.length) {
|
| 511 |
+
const [msg, cls] = FAKE_LOGS[logIdx++];
|
| 512 |
+
appendLog(msg, cls);
|
| 513 |
+
}
|
| 514 |
+
}, 900);
|
| 515 |
+
|
| 516 |
+
try {
|
| 517 |
+
const res = await fetch(URLS.ingest, { method:"GET", credentials:"include" });
|
| 518 |
+
const data = await res.json();
|
| 519 |
+
|
| 520 |
+
clearInterval(dripInterval);
|
| 521 |
+
$("live-dot").classList.remove("blink");
|
| 522 |
+
|
| 523 |
+
if (!res.ok) {
|
| 524 |
+
appendLog(`❌ Error: ${data.error || "Ingestion failed"}`, "text-red-400");
|
| 525 |
+
$("ingest-title").textContent = "Ingestion Failed";
|
| 526 |
+
$("ingest-spinner").innerHTML = '<span class="text-red-400 text-xl">❌</span>';
|
| 527 |
+
return;
|
| 528 |
+
}
|
| 529 |
+
|
| 530 |
+
/* ✅ success */
|
| 531 |
+
appendLog("✅ Ingestion complete! Knowledge base is ready.", "text-green-400");
|
| 532 |
+
$("ingest-title").textContent = "Ingestion Complete!";
|
| 533 |
+
$("ingest-spinner").innerHTML = '<span class="text-green-400 text-xl">✓</span>';
|
| 534 |
+
$("ingest-orb-icon").textContent = "✅";
|
| 535 |
+
|
| 536 |
+
/* show stats */
|
| 537 |
+
$("ingest-stats").classList.remove("hidden");
|
| 538 |
+
$("stat-files").textContent = data.files_processed ?? "—";
|
| 539 |
+
$("stat-docs").textContent = Array.isArray(data.all_docs) ? data.all_docs.length : (data.all_docs ?? "—");
|
| 540 |
+
$("stat-status").textContent = "✅";
|
| 541 |
+
|
| 542 |
+
/* ── auto-redirect to chat with 3s countdown ── */
|
| 543 |
+
appendLog("🚀 Redirecting to Chat in 3 seconds…", "text-indigo-300");
|
| 544 |
+
const goBtn = $("btn-go-chat");
|
| 545 |
+
goBtn.classList.remove("hidden");
|
| 546 |
+
let countdown = 3;
|
| 547 |
+
goBtn.textContent = `🚀 Opening Chat in ${countdown}s — click to go now`;
|
| 548 |
+
const countTimer = setInterval(() => {
|
| 549 |
+
countdown--;
|
| 550 |
+
if (countdown <= 0) {
|
| 551 |
+
clearInterval(countTimer);
|
| 552 |
+
window.location.href = URLS.chat;
|
| 553 |
+
} else {
|
| 554 |
+
goBtn.textContent = `🚀 Opening Chat in ${countdown}s — click to go now`;
|
| 555 |
+
}
|
| 556 |
+
}, 1000);
|
| 557 |
+
goBtn.onclick = () => { clearInterval(countTimer); window.location.href = URLS.chat; };
|
| 558 |
+
|
| 559 |
+
} catch(err) {
|
| 560 |
+
clearInterval(dripInterval);
|
| 561 |
+
appendLog(`❌ Network error: ${err.message}`, "text-red-400");
|
| 562 |
+
$("ingest-title").textContent = "Ingestion Failed";
|
| 563 |
+
$("ingest-spinner").innerHTML = '<span class="text-red-400 text-xl">❌</span>';
|
| 564 |
+
}
|
| 565 |
+
}
|
| 566 |
+
|
| 567 |
+
/* btn-go-chat click is wired dynamically inside startIngestion() */
|
| 568 |
+
|
| 569 |
+
</script>
|
| 570 |
+
{% endblock %}
|
data/Optical_Recognition.png
ADDED
|
data/google.docx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7eee211e7bc83917dde195f15c5458d6877dce8ba9fe080479c26a58e8da4c6a
|
| 3 |
+
size 3020407
|
data/growing_ai_tools.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
THE LATEST GROWING AI MODELS (2024-2025)LARGE LANGUAGE MODELS (LLMs) & MULTIMODALGemini 1.5 Pro (Google): Known for its massive context window (up to 2 million tokens), allowing it to process entire libraries or long videos in one go.GPT-4o (OpenAI): An "omni" model designed for seamless real-time interaction across text, audio, and vision.Claude 3.5 Sonnet (Anthropic): Widely praised for its human-like reasoning, coding abilities, and "Artifacts" UI feature.Llama 3.1 (Meta): The leading open-source model series, providing high performance for developers to build private AI applications.DeepSeek-V3: An emerging powerhouse from China gaining traction for its efficiency and strong performance in logic and coding.VIDEO GENERATION MODELS (THE NEW FRONTIER)Sora (OpenAI): A world-simulating model that creates highly realistic 60-second videos.Veo (Google): Google's latest high-definition video generation model with cinematic control.Kling / Luma Dream Machine: Rapidly growing tools accessible to the public for generating high-quality AI video from text prompts.Runway Gen-3 Alpha: A professional-grade video model used by filmmakers and creators for precise motion control.IMAGE & CREATIVE MODELSMidjourney v6: Continues to lead in artistic quality and photorealism.Flux.1 (Black Forest Labs): A new open-weights model that has quickly become a favorite for its incredible detail and ability to render text inside images.DALL-E 3: Integrated into ChatGPT and Bing, focused on strict adherence to complex user prompts.SPECIALIZED & RESEARCH MODELSAlphaFold 3 (Google DeepMind): A revolutionary model for biology that predicts the structure and interactions of all life’s molecules.Grok-2 (xAI): Elon Musk’s AI model integrated into X (Twitter), designed for real-time information access and "edgy" personality.Trends to Watch:Small Language Models (SLMs): Models like Phi-3 or Gemma designed to run locally on phones and laptops.Agentic AI: Models designed not just to talk, but to use tools and complete multi-step tasks autonomously.
|
exception/__init__.py
CHANGED
|
@@ -9,7 +9,4 @@ class MyException(Exception):
|
|
| 9 |
|
| 10 |
logging.exception(error_message)
|
| 11 |
def __str__(self) -> str:
|
| 12 |
-
|
| 13 |
-
Returns the string representation of the error message.
|
| 14 |
-
"""
|
| 15 |
-
return self.args[0]
|
|
|
|
| 9 |
|
| 10 |
logging.exception(error_message)
|
| 11 |
def __str__(self) -> str:
|
| 12 |
+
return str(self.args[0])
|
|
|
|
|
|
|
|
|
graph_visualization.png
ADDED
|
logger/__init__.py
CHANGED
|
@@ -2,7 +2,7 @@ import logging
|
|
| 2 |
import os
|
| 3 |
from logging.handlers import RotatingFileHandler
|
| 4 |
from datetime import datetime
|
| 5 |
-
from constants import LOGS_DIR
|
| 6 |
|
| 7 |
# Log File Configuration
|
| 8 |
LOG_FILE = f"{datetime.now().strftime('%m_%d_%Y_%H_%M_%S')}.log"
|
|
|
|
| 2 |
import os
|
| 3 |
from logging.handlers import RotatingFileHandler
|
| 4 |
from datetime import datetime
|
| 5 |
+
from src.constants import LOGS_DIR
|
| 6 |
|
| 7 |
# Log File Configuration
|
| 8 |
LOG_FILE = f"{datetime.now().strftime('%m_%d_%Y_%H_%M_%S')}.log"
|
main.py
CHANGED
|
@@ -1,25 +1,8 @@
|
|
| 1 |
from dotenv import load_dotenv
|
| 2 |
-
load_dotenv() #
|
| 3 |
|
| 4 |
-
import
|
| 5 |
from api.main import app
|
| 6 |
-
from logger import *
|
| 7 |
-
from fastapi.staticfiles import StaticFiles
|
| 8 |
-
from src.MultiRag.constants import DATA_FOLDER_PATH, DB_FOLDER_PATH
|
| 9 |
-
import os
|
| 10 |
-
app.mount("/static", StaticFiles(directory="static"), name="static")
|
| 11 |
-
os.makedirs("images", exist_ok=True)
|
| 12 |
-
app.mount("/blog/images", StaticFiles(directory="images"), name="blog_images")
|
| 13 |
-
# app.mount("/images", StaticFiles(directory="images"), name="blog_images")
|
| 14 |
|
| 15 |
-
os.makedirs(DATA_FOLDER_PATH, exist_ok=True)
|
| 16 |
-
os.makedirs(DB_FOLDER_PATH, exist_ok=True)
|
| 17 |
|
| 18 |
-
|
| 19 |
-
uv.run(
|
| 20 |
-
"main:app",
|
| 21 |
-
host="0.0.0.0",
|
| 22 |
-
port=7860,
|
| 23 |
-
reload=False,
|
| 24 |
-
reload_excludes=["db/*", "data/*", "logs/*", "vector_db/*", ".venv/*"],
|
| 25 |
-
)
|
|
|
|
| 1 |
from dotenv import load_dotenv
|
| 2 |
+
load_dotenv() #
|
| 3 |
|
| 4 |
+
import logger
|
| 5 |
from api.main import app
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
notebook/convert_to_pdf.ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
pyproject.toml
CHANGED
|
@@ -34,8 +34,17 @@ dependencies = [
|
|
| 34 |
"rank-bm25>=0.2.2",
|
| 35 |
"sentence-transformers>=5.2.3",
|
| 36 |
"transformers>=5.3.0",
|
| 37 |
-
"unstructured>=0.21.5",
|
| 38 |
"unstructured-inference>=1.6.11",
|
| 39 |
"unstructured-pytesseract>=0.3.15",
|
| 40 |
"youtube-transcript-api>=1.2.4",
|
|
|
|
|
|
|
| 41 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
"rank-bm25>=0.2.2",
|
| 35 |
"sentence-transformers>=5.2.3",
|
| 36 |
"transformers>=5.3.0",
|
| 37 |
+
"unstructured[all-docs]>=0.21.5",
|
| 38 |
"unstructured-inference>=1.6.11",
|
| 39 |
"unstructured-pytesseract>=0.3.15",
|
| 40 |
"youtube-transcript-api>=1.2.4",
|
| 41 |
+
"docx2pdf>=0.1.8",
|
| 42 |
+
"fpdf>=1.7.2",
|
| 43 |
]
|
| 44 |
+
|
| 45 |
+
[tool.pytest.ini_options]
|
| 46 |
+
testpaths = ["src/tests"]
|
| 47 |
+
python_files = ["*_pytest.py", "test_*.py"]
|
| 48 |
+
python_classes = ["Test*"]
|
| 49 |
+
python_functions = ["test_*"]
|
| 50 |
+
addopts = "-s -v"
|
references/Screenshot from 2026-05-19 09-16-20.png
ADDED
|
Git LFS Details
|
references/Screenshot from 2026-05-19 09-22-23.png
ADDED
|
Git LFS Details
|
references/Screenshot from 2026-05-21 12-05-26.png
ADDED
|
Git LFS Details
|
references/Screenshot from 2026-05-21 12-26-14.png
ADDED
|
references/Screenshot from 2026-05-29 16-20-02.png
ADDED
|
Git LFS Details
|
src/__init__.py
ADDED
|
File without changes
|
src/components/__init__.py
ADDED
|
File without changes
|
src/components/data_ingestion.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
from src.utils.asyncHandler import asyncHandler
|
| 3 |
+
import logging
|
| 4 |
+
from src.entity.config_entity import DataIngestionConfig
|
| 5 |
+
from src.utils.ingestion_utils import text_to_pdf,image_to_pdf,docs_to_pdf
|
| 6 |
+
from src.entity.artifact_entity import DataIngestionArtifact
|
| 7 |
+
import shutil
|
| 8 |
+
import os
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class DataIngestion:
|
| 12 |
+
def __init__(self,data_ingestion_config:DataIngestionConfig):
|
| 13 |
+
self.data_ingestion_config=data_ingestion_config
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
@asyncHandler
|
| 17 |
+
async def ingest_data(self)->DataIngestionArtifact:
|
| 18 |
+
logging.info(f"Ensuring directory exists for: {self.data_ingestion_config.save_file_path}")
|
| 19 |
+
os.makedirs(os.path.dirname(self.data_ingestion_config.save_file_path), exist_ok=True)
|
| 20 |
+
|
| 21 |
+
match (self.data_ingestion_config.input_file_path.split(".")[-1]):
|
| 22 |
+
|
| 23 |
+
case "docx":
|
| 24 |
+
await docs_to_pdf(docs_path=self.data_ingestion_config.input_file_path,output_pdf_path=self.data_ingestion_config.save_file_path)
|
| 25 |
+
|
| 26 |
+
case "txt":
|
| 27 |
+
await text_to_pdf(file_path=self.data_ingestion_config.input_file_path,output_file_path=self.data_ingestion_config.save_file_path)
|
| 28 |
+
|
| 29 |
+
case "png":
|
| 30 |
+
await image_to_pdf(imge_path=self.data_ingestion_config.input_file_path,output_pdf_path=self.data_ingestion_config.save_file_path)
|
| 31 |
+
case "jpg":
|
| 32 |
+
await image_to_pdf(imge_path=self.data_ingestion_config.input_file_path,output_pdf_path=self.data_ingestion_config.save_file_path)
|
| 33 |
+
case "webp":
|
| 34 |
+
await image_to_pdf(imge_path=self.data_ingestion_config.input_file_path,output_pdf_path=self.data_ingestion_config.save_file_path)
|
| 35 |
+
|
| 36 |
+
case "pdf":
|
| 37 |
+
shutil.copy(src=self.data_ingestion_config.input_file_path, dst=self.data_ingestion_config.save_file_path)
|
| 38 |
+
|
| 39 |
+
return DataIngestionArtifact(ingested_file_path=self.data_ingestion_config.save_file_path)
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
|
src/components/data_transformation.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from src.utils.asyncHandler import asyncHandler
|
| 2 |
+
import logging
|
| 3 |
+
from src.entity.config_entity import DataTransformationConfig, RetreiverConfig
|
| 4 |
+
from src.entity.artifact_entity import DataTransformationArtifact, DataIngestionArtifact
|
| 5 |
+
from src.retrievers.create_retreivers import Retreiver
|
| 6 |
+
|
| 7 |
+
class DataTransformation:
|
| 8 |
+
def __init__(self, data_transformation_config: DataTransformationConfig, data_ingestion_artifact: DataIngestionArtifact):
|
| 9 |
+
self.data_ingestion_artifact = data_ingestion_artifact
|
| 10 |
+
self.data_transformation_config = data_transformation_config
|
| 11 |
+
|
| 12 |
+
retreiver_config = RetreiverConfig(
|
| 13 |
+
vector_store_path=self.data_transformation_config.vector_store_path
|
| 14 |
+
)
|
| 15 |
+
self.retreiver = Retreiver(retreiver_config=retreiver_config)
|
| 16 |
+
|
| 17 |
+
@asyncHandler
|
| 18 |
+
async def initiate_data_transformation(self) -> DataTransformationArtifact:
|
| 19 |
+
logging.info("Initiating data transformation...")
|
| 20 |
+
|
| 21 |
+
elements = await self.retreiver.partition_document(
|
| 22 |
+
self.data_ingestion_artifact.ingested_file_path
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
chunks = await self.retreiver.create_chunks_by_title(elements)
|
| 26 |
+
|
| 27 |
+
documents = await self.retreiver.get_documents(
|
| 28 |
+
chunks,
|
| 29 |
+
ingested_file_path=self.data_ingestion_artifact.ingested_file_path
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
vector_store_path = await self.retreiver.save_to_vector_store(documents)
|
| 33 |
+
|
| 34 |
+
logging.info("Data transformation completed successfully.")
|
| 35 |
+
return DataTransformationArtifact(vector_store_path=vector_store_path)
|
src/components/run_graph.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from src.graphs.builder import graph
|
| 2 |
+
from src.utils.asyncHandler import asyncHandler
|
| 3 |
+
import logging
|
| 4 |
+
|
| 5 |
+
class RunGraph:
|
| 6 |
+
def __init__(self):
|
| 7 |
+
pass
|
| 8 |
+
|
| 9 |
+
@asyncHandler
|
| 10 |
+
async def run(self, state: dict, config: dict = None) -> dict:
|
| 11 |
+
logging.info("Starting RunGraph component execution...")
|
| 12 |
+
if config is None:
|
| 13 |
+
config = {"configurable": {"thread_id": "default_thread"}}
|
| 14 |
+
result = await graph.ainvoke(state, config=config)
|
| 15 |
+
logging.info("RunGraph component execution completed.")
|
| 16 |
+
return result
|
src/constants/__init__.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
INGESTION_FOLDER_NAME = "ingestion"
|
| 2 |
+
TRANSFORMATION_FOLDER_NAME="transformation"
|
| 3 |
+
EMBEDDING_MODEL = "sentence-transformers/all-MiniLM-L6-v2"
|
| 4 |
+
LLM_MODEL_ID = "us.meta.llama3-3-70b-instruct-v1:0"
|
| 5 |
+
LLM_REGION = "us-east-1"
|
| 6 |
+
MODEL_NAME = "llama-3.3-70b-versatile"
|
| 7 |
+
LOGS_DIR = "logs"
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
# ======================= Api ====================
|
| 11 |
+
PUBLIC_FOLDER_FILE_PATH:str="public"
|
| 12 |
+
ARTIFACT_DIR = "artifacts"
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
# ======================= Web Search Constants ====================
|
| 16 |
+
SEARCH_MAX_RESULT, SEARCH_TOPIC = 5, "general"
|
| 17 |
+
|
| 18 |
+
|
src/entity/artifact_entity.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from dataclasses import dataclass
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
@dataclass
|
| 5 |
+
class RetrievalArtifact:
|
| 6 |
+
retreivar: object
|
| 7 |
+
|
| 8 |
+
@dataclass
|
| 9 |
+
class DataIngestionArtifact:
|
| 10 |
+
ingested_file_path:str
|
| 11 |
+
|
| 12 |
+
@dataclass
|
| 13 |
+
class DataTransformationArtifact:
|
| 14 |
+
vector_store_path: str
|
| 15 |
+
|
| 16 |
+
@dataclass
|
| 17 |
+
class ContentEmbedderArtifact:
|
| 18 |
+
data_ingestion_artifacts: list[DataIngestionArtifact]
|
| 19 |
+
|
| 20 |
+
@dataclass
|
| 21 |
+
class ContentTransformedArtifact:
|
| 22 |
+
data_transformation_artifacts: list[DataTransformationArtifact]
|
| 23 |
+
|