--- title: GenAI Hackathon emoji: ๐Ÿ”ฅ colorFrom: indigo colorTo: green sdk: gradio sdk_version: 6.19.0 python_version: '3.13' app_file: app.py pinned: false --- # ๐Ÿ‘๏ธ HybridSight > A multimodal AI assistant that combines Retrieval-Augmented Generation (RAG), Web Search, and Vision into a single application through a custom reasoning agent. HybridSight is a lightweight GenAI application capable of answering questions from uploaded documents, uploaded images, and the web. Instead of relying on a fixed pipeline, it uses a custom-built reasoning agent that dynamically decides which tool(s) should be used for every query while exposing its reasoning process to the user. --- ## โœจ Features ### ๐Ÿ’ฌ Hybrid Chat - Free-form conversational interface - Dynamic tool selection using a custom reasoning agent - Supports document retrieval, web search, and image understanding - Multi-tool reasoning for complex queries - Collapsible reasoning trace for every response ### ๐Ÿ“„ Document QA - PDF upload and indexing into ChromaDB - Semantic retrieval using sentence embeddings - Multi-turn document conversations - Streaming responses - Source-aware answers ### ๐Ÿ–ผ๏ธ Image Studio - Image upload with adjustable resolution - Vision-based question answering - Image metadata preview - Token-aware image preprocessing - Automatic validation before sending images to the Vision model --- # ๐Ÿ—๏ธ Architecture ``` User โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚ โ–ผ โ–ผ โ–ผ Hybrid Chat Document QA Image Studio โ”‚ โ”‚ โ”‚ โ–ผ โ–ผ โ–ผ Custom Agent RAG Engine Vision Pipeline โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ search_documents โ”€โ”€โ”€โ”ค โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ web_search โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ describe_image โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ–ผ Groq API ``` --- # โš™๏ธ Technology Stack | Component | Technology | |------------|------------| | LLM | Llama 3.3 70B (Groq) | | Vision Model | Llama 4 Scout Vision | | Framework | Gradio | | Retrieval | LangChain | | Vector Database | ChromaDB | | Embeddings | all-MiniLM-L6-v2 | | Search | DuckDuckGo Search | | Image Processing | Pillow | --- # ๐Ÿ“‚ Project Structure ``` HybridSight โ”‚ โ”œโ”€โ”€ app.py โ”œโ”€โ”€ agent.py โ”œโ”€โ”€ tools.py โ”œโ”€โ”€ rag.py โ”œโ”€โ”€ retrival.py โ”œโ”€โ”€ indexing.py โ”œโ”€โ”€ vision.py โ”œโ”€โ”€ safety.py โ”œโ”€โ”€ requirements.txt โ”œโ”€โ”€ README.md โ””โ”€โ”€ .gitignore ``` --- # ๐Ÿš€ Running Locally Clone the repository ```bash git clone ``` Install dependencies ```bash pip install -r requirements.txt ``` Create a `.env` file ``` GROQ_API_KEY=YOUR_API_KEY ``` Run the application ```bash python app.py ``` --- # ๐Ÿงช Tested Scenarios โœ… Pure document questions โœ… Pure web-search questions โœ… Pure image questions โœ… Image + document reasoning โœ… Graceful handling of API failures โœ… Missing document handling โœ… Missing image handling โœ… Session-specific document retrieval --- # ๐Ÿ’ก Engineering Decisions ## Custom Reasoning Agent Instead of relying on a fixed workflow, HybridSight implements its own reasoning loop. The agent repeatedly: ``` Question โ”‚ Planner โ”‚ Tool โ”‚ Observation โ”‚ Planner โ”‚ Final Answer ``` This provides full control over: - tool routing - stopping conditions - reasoning traces - memory - runtime behaviour - tool-specific execution It also makes it straightforward to add new tools without changing the overall architecture. --- ## Runtime Image Placeholder A common challenge with multimodal agents is handling image data efficiently. Instead of sending the complete Base64 image to the planner model, the planner reasons only with a lightweight placeholder: ``` CURRENT_IMAGE ``` During execution, the runtime replaces this placeholder with the actual image before invoking the vision tool. ``` Planner โ”‚ CURRENT_IMAGE โ”‚ Runtime โ”‚ Vision Tool ``` This approach: - reduces prompt size - lowers token usage - avoids unnecessary serialization - keeps reasoning independent of image size - prevents duplicate image processing --- ## Token-Aware Vision Pipeline The resolution slider is not merely a UI feature. Large images generate significantly larger Base64 payloads, increasing latency, token consumption, and the likelihood of request failures. Before an image reaches the Vision model, HybridSight performs: ``` Upload โ”‚ Resize โ”‚ JPEG Compression โ”‚ Token Estimation โ”‚ Metadata Generation โ”‚ Validation โ”‚ Vision Model ``` Only images that satisfy the configured token threshold are analyzed. This protects the application from oversized requests while improving responsiveness. --- ## Dedicated Document QA Hybrid Chat and Document QA serve different purposes. Hybrid Chat focuses on open-ended multimodal reasoning. ``` Question โ”‚ Agent โ”‚ Multiple Tools โ”‚ Answer ``` Document QA is optimized specifically for retrieval. ``` PDF โ”‚ Embedding โ”‚ ChromaDB โ”‚ Retriever โ”‚ LLM ``` Separating these workflows keeps document conversations faster, source-grounded, and free from unnecessary planner overhead. --- ## Session Isolation Each user receives an independent ChromaDB collection. ``` collection_name = session_id ``` This ensures uploaded documents remain isolated between users and prevents retrieval across sessions. --- ## Reasoning Trace Every tool invocation is recorded and displayed. For each reasoning step, the application exposes: - selected tool - tool input - tool output This makes the decision-making process transparent and simplifies debugging. --- ## Unified Safety Layer External dependencies are wrapped with a unified safety decorator. Instead of terminating the application, common failures are handled gracefully, including: - rate limits - invalid API keys - network errors - JSON parsing failures - timeout errors - missing files - invalid tool requests This keeps the UI responsive even when external services fail. --- ## Progressive Document Indexing Document indexing provides real-time progress updates. ``` Loading PDF โ†“ Splitting โ†“ Preparing Metadata โ†“ Generating Embeddings โ†“ Writing ChromaDB โ†“ Completed ``` This improves user feedback, especially for larger documents. --- # ๐Ÿ”ฎ Future Improvements - Multi-document collections - OCR support for scanned PDFs - Citation highlighting - Streaming reasoning traces - Persistent cloud memory - Additional knowledge tools (Wikipedia, ArXiv, etc.) - Parallel tool execution ---