File size: 3,284 Bytes
b835d72
 
 
 
 
 
 
 
 
 
 
3712c2c
b4a727a
b835d72
 
c7f0c06
b4a727a
c7f0c06
b4a727a
3712c2c
b4a727a
3712c2c
ce68191
3712c2c
ce68191
3712c2c
 
 
 
b333cdd
 
c7f0c06
b4a727a
3712c2c
b4a727a
3712c2c
b4a727a
3712c2c
b4a727a
ce68191
3712c2c
 
b4a727a
 
3712c2c
ce68191
b333cdd
ce68191
 
 
 
 
b4a727a
b333cdd
b4a727a
ce68191
b4a727a
b333cdd
 
b4a727a
 
b333cdd
b4a727a
c7f0c06
 
 
 
 
 
 
ce68191
3712c2c
b333cdd
3712c2c
ce68191
 
b4a727a
3712c2c
b4a727a
ce68191
b4a727a
 
 
3712c2c
b4a727a
ce68191
b4a727a
3712c2c
b4a727a
 
3712c2c
 
 
b333cdd
3712c2c
b333cdd
c7f0c06
b333cdd
3712c2c
 
b333cdd
3712c2c
 
 
b333cdd
3712c2c
 
b333cdd
 
3712c2c
b333cdd
 
3712c2c
 
 
 
b333cdd
3712c2c
 
 
b4a727a
 
ce68191
b4a727a
3712c2c
b4a727a
b333cdd
ce68191
3712c2c
 
 
b4a727a
b333cdd
 
 
 
 
 
 
b4a727a
b333cdd
 
 
 
 
 
 
 
 
ce68191
 
b4a727a
3712c2c
b4a727a
3712c2c
b4a727a
ce68191
 
3712c2c
b4a727a
ce68191
 
1
2
3
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
---
title: LexAI
emoji: ⚖️
colorFrom: purple
colorTo: red
sdk: gradio
sdk_version: 5.34.0
app_file: lexai/__main__.py
pinned: true
---

# LexAI

[![Hugging Face Space](https://img.shields.io/badge/🤗%20HuggingFace-LexAI-blueviolet?logo=huggingface)](https://huggingface.co/spaces/alexulanch/lexai)

## AI-Powered Legal Research Assistant

LexAI is an AI-powered legal research assistant that helps users access location-specific legal information through a simple web interface. By combining large language models with structured jurisdictional data, LexAI delivers clear, tailored answers to everyday legal questions.

![LexAI Screenshot](assets/screenshot.png)

---

## Features

- **GPT-4 Integration**: Uses OpenAI's GPT-4 to generate concise, relevant legal responses.
- **Jurisdiction-Specific Search**: Preloaded embeddings for Boulder County and Denver, Colorado.
- **Semantic Search Engine**: Uses cosine similarity for embedding-based document retrieval.
- **Modern Web Interface**: Built with Gradio for real-time interaction.
- **Modular Design**: Clean separation of logic for UI, inference, and API handling.
- **Fully Tested**: Unit tests cover embedding loading, matching logic, and OpenAI API integration.
- **Developer Friendly**: Includes dev tools like Ruff, Black, pytest, mypy, and coverage reports.

---

## Getting Started

### 1. Clone the Repository

```bash
git clone https://github.com/alexulanch/lexai.git
cd lexai
```

### 2. Install Git LFS (if needed)

This project uses [Git LFS](https://git-lfs.github.com/) to manage large files such as `.npz` embedding data.

```bash
git lfs install
git lfs pull
```

### 3. Install Dependencies

```bash
pip install -r requirements.txt
# For development tools:
pip install -r dev-requirements.txt
```

### 4. Set Up Environment

Copy the template and add your API key:

```bash
cp .env.example .env
```

Then edit `.env` and set:

```dotenv
OPENAI_API_KEY=your_openai_api_key
```

---

## Running the App

```bash
python -m lexai
```

Then open `http://127.0.0.1:7860` in your browser.

---

## Project Structure

```
.
├── LICENSE
├── README.md
├── assets/
│   └── screenshot.png
├── dev-requirements.txt
├── .env.example
├── lexai/
│   ├── __main__.py
│   ├── config.py
│   ├── core/
│   │   ├── data_loader.py
│   │   ├── match_engine.py
│   │   └── matcher.py
│   ├── data/
│   │   ├── boulder_embeddings.npz
│   │   └── denver_embeddings.npz
│   ├── services/
│   │   ├── lexai_service.py
│   │   └── openai_client.py
│   └── ui/
│       ├── formatters.py
│       └── gradio_interface.py
├── pyproject.toml
├── pytest.ini
├── requirements.txt
└── tests/
    ├── test_data_loader.py
    ├── test_matcher.py
    └── test_openai_client.py
```

---

## Testing

To run tests:

```bash
pytest
```

To check code coverage:

```bash
pytest --cov=lexai --cov-report=term
```

To lint:

```bash
ruff check .
```

To format code:

```bash
black .
```

---

## License

MIT License

---

## Acknowledgements

- Built with [Gradio](https://gradio.app)
- Powered by [OpenAI](https://openai.com)