ali4568 commited on
Commit
36c7049
Β·
verified Β·
1 Parent(s): 6607e80

πŸš€ Auto-deploy from GitHub Action

Browse files
Files changed (1) hide show
  1. README.md +156 -1
README.md CHANGED
@@ -7,4 +7,159 @@ sdk: docker
7
  pinned: false
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  pinned: false
8
  ---
9
 
10
+ # βš–οΈ LawMadad-Model
11
+
12
+ LawMadad is a specialized AI-powered Pakistani Legal Assistant designed to provide structured, accurate, and context-aware guidance based on the Pakistani legal framework. Built using FastAPI and LlamaIndex, it leverages RAG (Retrieval-Augmented Generation) to query a comprehensive database of Pakistani laws, including civil, criminal, family, and constitutional codes.
13
+
14
+ ## πŸš€ Features
15
+
16
+ - **Legal RAG Pipeline**: Efficiently retrieves relevant legal clauses from a large corpus of PDF documents.
17
+ - **Intelligent Query Classification**: Automatically distinguishes between general greetings, capability inquiries, and complex legal queries.
18
+ - **Structured Legal Responses**: Provides detailed analysis including Introduction, Section Descriptions, Legal Provisions, Punishments, Precedents, and Recommendations.
19
+ - **Groq Acceleration**: Powered by Llama 3.1 8B on Groq for lightning-fast inference.
20
+ - **Confidence Scoring**: Internally calculates similarity scores to ensure high-quality information retrieval.
21
+
22
+ ## πŸ›  Tech Stack
23
+
24
+ - **Framework**: [FastAPI](https://fastapi.tiangolo.com/)
25
+ - **LLM**: [Groq](https://groq.com/) (Llama 3.1 8B Instant)
26
+ - **Engine**: [LlamaIndex](https://www.llamaindex.ai/)
27
+ - **Embeddings**: HuggingFace (`sentence-transformers/all-MiniLM-L6-v2`)
28
+ - **Containerization**: [Docker](https://www.docker.com/)
29
+
30
+ ---
31
+
32
+ ## πŸ“₯ Getting Started
33
+
34
+ ### Prerequisites
35
+
36
+ - Python 3.9 or higher
37
+ - [Groq API Key](https://console.groq.com/)
38
+ - Docker (optional, for containerized deployment)
39
+
40
+ ### Installation
41
+
42
+ 1. **Clone the repository**:
43
+ ```bash
44
+ git clone <repository-url>
45
+ cd LawMadad-Model
46
+ ```
47
+
48
+ 2. **Create a virtual environment**:
49
+ ```bash
50
+ python -m venv venv
51
+ source venv/bin/activate # On Windows: venv\Scripts\activate
52
+ ```
53
+
54
+ 3. **Install dependencies**:
55
+ ```bash
56
+ pip install -r requirements.txt
57
+ ```
58
+
59
+ ### Configuration
60
+
61
+ Create a `.env` file in the root directory and add your Groq API key:
62
+
63
+ ```env
64
+ GROQ_API_KEY=your_groq_api_key_here
65
+ ```
66
+
67
+ ---
68
+
69
+ ## πŸƒ Running the Application
70
+
71
+ ### Locally
72
+
73
+ Start the FastAPI server using Uvicorn:
74
+
75
+ ```bash
76
+ python app.py
77
+ ```
78
+ Or:
79
+ ```bash
80
+ uvicorn app:app --host 0.0.0.0 --port 7860
81
+ ```
82
+
83
+ The API will be available at `http://localhost:7860`.
84
+
85
+ ### With Docker
86
+
87
+ 1. **Build the image**:
88
+ ```bash
89
+ docker build -t lawmadad-model .
90
+ ```
91
+
92
+ 2. **Run the container**:
93
+ ```bash
94
+ docker run -p 7860:7860 --env GROQ_API_KEY=your_groq_api_key_here lawmadad-model
95
+ ```
96
+
97
+ ---
98
+
99
+ ## πŸ“‘ API Documentation
100
+
101
+ ### Root Endpoint
102
+ - **URL**: `/`
103
+ - **Method**: `GET`
104
+ - **Description**: Returns a simple welcome message and usage instructions.
105
+
106
+ ### Query Endpoint
107
+ - **URL**: `/query/`
108
+ - **Method**: `POST`
109
+ - **Request Body**:
110
+ ```json
111
+ {
112
+ "query": "What is the punishment for theft under the Pakistan Penal Code?"
113
+ }
114
+ ```
115
+ - **Response**:
116
+ ```json
117
+ {
118
+ "response": "1. **Introduction/Overview**: Theft is defined under Section 378 of the PPC...\n..."
119
+ }
120
+ ```
121
+
122
+ ---
123
+
124
+ ## πŸ“ Project Structure
125
+
126
+ ```text
127
+ .
128
+ β”œβ”€β”€ app.py # Main FastAPI application & RAG logic
129
+ β”œβ”€β”€ Dockerfile # Containerization for HF Spaces
130
+ β”œβ”€β”€ requirements.txt # Python dependencies
131
+ β”œβ”€β”€ storage_law_app/ # Persisted LlamaIndex vector store
132
+ β”œβ”€β”€ .github/workflows/ # CI/CD for Hugging Face deployment
133
+ └── *.pdf # Pakistani legal corpus (Data source)
134
+ ```
135
+
136
+ ---
137
+
138
+ ## πŸš€ Deployment
139
+
140
+ The project is configured for automated deployment to **Hugging Face Spaces**.
141
+
142
+ ### GitHub Actions
143
+ - **Deploy**: On every push to the `master` branch, the `deploy.yml` workflow pushes the code to the [ali4568/LawMadad](https://huggingface.co/spaces/ali4568/LawMadad) Space.
144
+ - **Sync Env**: The `sync_env_to_huggingface.yml` workflow ensures environment variables like `GROQ_API_KEY` are synchronized.
145
+
146
+ ---
147
+
148
+ ## πŸ“š Data Corpus
149
+
150
+ The model is powered by a comprehensive set of legal documents, including:
151
+ - Constitution of Pakistan
152
+ - Pakistan Penal Code (PPC)
153
+ - Civil Procedure Code (CPC)
154
+ - Family Law Ordinance
155
+ - Property & West Family Laws
156
+ - And various other specialized legal drafts.
157
+
158
+ ---
159
+
160
+ ## πŸ“„ License
161
+
162
+ This project is licensed under the MIT License - see the LICENSE file for details.
163
+
164
+ ---
165
+ *Note: This application is intended for educational and informational purposes. Always consult with a qualified legal professional for actual legal advice.*