Skip to content

Commit 48fdabf

Browse files
final msg
1 parent 4a1c666 commit 48fdabf

File tree

12 files changed

+19
-46
lines changed

12 files changed

+19
-46
lines changed

.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
GOOGLE_API_KEY="AIzaSyDogEE6z042tkYJGw7lcVuvLkjmMMLiybU"
1+
GOOGLE_API_KEY="AIzaSyDogEE6z042tkYJGw7lcVuvLkjmMMLiybU"

.insightignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
venv/
2-
node_modules/
32
.env
-54 Bytes
Binary file not shown.
-23 Bytes
Binary file not shown.
-137 Bytes
Binary file not shown.
-139 Bytes
Binary file not shown.
-73 Bytes
Binary file not shown.

insight/analyzer.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,15 @@
44
from .utils import list_source_files
55

66
def extract_code_stats(file_path, content):
7-
"""Extract basic static analysis stats."""
87
stats = {
98
"functions": 0,
109
"classes": 0,
1110
"imports": [],
1211
"comments": 0
1312
}
1413

15-
# Count comments
1614
stats["comments"] = sum(1 for line in content.splitlines() if line.strip().startswith("#"))
1715

18-
# For Python files → use AST parsing
1916
if file_path.endswith(".py"):
2017
try:
2118
tree = ast.parse(content)
@@ -29,7 +26,7 @@ def extract_code_stats(file_path, content):
2926
elif isinstance(node, ast.ImportFrom):
3027
stats["imports"].append(node.module)
3128
except Exception:
32-
pass # ignore parsing errors
29+
pass
3330

3431
return stats
3532

@@ -39,11 +36,7 @@ def analyze_file(file_path):
3936

4037
lines = content.splitlines()
4138
preview = lines[:30]
42-
43-
# Extract static stats
4439
stats = extract_code_stats(file_path, content)
45-
46-
# Ask Gemini for explanation + AI probability score
4740
explanation, ai_score = explain_code(content, file_path)
4841

4942
return {
@@ -55,7 +48,7 @@ def analyze_file(file_path):
5548
"classes": stats["classes"],
5649
"imports": stats["imports"],
5750
"comments": stats["comments"],
58-
"ai_score": ai_score # 1–10 scale
51+
"ai_score": ai_score
5952
}
6053

6154
def analyze_codebase(path, limit=None):
@@ -66,7 +59,7 @@ def analyze_codebase(path, limit=None):
6659
for idx, file_path in enumerate(files, start=1):
6760
if limit and idx > limit:
6861
break
69-
print(f"🔎 Processing {idx}/{total_files}: {file_path}")
62+
print(f"Processing {idx}/{total_files}: {file_path}")
7063
results.append(analyze_file(file_path))
7164

7265
return results

insight/cli.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ def main():
1111
args = parser.parse_args()
1212

1313
if not os.path.exists(args.path):
14-
print(" Path not found.")
14+
print("Error: Path not found.")
1515
return
1616

17-
print("🔍 Analyzing codebase...")
17+
print("Analyzing codebase...")
1818
analysis = analyze_codebase(args.path, limit=args.limit)
1919

20-
print("📝 Generating reports...")
20+
print("Generating reports...")
2121
generate_report(analysis, args.output)
2222

23-
print(f"Reports saved in {args.output}/")
23+
print(f"Reports saved in {args.output}/")

insight/detector.py

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,21 @@
11
import google.generativeai as genai
22
import os
33
import sys
4-
5-
# Check for API key in environment
64
api_key = os.environ.get("GOOGLE_API_KEY") or os.environ.get("GEMINI_API_KEY")
7-
85
if not api_key:
9-
print(" No API key found.")
6+
print("Error: No API key found.")
107
print("Please set your key using one of the following:")
11-
print(" export GOOGLE_API_KEY='your_key_here' # Mac/Linux")
12-
print(" setx GOOGLE_API_KEY 'your_key_here' # Windows")
8+
print(" export GOOGLE_API_KEY='your_key_here'")
9+
print(" setx GOOGLE_API_KEY 'your_key_here'")
1310
sys.exit(1)
14-
15-
# Configure Gemini
1611
genai.configure(api_key=api_key)
17-
1812
def explain_code(content: str, filename: str):
19-
"""Use Gemini to explain file + detect if AI-generated (1–10 scale)."""
2013
if not content.strip():
21-
return "⚠️ File is empty.", 1
22-
14+
return "File is empty.", 1
2315
model = genai.GenerativeModel("gemini-1.5-flash")
24-
2516
prompt = f"""
2617
You are analyzing a code file.
2718
File: {filename}
28-
2919
Tasks:
3020
1. Summarize what this file does in detail.
3121
2. Mention its key logic (functions, classes, workflows).
@@ -36,18 +26,15 @@ def explain_code(content: str, filename: str):
3626
Code (truncated if too long):
3727
{content[:5000]}
3828
"""
39-
4029
try:
4130
response = model.generate_content(prompt)
42-
text = response.text if response else "⚠️ No explanation generated."
31+
text = response.text if response else "No explanation generated."
4332
ai_score = 5
4433

45-
# crude number extraction
4634
for num in range(10, 0, -1):
4735
if str(num) in text:
4836
ai_score = num
4937
break
50-
5138
return text, ai_score
5239
except Exception as e:
53-
return f"⚠️ Gemini API error: {str(e)}", 1
40+
return f"Gemini API error: {str(e)}", 1

0 commit comments

Comments
 (0)