Spaces:
Running on Zero
Running on Zero
final changes
Browse files
.DS_Store
CHANGED
|
Binary files a/.DS_Store and b/.DS_Store differ
|
|
|
README.md
CHANGED
|
@@ -12,36 +12,70 @@ license: mit
|
|
| 12 |
short_description: urn any Git commit into a human-readable engineering report.
|
| 13 |
---
|
| 14 |
|
| 15 |
-
# CommitLens β AI-Powered
|
| 16 |
|
| 17 |
-
|
| 18 |
|
| 19 |
-
|
|
|
|
|
|
|
| 20 |
|
| 21 |
-
|
| 22 |
-
2. **Optionally provide a GitHub token** for higher rate limits or private repos
|
| 23 |
-
3. **Click *Run Analysis*** β the app:
|
| 24 |
-
- Fetches the two most recent commits via the GitHub API
|
| 25 |
-
- Filters for source-code files (`.py`, `.js`, `.ts`, `.go`, `.rs`, etc.)
|
| 26 |
-
- Builds a structured prompt per file (commit metadata + before/after code + diff)
|
| 27 |
-
- Sends each prompt to **Mellum 2** for a concise per-file summary
|
| 28 |
-
- Combines all summaries and asks the model again for a comprehensive markdown report
|
| 29 |
-
4. **View results** β per-file summaries and the final `.md` report side by side
|
| 30 |
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
-
|
| 34 |
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
| File | Purpose |
|
| 38 |
|------|---------|
|
| 39 |
-
| `app.py` |
|
| 40 |
-
| `commitlens.py` | GitHub API
|
| 41 |
-
| `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
- `llama-cpp-python>=0.2.0`
|
|
|
|
| 12 |
short_description: urn any Git commit into a human-readable engineering report.
|
| 13 |
---
|
| 14 |
|
| 15 |
+
# CommitLens β AI-Powered Code Review Pipeline
|
| 16 |
|
| 17 |
+
**CommitLens** is a high-performance information extraction and analysis pipeline that transforms raw GitHub diffs into structured, human-readable engineering reports. It uses a hybrid LLM approach: **JetBrains Mellum 2** for deep per-file analysis and **Groq-hosted Llama 3.3** for lightning-fast synthesis.
|
| 18 |
|
| 19 |
+

|
| 20 |
+

|
| 21 |
+

|
| 22 |
|
| 23 |
+
## π Key Features
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
+
- **Automated Diff Extraction**: Fetches the two latest commits from any GitHub repository and generates semantic diffs.
|
| 26 |
+
- **Top-Impact Filtering**: Automatically identifies and prioritizes the most significant changes (top 2 files by lines changed) to ensure high-signal reviews.
|
| 27 |
+
- **Hybrid LLM Pipeline**:
|
| 28 |
+
- **Mellum 2 (12B)**: Performs surgical, per-file code analysis. Optimized with 6-bit NF4 quantization for efficient GPU utilization.
|
| 29 |
+
- **Groq (Llama 3.3 70B)**: Generates a high-level executive summary and key takeaways in milliseconds.
|
| 30 |
+
- **Cinematic UI**: A bespoke, low-latency frontend featuring a custom particle engine, real-time status tracking, and a "git-graph" hero visualization.
|
| 31 |
|
| 32 |
+
## π Tech Stack
|
| 33 |
|
| 34 |
+
- **Core**: Python 3.12, FastAPI, Gradio (Server Mode).
|
| 35 |
+
- **ML/Inference**: `transformers`, `bitsandbytes` (4-bit/6-bit quantization), `torch`, `spaces` (ZeroGPU).
|
| 36 |
+
- **APIs**: GitHub REST API, Groq Cloud API.
|
| 37 |
+
- **Frontend**: Vanilla JavaScript (ES6+), HTML5 Canvas, CSS3 Grid/Flexbox.
|
| 38 |
+
|
| 39 |
+
## π Project Structure
|
| 40 |
|
| 41 |
| File | Purpose |
|
| 42 |
|------|---------|
|
| 43 |
+
| `app.py` | Main application server; manages model lifecycle and GPU/API orchestration. |
|
| 44 |
+
| `commitlens.py` | Data pipeline; handles GitHub API interaction, file filtering, and prompt engineering. |
|
| 45 |
+
| `index.html` | Custom-built, high-fidelity frontend with interactive Git visualizations. |
|
| 46 |
+
| `requirements.txt` | Dependency manifest (requests, gradio, torch, transformers, etc.). |
|
| 47 |
+
|
| 48 |
+
## βοΈ How It Works
|
| 49 |
+
|
| 50 |
+
1. **Extraction**: The `GitHubClient` fetches commit metadata and raw patches.
|
| 51 |
+
2. **Filtering**: Files are filtered by extension (keeping source code, ignoring binaries/locks) and sorted by impact.
|
| 52 |
+
3. **Mellum Analysis**: The pipeline builds structured prompts containing "Before", "After", and "Diff" blocks. Mellum 2 generates concise summaries for each file.
|
| 53 |
+
4. **Groq Synthesis**: Per-file summaries are batched and sent to Groq for a final structured Markdown report including a "Commit Overview" and "Key Takeaways".
|
| 54 |
+
|
| 55 |
+
## π Setup & Usage
|
| 56 |
+
|
| 57 |
+
### Local Development
|
| 58 |
+
|
| 59 |
+
1. **Install dependencies**:
|
| 60 |
+
```bash
|
| 61 |
+
pip install -r requirements.txt
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
2. **Set Environment Variables**:
|
| 65 |
+
```bash
|
| 66 |
+
export GROQ_API_KEY="your_groq_api_key"
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
+
3. **Run the application**:
|
| 70 |
+
```bash
|
| 71 |
+
python app.py
|
| 72 |
+
```
|
| 73 |
|
| 74 |
+
### CLI Mode
|
| 75 |
+
You can also run the extraction pipeline directly:
|
| 76 |
+
```bash
|
| 77 |
+
python commitlens.py <github_repo_url> --token <optional_pat> --print-prompts
|
| 78 |
+
```
|
| 79 |
|
| 80 |
+
## π License
|
| 81 |
+
MIT
|
|
|
app.py
CHANGED
|
@@ -37,7 +37,7 @@ log = logging.getLogger("commitlens")
|
|
| 37 |
# Config
|
| 38 |
# ---------------------------------------------------------------------------
|
| 39 |
|
| 40 |
-
MODEL_REPO_ID = "JetBrains/Mellum2-12B-A2.5B-
|
| 41 |
GROQ_MODEL = "llama-3.3-70b-versatile" # fast Groq-hosted 70B
|
| 42 |
# BATCH_TOKEN_BUDGET = 7000 # estimated input tokens; above this β sequential
|
| 43 |
|
|
@@ -202,9 +202,9 @@ def _generate_sequential(prompts: list[str]) -> list[str]:
|
|
| 202 |
with torch.no_grad():
|
| 203 |
out = _model.generate(
|
| 204 |
**enc,
|
| 205 |
-
max_new_tokens=
|
| 206 |
use_cache=True,
|
| 207 |
-
do_sample=
|
| 208 |
temperature=0.4,
|
| 209 |
top_p=0.95,
|
| 210 |
pad_token_id=_tokenizer.pad_token_id,
|
|
|
|
| 37 |
# Config
|
| 38 |
# ---------------------------------------------------------------------------
|
| 39 |
|
| 40 |
+
MODEL_REPO_ID = "JetBrains/Mellum2-12B-A2.5B-Instruct"
|
| 41 |
GROQ_MODEL = "llama-3.3-70b-versatile" # fast Groq-hosted 70B
|
| 42 |
# BATCH_TOKEN_BUDGET = 7000 # estimated input tokens; above this β sequential
|
| 43 |
|
|
|
|
| 202 |
with torch.no_grad():
|
| 203 |
out = _model.generate(
|
| 204 |
**enc,
|
| 205 |
+
max_new_tokens=1024,
|
| 206 |
use_cache=True,
|
| 207 |
+
do_sample=True,
|
| 208 |
temperature=0.4,
|
| 209 |
top_p=0.95,
|
| 210 |
pad_token_id=_tokenizer.pad_token_id,
|
commitlens.py
CHANGED
|
@@ -237,7 +237,7 @@ def fetch_commit_context(
|
|
| 237 |
filtered,
|
| 238 |
key=lambda x: x.get("additions", 0) + x.get("deletions", 0),
|
| 239 |
reverse=True
|
| 240 |
-
)
|
| 241 |
|
| 242 |
# Step 5 + 6 β build FileContext, fetch before/after content
|
| 243 |
file_contexts: list[FileContext] = []
|
|
@@ -305,22 +305,22 @@ def build_prompts(ctx: CommitContext) -> list[str]:
|
|
| 305 |
)
|
| 306 |
|
| 307 |
# Before content
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
#
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
|
| 325 |
# Diff patch
|
| 326 |
if fc.patch:
|
|
|
|
| 237 |
filtered,
|
| 238 |
key=lambda x: x.get("additions", 0) + x.get("deletions", 0),
|
| 239 |
reverse=True
|
| 240 |
+
)
|
| 241 |
|
| 242 |
# Step 5 + 6 β build FileContext, fetch before/after content
|
| 243 |
file_contexts: list[FileContext] = []
|
|
|
|
| 305 |
)
|
| 306 |
|
| 307 |
# Before content
|
| 308 |
+
if fc.before_content is not None:
|
| 309 |
+
sections.append(
|
| 310 |
+
"=== BEFORE CODE ===\n"
|
| 311 |
+
f"{fc.before_content}\n"
|
| 312 |
+
)
|
| 313 |
+
else:
|
| 314 |
+
sections.append("=== BEFORE CODE ===\n(file did not exist)\n")
|
| 315 |
+
|
| 316 |
+
# After content
|
| 317 |
+
if fc.after_content is not None:
|
| 318 |
+
sections.append(
|
| 319 |
+
"=== AFTER CODE ===\n"
|
| 320 |
+
f"{fc.after_content}\n"
|
| 321 |
+
)
|
| 322 |
+
else:
|
| 323 |
+
sections.append("=== AFTER CODE ===\n(file was deleted)\n")
|
| 324 |
|
| 325 |
# Diff patch
|
| 326 |
if fc.patch:
|