fixed the issue 2
Browse files- .DS_Store +0 -0
- app.py +22 -6
- requirements.txt +1 -0
.DS_Store
CHANGED
|
Binary files a/.DS_Store and b/.DS_Store differ
|
|
|
app.py
CHANGED
|
@@ -1,10 +1,17 @@
|
|
| 1 |
"""
|
| 2 |
-
CommitLens — Gradio UI
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
"""
|
| 4 |
|
| 5 |
from __future__ import annotations
|
| 6 |
|
| 7 |
import gradio as gr
|
|
|
|
| 8 |
import torch
|
| 9 |
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
|
| 10 |
|
|
@@ -39,32 +46,34 @@ FINAL_SYSTEM_PROMPT = (
|
|
| 39 |
_model = None
|
| 40 |
_tokenizer = None
|
| 41 |
|
|
|
|
| 42 |
def _get_llm():
|
| 43 |
global _model, _tokenizer
|
| 44 |
if _model is None:
|
| 45 |
-
# 8-bit quantization is
|
| 46 |
quantization_config = BitsAndBytesConfig(
|
| 47 |
load_in_8bit=True,
|
| 48 |
)
|
| 49 |
|
| 50 |
_tokenizer = AutoTokenizer.from_pretrained(MODEL_REPO_ID)
|
| 51 |
|
| 52 |
-
#
|
| 53 |
-
# CHANGED: Removed Flash Attention (T4 relies on native SDPA instead)
|
| 54 |
_model = AutoModelForCausalLM.from_pretrained(
|
| 55 |
MODEL_REPO_ID,
|
| 56 |
quantization_config=quantization_config,
|
| 57 |
device_map="auto",
|
| 58 |
-
torch_dtype=torch.
|
| 59 |
)
|
| 60 |
return _model, _tokenizer
|
| 61 |
|
|
|
|
| 62 |
def _extract_filename(prompt: str) -> str:
|
| 63 |
for line in prompt.splitlines():
|
| 64 |
if line.startswith("Filename :"):
|
| 65 |
return line.split(":", 1)[1].strip()
|
| 66 |
return "unknown"
|
| 67 |
|
|
|
|
| 68 |
def _generate_response(system_prompt: str, user_prompt: str, max_tokens: int) -> str:
|
| 69 |
model, tokenizer = _get_llm()
|
| 70 |
|
|
@@ -73,6 +82,7 @@ def _generate_response(system_prompt: str, user_prompt: str, max_tokens: int) ->
|
|
| 73 |
{"role": "user", "content": user_prompt},
|
| 74 |
]
|
| 75 |
|
|
|
|
| 76 |
formatted_prompt = tokenizer.apply_chat_template(
|
| 77 |
messages, tokenize=False, add_generation_prompt=True
|
| 78 |
)
|
|
@@ -87,20 +97,25 @@ def _generate_response(system_prompt: str, user_prompt: str, max_tokens: int) ->
|
|
| 87 |
pad_token_id=tokenizer.eos_token_id
|
| 88 |
)
|
| 89 |
|
|
|
|
| 90 |
response = tokenizer.decode(outputs[0][inputs.input_ids.shape[-1]:], skip_special_tokens=True)
|
| 91 |
return response.strip()
|
| 92 |
|
|
|
|
| 93 |
def _summarize(prompt: str) -> str:
|
| 94 |
return _generate_response(SUMMARY_SYSTEM_PROMPT, prompt, max_tokens=1024)
|
| 95 |
|
|
|
|
| 96 |
def _final_md(combined: str) -> str:
|
| 97 |
return _generate_response(FINAL_SYSTEM_PROMPT, combined, max_tokens=2048)
|
| 98 |
|
|
|
|
| 99 |
# ---------------------------------------------------------------------------
|
| 100 |
# Pipeline
|
| 101 |
# ---------------------------------------------------------------------------
|
| 102 |
|
| 103 |
-
#
|
|
|
|
| 104 |
def process_repo(repo_url: str, token: str, progress: gr.Progress = gr.Progress()):
|
| 105 |
try:
|
| 106 |
progress(0, desc="Running CommitLens pipeline...")
|
|
@@ -129,6 +144,7 @@ def process_repo(repo_url: str, token: str, progress: gr.Progress = gr.Progress(
|
|
| 129 |
except Exception as e:
|
| 130 |
raise gr.Error(str(e))
|
| 131 |
|
|
|
|
| 132 |
# ---------------------------------------------------------------------------
|
| 133 |
# Gradio app
|
| 134 |
# ---------------------------------------------------------------------------
|
|
|
|
| 1 |
"""
|
| 2 |
+
CommitLens — Gradio UI
|
| 3 |
+
=======================
|
| 4 |
+
- Asks for a GitHub repo URL (and optional PAT)
|
| 5 |
+
- Runs commitlens.run_pipeline() to get per-file prompts
|
| 6 |
+
- Feeds each prompt to Mellum 2 for a per-file summary
|
| 7 |
+
- Combines all summaries and asks the model for a final .md report
|
| 8 |
+
- Displays everything in the browser
|
| 9 |
"""
|
| 10 |
|
| 11 |
from __future__ import annotations
|
| 12 |
|
| 13 |
import gradio as gr
|
| 14 |
+
import spaces
|
| 15 |
import torch
|
| 16 |
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
|
| 17 |
|
|
|
|
| 46 |
_model = None
|
| 47 |
_tokenizer = None
|
| 48 |
|
| 49 |
+
|
| 50 |
def _get_llm():
|
| 51 |
global _model, _tokenizer
|
| 52 |
if _model is None:
|
| 53 |
+
# 8-bit quantization is required to bypass the 16GB ZeroGPU CPU RAM limit
|
| 54 |
quantization_config = BitsAndBytesConfig(
|
| 55 |
load_in_8bit=True,
|
| 56 |
)
|
| 57 |
|
| 58 |
_tokenizer = AutoTokenizer.from_pretrained(MODEL_REPO_ID)
|
| 59 |
|
| 60 |
+
# flash_attention_2 removed. PyTorch will automatically use native SDPA.
|
|
|
|
| 61 |
_model = AutoModelForCausalLM.from_pretrained(
|
| 62 |
MODEL_REPO_ID,
|
| 63 |
quantization_config=quantization_config,
|
| 64 |
device_map="auto",
|
| 65 |
+
torch_dtype=torch.bfloat16 # ZeroGPU RTX 6000 natively supports bfloat16
|
| 66 |
)
|
| 67 |
return _model, _tokenizer
|
| 68 |
|
| 69 |
+
|
| 70 |
def _extract_filename(prompt: str) -> str:
|
| 71 |
for line in prompt.splitlines():
|
| 72 |
if line.startswith("Filename :"):
|
| 73 |
return line.split(":", 1)[1].strip()
|
| 74 |
return "unknown"
|
| 75 |
|
| 76 |
+
|
| 77 |
def _generate_response(system_prompt: str, user_prompt: str, max_tokens: int) -> str:
|
| 78 |
model, tokenizer = _get_llm()
|
| 79 |
|
|
|
|
| 82 |
{"role": "user", "content": user_prompt},
|
| 83 |
]
|
| 84 |
|
| 85 |
+
# Format the prompt using the model's chat template
|
| 86 |
formatted_prompt = tokenizer.apply_chat_template(
|
| 87 |
messages, tokenize=False, add_generation_prompt=True
|
| 88 |
)
|
|
|
|
| 97 |
pad_token_id=tokenizer.eos_token_id
|
| 98 |
)
|
| 99 |
|
| 100 |
+
# Decode and return just the generated response
|
| 101 |
response = tokenizer.decode(outputs[0][inputs.input_ids.shape[-1]:], skip_special_tokens=True)
|
| 102 |
return response.strip()
|
| 103 |
|
| 104 |
+
|
| 105 |
def _summarize(prompt: str) -> str:
|
| 106 |
return _generate_response(SUMMARY_SYSTEM_PROMPT, prompt, max_tokens=1024)
|
| 107 |
|
| 108 |
+
|
| 109 |
def _final_md(combined: str) -> str:
|
| 110 |
return _generate_response(FINAL_SYSTEM_PROMPT, combined, max_tokens=2048)
|
| 111 |
|
| 112 |
+
|
| 113 |
# ---------------------------------------------------------------------------
|
| 114 |
# Pipeline
|
| 115 |
# ---------------------------------------------------------------------------
|
| 116 |
|
| 117 |
+
# Re-added the @spaces.GPU decorator with the 300-second timeout
|
| 118 |
+
@spaces.GPU(duration=300)
|
| 119 |
def process_repo(repo_url: str, token: str, progress: gr.Progress = gr.Progress()):
|
| 120 |
try:
|
| 121 |
progress(0, desc="Running CommitLens pipeline...")
|
|
|
|
| 144 |
except Exception as e:
|
| 145 |
raise gr.Error(str(e))
|
| 146 |
|
| 147 |
+
|
| 148 |
# ---------------------------------------------------------------------------
|
| 149 |
# Gradio app
|
| 150 |
# ---------------------------------------------------------------------------
|
requirements.txt
CHANGED
|
@@ -2,4 +2,5 @@ transformers
|
|
| 2 |
accelerate
|
| 3 |
bitsandbytes
|
| 4 |
torch
|
|
|
|
| 5 |
gradio
|
|
|
|
| 2 |
accelerate
|
| 3 |
bitsandbytes
|
| 4 |
torch
|
| 5 |
+
spaces
|
| 6 |
gradio
|