How aparimeyatiwari/yc_lawgic works
Project Type and Purpose
• LAWGIC is a full-stack AI-powered legal assistant targeted at the Indian legal ecosystem.
• It provides multimodal input (text, PDF, images, future speech), language translation, semantic retrieval of legal documents, LLM-based reasoning, and nearby lawyer lookup.
• Built as a modular Python application with a Chainlit UI frontend and Semantic Kernel-driven plugins for distinct tasks.
File Structure
Top-Level Files and Folders:
• README.md, requirement.txt, prompt.txt, chainlit.md – documentation and prompts.
• final.py (or main.py invoked by Chainlit) – application entrypoint.
• public/ – static assets for the Chainlit UI.
• SpeechModules/ – speech-to-text (stt.py) and text-to-speech (tts.py) modules (planned features).
• plugins/ – Semantic Kernel plugins organized by domain:
– LegalAgents/** – subfolders for tasks (document_analyzer, summarizer, query_classifier, etc.), each with config.json and skprompt.txt.
– LocationAgent/** – plugins for location_extractor and city_validator.
• __pycache__/ – compiled Python bytecode.
Configuration & Environment:
• requirement.txt – Python dependencies.
• .gitignore, .DS_Store – project housekeeping.
Extract Insights from the README
• Architecture Overview: shows a pipeline of input → translation → embedding → semantic search → LLM → translation → UI.
• Software Stack: Chainlit (frontend), Python & Semantic Kernel (backend), Azure OpenAI (embeddings & LLM), Azure Computer Vision, Azure Translator, Azure Blob & AI Search, Google Maps API.
• Plugins are orchestrated by Semantic Kernel to handle distinct functions (Translator, Lawyer AI, Nearby Lawyers).
Main Components and Their Interactions
A. User Interface (Chainlit UI)
– Receives user queries or document uploads (text, PDF, images).
– Displays multilingual results and “Nearby Lawyer” map.
B. Input Preprocessing
– SpeechModules (optional): STT module converts voice to text; TTS for responses.
– Azure Computer Vision OCR extracts text from images/PDF.
C. Translator Plugin
– Detects input language via Azure Translator.
– Converts input to English for internal processing.
D. Semantic Retrieval & Reasoning
– Embedding step: translates query to vector using Azure OpenAI Embeddings.
– Search step: queries Azure AI Search index of legal docs stored in Azure Blob Storage.
– Planner + Lawyer AI Plugin: feeds top-k retrieval to Azure LLM for grounded legal reasoning.
E. Location Plugin
– LocationExtractor and CityValidator determine user’s geolocation (IP, geocode, manual).
– Google Maps API fetches nearby lawyers.
F. Output Postprocessing
– Translates LLM result back into original language.
– Formats response with references and displays via Chainlit.
G. Configuration & Orchestration
– Semantic Kernel wires together plugins (config.json + skprompt.txt) under a Planner component.
– Environment variables hold all API keys/endpoints.
Architectural Patterns and Design Principles
• Modular Plugin Architecture: each capability is encapsulated as a Semantic Kernel plugin, enabling easy addition/removal of features.
• Separation of Concerns: distinct layers for UI, preprocessing, translation, retrieval, reasoning, and postprocessing.
• Human-in-the-Loop: optional handoff to verified lawyers for high-impact scenarios.
• Responsible AI: transparency (grounded references), multilingual fairness, traceability.