Downloads · 30 days
10
53% of all-time downloads
Ranajit1997/red-ai-code-reviewer
red-ai-code-reviewer is a machine learning model from Ranajit1997. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
An RedAI-powered code review tool using OpenAI GPT models to analyze and improve your code quality. developed by Ranajit Sahoo Software developer at Redintegro .
Downloads · 30 days
10
53% of all-time downloads
All-time downloads
19
Public
Repo size
—
Likes
1
Public
Click a slice to open those files.
.py5.4 KB · 49%
From the Hugging Face model README
An RedAI-powered code review tool using OpenAI GPT models to analyze and improve your code quality. developed by Ranajit Sahoo Software developer at Redintegro .
🤖 AI-Powered Analysis - Uses OpenAI's advanced language models for comprehensive code review
📊 Multi-dimensional Review - Evaluates readability, bugs, optimizations, security, and more
🔄 Code Refactoring - Suggests improved code versions with detailed explanations
🎯 Overall Scoring - Provides quantitative score (0-100) for code quality assessment
🚀 Easy Integration - Simple Python API for quick implementation
🔍 Security Scanning - Identifies potential security vulnerabilities
⚡ Performance Optimization - Suggests performance improvements
# Install required dependencies
pip install huggingface_hub openai
Load and use directly from Hugging Face Hub!
from huggingface_hub import snapshot_download
import sys, os
# Set OpenAI key (if not set in terminal)
os.environ["OPENAI_API_KEY"] = "sk-your-openai-key-here"
# Download repo from Hugging Face
repo_dir = snapshot_download("Ranajit1997/red-ai-code-reviewer")
# Add repo folder to Python path
package_dir = os.path.join(repo_dir, "red_ai_code_reviewer") # folder with model.py, pipeline.py, __init__.py
sys.path.append(package_dir)
# 4️⃣ Import classes directly from files
from model import CodeReviewerModel
from pipeline import CodeReviewerPipeline
# 5️⃣ Initialize
model = CodeReviewerModel(api_key="sk-your-openai-key-here",
)
reviewer = CodeReviewerPipeline(model)
# 6️⃣ Example code
code = """
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n-1)
"""
# 7️⃣ Run review
review = reviewer(code)
# 8️⃣ Print result
print("AI Review:\n", review)
The code review returns a comprehensive analysis in the following structured format:
{
'readability': 'Assessment of code clarity and understandability',
'bugs': ['List of potential bugs and issues'],
'optimizations': ['List of optimization suggestions'],
'refactored_code': 'Improved version of the code',
'security_issues': ['List of security vulnerabilities'],
'overall_score': 85 # Numerical score (0-100)
}
AI Review:
{
'readability': 'The code is simple and easy to understand, with a clear recursive approach to calculating the factorial.',
'bugs': [],
'optimizations': ['Consider using an iterative approach to avoid potential stack overflow with large inputs.'],
'refactored_code': 'def factorial(n):\n result = 1\n for i in range(2, n + 1):\n result *= i\n return result',
'security_issues': [],
'overall_score': 85
}
}
You need an OpenAI API key to use this tool. Get your API key from Openai Platform
# Option 1: Set environment variable
os.environ["OPENAI_API_KEY"] = "sk-your-key-here"
# Option 2: Pass directly to model
model = CodeReviewerModel(api_key="sk-your-key-here")
# Option 3: Use .env file (recommended for production)
from dotenv import load_dotenv
load_dotenv()
# Then set OPENAI_API_KEY in your .env file