Spaces:
Running
Running
Update app/predictor.py
Browse files- app/predictor.py +1 -11
app/predictor.py
CHANGED
|
@@ -4,7 +4,6 @@ import torch
|
|
| 4 |
import torch.nn.functional as F
|
| 5 |
from transformers import AutoModel, AutoTokenizer
|
| 6 |
|
| 7 |
-
# Resilient import handling for AIReviewerService across different project layouts
|
| 8 |
try:
|
| 9 |
from app.services.reviewer_service import AIReviewerService
|
| 10 |
except ImportError:
|
|
@@ -24,7 +23,6 @@ class CodeClassifier:
|
|
| 24 |
"""
|
| 25 |
def __init__(self):
|
| 26 |
logger.info("⏳ Initializing CodeBERT AI Service...")
|
| 27 |
-
|
| 28 |
self.device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 29 |
if torch.backends.mps.is_available():
|
| 30 |
self.device = "mps"
|
|
@@ -74,7 +72,6 @@ class CodeClassifier:
|
|
| 74 |
Returns: { "label": str, "confidence": float, "embedding": List[float] }
|
| 75 |
"""
|
| 76 |
path = file_path.lower()
|
| 77 |
-
|
| 78 |
try:
|
| 79 |
text_to_analyze = content[:1000] if content else file_path
|
| 80 |
target_embedding_tensor = self._get_embedding(text_to_analyze)
|
|
@@ -207,8 +204,6 @@ class GuideGenerator:
|
|
| 207 |
detected = {"languages": set(), "frameworks": set(), "tools": set()}
|
| 208 |
for file in files:
|
| 209 |
path = file.lower()
|
| 210 |
-
|
| 211 |
-
# Languages
|
| 212 |
if path.endswith(".ts") or path.endswith(".tsx"):
|
| 213 |
detected["languages"].add("TypeScript")
|
| 214 |
elif path.endswith(".js") or path.endswith(".jsx"):
|
|
@@ -224,12 +219,10 @@ class GuideGenerator:
|
|
| 224 |
elif path.endswith(".kt") or path.endswith(".kts"):
|
| 225 |
detected["languages"].add("Kotlin")
|
| 226 |
|
| 227 |
-
# Frameworks
|
| 228 |
for framework, indicators in self.tech_stacks.items():
|
| 229 |
if any(ind in path for ind in indicators):
|
| 230 |
detected["frameworks"].add(framework)
|
| 231 |
|
| 232 |
-
# Tools & Libraries
|
| 233 |
for tool, indicators in self.tools.items():
|
| 234 |
if any(ind in path for ind in indicators):
|
| 235 |
detected["tools"].add(tool)
|
|
@@ -260,7 +253,6 @@ class GuideGenerator:
|
|
| 260 |
total_files = len(files) if files else 1
|
| 261 |
primary_layer = max(stats, key=stats.get)
|
| 262 |
|
| 263 |
-
# Cross-file logical couplings analysis
|
| 264 |
couplings = []
|
| 265 |
try:
|
| 266 |
sample_paths = list(file_embeddings.keys())[:50]
|
|
@@ -306,7 +298,6 @@ class GuideGenerator:
|
|
| 306 |
run_cmd = "go run main.go"
|
| 307 |
test_cmd = "go test ./..."
|
| 308 |
|
| 309 |
-
# Assemble Markdown Document
|
| 310 |
md = f"# {repo_name} Developer Guide\n\n"
|
| 311 |
md += "## AI Codebase Insights\n"
|
| 312 |
md += "Analysis powered by **CodeBERT** semantic vector embeddings.\n\n"
|
|
@@ -373,7 +364,7 @@ class GuideGenerator:
|
|
| 373 |
md += "\n### Installation & Setup\n"
|
| 374 |
md += "1. Clone the repository:\n"
|
| 375 |
md += " ```bash\n"
|
| 376 |
-
md += f" git clone
|
| 377 |
md += f" cd {repo_name}\n"
|
| 378 |
md += " ```\n\n"
|
| 379 |
md += "2. Install dependencies:\n"
|
|
@@ -492,7 +483,6 @@ class GuideGenerator:
|
|
| 492 |
return "\n".join(lines[:60])
|
| 493 |
|
| 494 |
|
| 495 |
-
# Global Singleton Instances
|
| 496 |
classifier = CodeClassifier()
|
| 497 |
guide_generator = GuideGenerator()
|
| 498 |
|
|
|
|
| 4 |
import torch.nn.functional as F
|
| 5 |
from transformers import AutoModel, AutoTokenizer
|
| 6 |
|
|
|
|
| 7 |
try:
|
| 8 |
from app.services.reviewer_service import AIReviewerService
|
| 9 |
except ImportError:
|
|
|
|
| 23 |
"""
|
| 24 |
def __init__(self):
|
| 25 |
logger.info("⏳ Initializing CodeBERT AI Service...")
|
|
|
|
| 26 |
self.device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 27 |
if torch.backends.mps.is_available():
|
| 28 |
self.device = "mps"
|
|
|
|
| 72 |
Returns: { "label": str, "confidence": float, "embedding": List[float] }
|
| 73 |
"""
|
| 74 |
path = file_path.lower()
|
|
|
|
| 75 |
try:
|
| 76 |
text_to_analyze = content[:1000] if content else file_path
|
| 77 |
target_embedding_tensor = self._get_embedding(text_to_analyze)
|
|
|
|
| 204 |
detected = {"languages": set(), "frameworks": set(), "tools": set()}
|
| 205 |
for file in files:
|
| 206 |
path = file.lower()
|
|
|
|
|
|
|
| 207 |
if path.endswith(".ts") or path.endswith(".tsx"):
|
| 208 |
detected["languages"].add("TypeScript")
|
| 209 |
elif path.endswith(".js") or path.endswith(".jsx"):
|
|
|
|
| 219 |
elif path.endswith(".kt") or path.endswith(".kts"):
|
| 220 |
detected["languages"].add("Kotlin")
|
| 221 |
|
|
|
|
| 222 |
for framework, indicators in self.tech_stacks.items():
|
| 223 |
if any(ind in path for ind in indicators):
|
| 224 |
detected["frameworks"].add(framework)
|
| 225 |
|
|
|
|
| 226 |
for tool, indicators in self.tools.items():
|
| 227 |
if any(ind in path for ind in indicators):
|
| 228 |
detected["tools"].add(tool)
|
|
|
|
| 253 |
total_files = len(files) if files else 1
|
| 254 |
primary_layer = max(stats, key=stats.get)
|
| 255 |
|
|
|
|
| 256 |
couplings = []
|
| 257 |
try:
|
| 258 |
sample_paths = list(file_embeddings.keys())[:50]
|
|
|
|
| 298 |
run_cmd = "go run main.go"
|
| 299 |
test_cmd = "go test ./..."
|
| 300 |
|
|
|
|
| 301 |
md = f"# {repo_name} Developer Guide\n\n"
|
| 302 |
md += "## AI Codebase Insights\n"
|
| 303 |
md += "Analysis powered by **CodeBERT** semantic vector embeddings.\n\n"
|
|
|
|
| 364 |
md += "\n### Installation & Setup\n"
|
| 365 |
md += "1. Clone the repository:\n"
|
| 366 |
md += " ```bash\n"
|
| 367 |
+
md += f" git clone https://github.com/OWNER/{repo_name}.git\n"
|
| 368 |
md += f" cd {repo_name}\n"
|
| 369 |
md += " ```\n\n"
|
| 370 |
md += "2. Install dependencies:\n"
|
|
|
|
| 483 |
return "\n".join(lines[:60])
|
| 484 |
|
| 485 |
|
|
|
|
| 486 |
classifier = CodeClassifier()
|
| 487 |
guide_generator = GuideGenerator()
|
| 488 |
|