Spaces:
Sleeping
Sleeping
arun3676 commited on
Commit ·
646ba30
0
Parent(s):
Initial commit: LLM Code Analyzer with multi-model support
Browse files- .gitignore +44 -0
- .streamlit/config.toml +11 -0
- API_SETUP.md +44 -0
- Procfile +1 -0
- README.md +234 -0
- analyzer/__init__.py +4 -0
- analyzer/code_analyzer.py +335 -0
- analyzer/llm_clients.py +143 -0
- analyzer/prompts.py +88 -0
- analyzer/utils.py +232 -0
- app.py +293 -0
- launch.py +111 -0
- launch_matrix.py +144 -0
- matrix_app.py +562 -0
- matrix_final.py +978 -0
- matrix_final_backup.py +978 -0
- netlify.toml +9 -0
- render.yaml +18 -0
- requirements.txt +6 -0
- runtime.txt +1 -0
- streamlit.bat +2 -0
- test_app.py +34 -0
.gitignore
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Python
|
| 2 |
+
__pycache__/
|
| 3 |
+
*.py[cod]
|
| 4 |
+
*$py.class
|
| 5 |
+
*.so
|
| 6 |
+
.Python
|
| 7 |
+
*.egg-info/
|
| 8 |
+
dist/
|
| 9 |
+
build/
|
| 10 |
+
|
| 11 |
+
# Virtual Environment
|
| 12 |
+
.venv/
|
| 13 |
+
venv/
|
| 14 |
+
ENV/
|
| 15 |
+
env/
|
| 16 |
+
|
| 17 |
+
# Environment variables
|
| 18 |
+
.env
|
| 19 |
+
.env.local
|
| 20 |
+
.env.production
|
| 21 |
+
|
| 22 |
+
# IDE
|
| 23 |
+
.vscode/
|
| 24 |
+
.idea/
|
| 25 |
+
*.swp
|
| 26 |
+
*.swo
|
| 27 |
+
|
| 28 |
+
# OS
|
| 29 |
+
.DS_Store
|
| 30 |
+
Thumbs.db
|
| 31 |
+
|
| 32 |
+
# Logs
|
| 33 |
+
*.log
|
| 34 |
+
|
| 35 |
+
# Streamlit
|
| 36 |
+
.streamlit/secrets.toml
|
| 37 |
+
|
| 38 |
+
# Test files
|
| 39 |
+
test_analyzer.py
|
| 40 |
+
test_results.txt
|
| 41 |
+
|
| 42 |
+
# Deployment
|
| 43 |
+
render.yaml.bak
|
| 44 |
+
netlify.toml.bak
|
.streamlit/config.toml
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[server]
|
| 2 |
+
headless = true
|
| 3 |
+
port = 8501
|
| 4 |
+
enableCORS = false
|
| 5 |
+
enableXsrfProtection = false
|
| 6 |
+
|
| 7 |
+
[theme]
|
| 8 |
+
primaryColor = "#FF6B6B"
|
| 9 |
+
backgroundColor = "#0E1117"
|
| 10 |
+
secondaryBackgroundColor = "#262730"
|
| 11 |
+
textColor = "#FAFAFA"
|
API_SETUP.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# API Setup Guide
|
| 2 |
+
|
| 3 |
+
## Setting up DeepSeek API Key
|
| 4 |
+
|
| 5 |
+
1. **Get your DeepSeek API Key**:
|
| 6 |
+
- Go to [DeepSeek Console](https://platform.deepseek.com/)
|
| 7 |
+
- Sign up or log in
|
| 8 |
+
- Navigate to API Keys section
|
| 9 |
+
- Create a new API key
|
| 10 |
+
|
| 11 |
+
2. **Add the key to your environment**:
|
| 12 |
+
- Create a `.env` file in your project root
|
| 13 |
+
- Add: `DEEPSEEK_API_KEY=your_actual_api_key_here`
|
| 14 |
+
- **Important**: Use your real API key, not placeholder text like `****`
|
| 15 |
+
|
| 16 |
+
3. **Other supported APIs**:
|
| 17 |
+
```
|
| 18 |
+
OPENAI_API_KEY=your_openai_key_here
|
| 19 |
+
ANTHROPIC_API_KEY=your_claude_key_here
|
| 20 |
+
GEMINI_API_KEY=your_gemini_key_here
|
| 21 |
+
```
|
| 22 |
+
|
| 23 |
+
## Common Issues & Solutions
|
| 24 |
+
|
| 25 |
+
### DeepSeek Authentication Error (401)
|
| 26 |
+
- **Problem**: Error message "Authentication Fails, Your api key: ****here is invalid"
|
| 27 |
+
- **Solution**:
|
| 28 |
+
1. Double-check your API key is correct
|
| 29 |
+
2. Make sure there are no extra spaces or quotes
|
| 30 |
+
3. Verify the key is active in DeepSeek console
|
| 31 |
+
4. Try regenerating the API key
|
| 32 |
+
|
| 33 |
+
### Button Not Clickable
|
| 34 |
+
- **Fixed**: The "Analyze Code" button is now always clickable
|
| 35 |
+
- **Usage**: Just paste your code and click "Analyze Code"
|
| 36 |
+
- No need to wait for any delays
|
| 37 |
+
|
| 38 |
+
## Running the Application
|
| 39 |
+
|
| 40 |
+
```bash
|
| 41 |
+
python -m streamlit run matrix_final.py --server.port 8500
|
| 42 |
+
```
|
| 43 |
+
|
| 44 |
+
Access at: http://localhost:8500
|
Procfile
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
web: streamlit run app.py --server.port=$PORT --server.address=0.0.0.0
|
README.md
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# LLM Code Analyzer
|
| 2 |
+
|
| 3 |
+
A professional code analysis tool that leverages multiple Large Language Models (LLMs) to provide comprehensive code reviews, identify issues, and suggest improvements.
|
| 4 |
+
|
| 5 |
+

|
| 6 |
+

|
| 7 |
+

|
| 8 |
+
|
| 9 |
+
## ✨ Features
|
| 10 |
+
|
| 11 |
+
- **🤖 Multi-Model Analysis**: Compare insights from OpenAI GPT-4, Anthropic Claude, Google Gemini, and DeepSeek
|
| 12 |
+
- **📊 Comprehensive Code Review**: Get quality scores, identify bugs, security issues, and performance concerns
|
| 13 |
+
- **🔍 Language Auto-Detection**: Automatically detects programming language or manually specify
|
| 14 |
+
- **🎨 Clean Professional UI**: Built with Streamlit for a modern, responsive interface
|
| 15 |
+
- **⚡ Lightweight & Fast**: Optimized for deployment on platforms like Render
|
| 16 |
+
- **🔒 Secure**: API keys are securely managed through environment variables
|
| 17 |
+
- **📈 Real-time Metrics**: Track analysis time, quality scores, and model comparisons
|
| 18 |
+
- **🤝 Consensus Analysis**: Identify issues that multiple models agree on
|
| 19 |
+
|
| 20 |
+
## 🌐 Live Demo
|
| 21 |
+
|
| 22 |
+
[Try it on Render](https://your-app-name.onrender.com) *(Coming Soon)*
|
| 23 |
+
|
| 24 |
+
## 🛠️ Tech Stack
|
| 25 |
+
|
| 26 |
+
- **Frontend**: Streamlit
|
| 27 |
+
- **LLM Integration**: OpenAI, Anthropic, Google Gemini, DeepSeek APIs
|
| 28 |
+
- **Language**: Python 3.11+
|
| 29 |
+
- **Deployment**: Render (or any Python hosting platform)
|
| 30 |
+
|
| 31 |
+
## 🚀 Quick Start
|
| 32 |
+
|
| 33 |
+
### Prerequisites
|
| 34 |
+
|
| 35 |
+
- Python 3.11 or higher
|
| 36 |
+
- API keys for at least one LLM provider:
|
| 37 |
+
- OpenAI API Key
|
| 38 |
+
- Anthropic API Key
|
| 39 |
+
- Google Gemini API Key
|
| 40 |
+
- DeepSeek API Key
|
| 41 |
+
|
| 42 |
+
### Installation
|
| 43 |
+
|
| 44 |
+
1. **Clone the repository:**
|
| 45 |
+
```bash
|
| 46 |
+
git clone https://github.com/yourusername/llm-code-analyzer.git
|
| 47 |
+
cd llm-code-analyzer
|
| 48 |
+
```
|
| 49 |
+
|
| 50 |
+
2. **Create a virtual environment:**
|
| 51 |
+
```bash
|
| 52 |
+
python -m venv .venv
|
| 53 |
+
source .venv/bin/activate # On Windows: .venv\Scripts\activate
|
| 54 |
+
```
|
| 55 |
+
|
| 56 |
+
3. **Install dependencies:**
|
| 57 |
+
```bash
|
| 58 |
+
pip install -r requirements.txt
|
| 59 |
+
```
|
| 60 |
+
|
| 61 |
+
4. **Configure environment variables:**
|
| 62 |
+
|
| 63 |
+
Copy the `.env` file and add your API keys:
|
| 64 |
+
```bash
|
| 65 |
+
cp .env .env.local
|
| 66 |
+
```
|
| 67 |
+
|
| 68 |
+
Edit `.env.local` with your actual API keys:
|
| 69 |
+
```env
|
| 70 |
+
# API Keys - Replace with your actual API keys
|
| 71 |
+
OPENAI_API_KEY=your_openai_api_key_here
|
| 72 |
+
ANTHROPIC_API_KEY=your_anthropic_api_key_here
|
| 73 |
+
GEMINI_API_KEY=your_google_api_key_here
|
| 74 |
+
DEEPSEEK_API_KEY=your_deepseek_api_key_here
|
| 75 |
+
```
|
| 76 |
+
|
| 77 |
+
5. **Run the application:**
|
| 78 |
+
```bash
|
| 79 |
+
streamlit run app.py
|
| 80 |
+
```
|
| 81 |
+
|
| 82 |
+
The application will be available at `http://localhost:8501`
|
| 83 |
+
|
| 84 |
+
## 📋 Usage
|
| 85 |
+
|
| 86 |
+
### Single Model Analysis
|
| 87 |
+
1. Paste your code in the left panel
|
| 88 |
+
2. Select a specific LLM model from the dropdown
|
| 89 |
+
3. Choose the programming language (or use auto-detect)
|
| 90 |
+
4. Click "🚀 Analyze Code"
|
| 91 |
+
|
| 92 |
+
### Multi-Model Comparison
|
| 93 |
+
1. Paste your code in the left panel
|
| 94 |
+
2. Check "Compare All Models"
|
| 95 |
+
3. Click "🚀 Analyze Code"
|
| 96 |
+
4. View results in separate tabs for each model
|
| 97 |
+
5. See consensus issues identified by multiple models
|
| 98 |
+
|
| 99 |
+
### Sample Code
|
| 100 |
+
Use the "Sample Code" section in the sidebar to quickly load example Python or JavaScript code for testing.
|
| 101 |
+
|
| 102 |
+
## 🏗️ Project Structure
|
| 103 |
+
|
| 104 |
+
```
|
| 105 |
+
llm-code-analyzer/
|
| 106 |
+
├── .env # Environment variables template
|
| 107 |
+
├── .gitignore # Git ignore patterns
|
| 108 |
+
├── requirements.txt # Python dependencies
|
| 109 |
+
├── README.md # This file
|
| 110 |
+
├── app.py # Main Streamlit application
|
| 111 |
+
└── analyzer/
|
| 112 |
+
├── __init__.py # Package initialization
|
| 113 |
+
├── llm_clients.py # LLM API client implementations
|
| 114 |
+
├── code_analyzer.py # Main analysis engine
|
| 115 |
+
├── prompts.py # Analysis prompt templates
|
| 116 |
+
└── utils.py # Utility functions
|
| 117 |
+
```
|
| 118 |
+
|
| 119 |
+
## 🔧 Configuration
|
| 120 |
+
|
| 121 |
+
### Supported LLM Providers
|
| 122 |
+
|
| 123 |
+
| Provider | Model | API Key Environment Variable |
|
| 124 |
+
|----------|-------|------------------------------|
|
| 125 |
+
| OpenAI | GPT-4o-mini | `OPENAI_API_KEY` |
|
| 126 |
+
| Anthropic | Claude 3 Haiku | `ANTHROPIC_API_KEY` |
|
| 127 |
+
| Google | Gemini Pro | `GEMINI_API_KEY` |
|
| 128 |
+
| DeepSeek | DeepSeek Chat | `DEEPSEEK_API_KEY` |
|
| 129 |
+
|
| 130 |
+
### Supported Programming Languages
|
| 131 |
+
|
| 132 |
+
- Python
|
| 133 |
+
- JavaScript
|
| 134 |
+
- Java
|
| 135 |
+
- C++
|
| 136 |
+
- C#
|
| 137 |
+
- Go
|
| 138 |
+
- Rust
|
| 139 |
+
- And more (auto-detection available)
|
| 140 |
+
|
| 141 |
+
## 🚀 Deployment
|
| 142 |
+
|
| 143 |
+
### Deploy to Render
|
| 144 |
+
|
| 145 |
+
1. Fork this repository
|
| 146 |
+
2. Create a new Web Service on [Render](https://render.com)
|
| 147 |
+
3. Connect your GitHub repository
|
| 148 |
+
4. Configure environment variables in Render dashboard
|
| 149 |
+
5. Deploy with these settings:
|
| 150 |
+
- **Build Command**: `pip install -r requirements.txt`
|
| 151 |
+
- **Start Command**: `streamlit run app.py --server.port=$PORT --server.address=0.0.0.0`
|
| 152 |
+
|
| 153 |
+
### Deploy to Heroku
|
| 154 |
+
|
| 155 |
+
1. Install the Heroku CLI
|
| 156 |
+
2. Create a `Procfile`:
|
| 157 |
+
```
|
| 158 |
+
web: streamlit run app.py --server.port=$PORT --server.address=0.0.0.0
|
| 159 |
+
```
|
| 160 |
+
3. Deploy:
|
| 161 |
+
```bash
|
| 162 |
+
heroku create your-app-name
|
| 163 |
+
heroku config:set OPENAI_API_KEY=your_key_here
|
| 164 |
+
heroku config:set ANTHROPIC_API_KEY=your_key_here
|
| 165 |
+
# ... add other API keys
|
| 166 |
+
git push heroku main
|
| 167 |
+
```
|
| 168 |
+
|
| 169 |
+
### Deploy to Railway
|
| 170 |
+
|
| 171 |
+
1. Connect your GitHub repository to Railway
|
| 172 |
+
2. Set environment variables in Railway dashboard
|
| 173 |
+
3. Deploy automatically on push
|
| 174 |
+
|
| 175 |
+
## 🧪 Development
|
| 176 |
+
|
| 177 |
+
### Running Tests
|
| 178 |
+
```bash
|
| 179 |
+
python -m pytest tests/
|
| 180 |
+
```
|
| 181 |
+
|
| 182 |
+
### Code Formatting
|
| 183 |
+
```bash
|
| 184 |
+
black analyzer/ app.py
|
| 185 |
+
```
|
| 186 |
+
|
| 187 |
+
### Type Checking
|
| 188 |
+
```bash
|
| 189 |
+
mypy analyzer/
|
| 190 |
+
```
|
| 191 |
+
|
| 192 |
+
## 📊 Analysis Output
|
| 193 |
+
|
| 194 |
+
The tool provides structured analysis including:
|
| 195 |
+
|
| 196 |
+
- **Quality Score**: 0-100 rating of code quality
|
| 197 |
+
- **Summary**: Brief description of the code's purpose
|
| 198 |
+
- **Strengths**: What the code does well
|
| 199 |
+
- **Issues**: Potential bugs and problems
|
| 200 |
+
- **Suggestions**: Specific improvement recommendations
|
| 201 |
+
- **Security Concerns**: Potential security vulnerabilities
|
| 202 |
+
- **Performance Notes**: Performance optimization opportunities
|
| 203 |
+
|
| 204 |
+
## 🤝 Contributing
|
| 205 |
+
|
| 206 |
+
1. Fork the repository
|
| 207 |
+
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
|
| 208 |
+
3. Commit your changes (`git commit -m 'Add amazing feature'`)
|
| 209 |
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
| 210 |
+
5. Open a Pull Request
|
| 211 |
+
|
| 212 |
+
## 📝 License
|
| 213 |
+
|
| 214 |
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
| 215 |
+
|
| 216 |
+
## 🙏 Acknowledgments
|
| 217 |
+
|
| 218 |
+
- [Streamlit](https://streamlit.io/) for the amazing framework
|
| 219 |
+
- [OpenAI](https://openai.com/) for GPT models
|
| 220 |
+
- [Anthropic](https://anthropic.com/) for Claude
|
| 221 |
+
- [Google](https://ai.google.dev/) for Gemini
|
| 222 |
+
- [DeepSeek](https://www.deepseek.com/) for DeepSeek Coder
|
| 223 |
+
|
| 224 |
+
## 📞 Support
|
| 225 |
+
|
| 226 |
+
If you encounter any issues or have questions:
|
| 227 |
+
|
| 228 |
+
1. Check the [Issues](https://github.com/yourusername/llm-code-analyzer/issues) page
|
| 229 |
+
2. Create a new issue with detailed information
|
| 230 |
+
3. Contact the maintainers
|
| 231 |
+
|
| 232 |
+
---
|
| 233 |
+
|
| 234 |
+
**Built with ❤️ by [Your Name](https://github.com/yourusername)**
|
analyzer/__init__.py
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from .code_analyzer import CodeAnalyzer
|
| 2 |
+
from .llm_clients import LLMClientManager
|
| 3 |
+
|
| 4 |
+
__all__ = ['CodeAnalyzer', 'LLMClientManager']
|
analyzer/code_analyzer.py
ADDED
|
@@ -0,0 +1,335 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Dict, Any, List, Optional
|
| 2 |
+
import time
|
| 3 |
+
import requests
|
| 4 |
+
import os
|
| 5 |
+
import re
|
| 6 |
+
from .llm_clients import LLMClientManager, LLMResponse
|
| 7 |
+
from .prompts import get_code_analysis_prompt, get_comparison_prompt, get_github_analysis_prompt
|
| 8 |
+
from .utils import detect_language, parse_analysis_result
|
| 9 |
+
|
| 10 |
+
class CodeAnalyzer:
|
| 11 |
+
"""Main code analysis engine with GitHub integration."""
|
| 12 |
+
|
| 13 |
+
def __init__(self):
|
| 14 |
+
self.llm_manager = LLMClientManager()
|
| 15 |
+
self.available_models = self.llm_manager.get_available_models()
|
| 16 |
+
|
| 17 |
+
def analyze_code(self, code: str, model: str, language: Optional[str] = None) -> Dict[str, Any]:
|
| 18 |
+
"""Analyze code using a specific model with focused output."""
|
| 19 |
+
start_time = time.time()
|
| 20 |
+
|
| 21 |
+
# Detect language if not provided
|
| 22 |
+
if not language:
|
| 23 |
+
language = detect_language(code)
|
| 24 |
+
|
| 25 |
+
# Generate focused prompt
|
| 26 |
+
prompt = get_code_analysis_prompt(code, language)
|
| 27 |
+
|
| 28 |
+
# Query LLM
|
| 29 |
+
response = self.llm_manager.query(model, prompt)
|
| 30 |
+
|
| 31 |
+
# Process response
|
| 32 |
+
if response.success:
|
| 33 |
+
analysis = parse_analysis_result(response.content)
|
| 34 |
+
analysis['raw_response'] = response.content
|
| 35 |
+
else:
|
| 36 |
+
analysis = {
|
| 37 |
+
'error': response.error,
|
| 38 |
+
'quality_score': 0,
|
| 39 |
+
'summary': f"Analysis failed: {response.error}",
|
| 40 |
+
'bugs': [],
|
| 41 |
+
'quality_issues': [],
|
| 42 |
+
'security_vulnerabilities': [],
|
| 43 |
+
'quick_fixes': [],
|
| 44 |
+
# Legacy fields
|
| 45 |
+
'strengths': [],
|
| 46 |
+
'issues': [],
|
| 47 |
+
'suggestions': [],
|
| 48 |
+
'security_concerns': [],
|
| 49 |
+
'performance_notes': []
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
# Add metadata
|
| 53 |
+
analysis['model'] = response.model
|
| 54 |
+
analysis['language'] = language
|
| 55 |
+
analysis['execution_time'] = round(time.time() - start_time, 2)
|
| 56 |
+
analysis['code_length'] = len(code)
|
| 57 |
+
analysis['line_count'] = len(code.splitlines())
|
| 58 |
+
|
| 59 |
+
return analysis
|
| 60 |
+
|
| 61 |
+
def analyze_github_repo(self, repo_url: str, model: str = None) -> Dict[str, Any]:
|
| 62 |
+
"""Analyze a GitHub repository."""
|
| 63 |
+
start_time = time.time()
|
| 64 |
+
|
| 65 |
+
# Use first available model if none specified
|
| 66 |
+
if not model or model not in self.available_models:
|
| 67 |
+
model = list(self.available_models.keys())[0]
|
| 68 |
+
|
| 69 |
+
try:
|
| 70 |
+
# Parse GitHub URL
|
| 71 |
+
if not repo_url.startswith('https://github.com/'):
|
| 72 |
+
return {'error': 'Please provide a valid GitHub repository URL'}
|
| 73 |
+
|
| 74 |
+
# Extract owner and repo
|
| 75 |
+
parts = repo_url.replace('https://github.com/', '').split('/')
|
| 76 |
+
if len(parts) < 2:
|
| 77 |
+
return {'error': 'Invalid GitHub repository URL format'}
|
| 78 |
+
|
| 79 |
+
owner, repo = parts[0], parts[1]
|
| 80 |
+
|
| 81 |
+
# Get repository structure and key files
|
| 82 |
+
repo_data = self._fetch_github_repo_data(owner, repo)
|
| 83 |
+
if 'error' in repo_data:
|
| 84 |
+
return repo_data
|
| 85 |
+
|
| 86 |
+
# Generate analysis prompt
|
| 87 |
+
prompt = get_github_analysis_prompt(
|
| 88 |
+
repo_data['structure'],
|
| 89 |
+
repo_data['main_files']
|
| 90 |
+
)
|
| 91 |
+
|
| 92 |
+
# Query LLM
|
| 93 |
+
response = self.llm_manager.query(model, prompt)
|
| 94 |
+
|
| 95 |
+
if response.success:
|
| 96 |
+
analysis = self._parse_github_analysis(response.content)
|
| 97 |
+
analysis['raw_response'] = response.content
|
| 98 |
+
analysis['repository_info'] = repo_data['info']
|
| 99 |
+
else:
|
| 100 |
+
analysis = {
|
| 101 |
+
'error': response.error,
|
| 102 |
+
'project_overview': f"Analysis failed: {response.error}",
|
| 103 |
+
'architecture_quality': [],
|
| 104 |
+
'critical_issues': [],
|
| 105 |
+
'improvement_priorities': []
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
# Add metadata
|
| 109 |
+
analysis['model'] = response.model
|
| 110 |
+
analysis['execution_time'] = round(time.time() - start_time, 2)
|
| 111 |
+
analysis['repo_url'] = repo_url
|
| 112 |
+
|
| 113 |
+
return analysis
|
| 114 |
+
|
| 115 |
+
except Exception as e:
|
| 116 |
+
return {
|
| 117 |
+
'error': f"GitHub analysis failed: {str(e)}",
|
| 118 |
+
'execution_time': round(time.time() - start_time, 2)
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
def _fetch_github_repo_data(self, owner: str, repo: str) -> Dict[str, Any]:
|
| 122 |
+
"""Fetch repository data from GitHub API."""
|
| 123 |
+
try:
|
| 124 |
+
# GitHub API endpoints
|
| 125 |
+
api_base = f"https://api.github.com/repos/{owner}/{repo}"
|
| 126 |
+
|
| 127 |
+
# Get repository info
|
| 128 |
+
headers = {}
|
| 129 |
+
if os.getenv('GITHUB_TOKEN'):
|
| 130 |
+
headers['Authorization'] = f"token {os.getenv('GITHUB_TOKEN')}"
|
| 131 |
+
|
| 132 |
+
repo_response = requests.get(api_base, headers=headers)
|
| 133 |
+
if repo_response.status_code != 200:
|
| 134 |
+
return {'error': f'Repository not found or private: {owner}/{repo}'}
|
| 135 |
+
|
| 136 |
+
repo_info = repo_response.json()
|
| 137 |
+
|
| 138 |
+
# Get file tree
|
| 139 |
+
tree_response = requests.get(f"{api_base}/git/trees/main?recursive=1", headers=headers)
|
| 140 |
+
if tree_response.status_code != 200:
|
| 141 |
+
# Try master branch
|
| 142 |
+
tree_response = requests.get(f"{api_base}/git/trees/master?recursive=1", headers=headers)
|
| 143 |
+
|
| 144 |
+
if tree_response.status_code != 200:
|
| 145 |
+
return {'error': 'Could not fetch repository structure'}
|
| 146 |
+
|
| 147 |
+
tree_data = tree_response.json()
|
| 148 |
+
|
| 149 |
+
# Build structure and get key files
|
| 150 |
+
structure = self._build_repo_structure(tree_data['tree'])
|
| 151 |
+
main_files = self._get_key_files(owner, repo, tree_data['tree'], headers)
|
| 152 |
+
|
| 153 |
+
return {
|
| 154 |
+
'info': {
|
| 155 |
+
'name': repo_info['name'],
|
| 156 |
+
'description': repo_info.get('description', 'No description'),
|
| 157 |
+
'language': repo_info.get('language', 'Unknown'),
|
| 158 |
+
'stars': repo_info.get('stargazers_count', 0),
|
| 159 |
+
'forks': repo_info.get('forks_count', 0),
|
| 160 |
+
'size': repo_info.get('size', 0)
|
| 161 |
+
},
|
| 162 |
+
'structure': structure,
|
| 163 |
+
'main_files': main_files
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
except Exception as e:
|
| 167 |
+
return {'error': f'Failed to fetch repository data: {str(e)}'}
|
| 168 |
+
|
| 169 |
+
def _build_repo_structure(self, tree: List[Dict]) -> str:
|
| 170 |
+
"""Build a readable repository structure."""
|
| 171 |
+
structure_lines = []
|
| 172 |
+
dirs = set()
|
| 173 |
+
|
| 174 |
+
for item in tree[:50]: # Limit to first 50 items
|
| 175 |
+
if item['type'] == 'tree':
|
| 176 |
+
dirs.add(item['path'])
|
| 177 |
+
else:
|
| 178 |
+
structure_lines.append(f"📄 {item['path']}")
|
| 179 |
+
|
| 180 |
+
for dir_path in sorted(dirs):
|
| 181 |
+
structure_lines.append(f"📁 {dir_path}/")
|
| 182 |
+
|
| 183 |
+
return '\n'.join(structure_lines[:30]) # Limit output
|
| 184 |
+
|
| 185 |
+
def _get_key_files(self, owner: str, repo: str, tree: List[Dict], headers: Dict) -> str:
|
| 186 |
+
"""Get content of key files like README, main source files."""
|
| 187 |
+
key_files = []
|
| 188 |
+
|
| 189 |
+
# Priority files to analyze
|
| 190 |
+
priority_patterns = [
|
| 191 |
+
'README.md', 'readme.md', 'README.txt',
|
| 192 |
+
'package.json', 'requirements.txt', 'Cargo.toml', 'go.mod',
|
| 193 |
+
'main.py', 'index.js', 'main.js', 'app.py', 'server.js'
|
| 194 |
+
]
|
| 195 |
+
|
| 196 |
+
for item in tree:
|
| 197 |
+
if item['type'] == 'blob':
|
| 198 |
+
filename = item['path'].split('/')[-1]
|
| 199 |
+
|
| 200 |
+
# Check if it's a priority file
|
| 201 |
+
if filename in priority_patterns or any(
|
| 202 |
+
pattern in filename.lower() for pattern in ['main', 'index', 'app']
|
| 203 |
+
):
|
| 204 |
+
try:
|
| 205 |
+
file_response = requests.get(
|
| 206 |
+
f"https://api.github.com/repos/{owner}/{repo}/contents/{item['path']}",
|
| 207 |
+
headers=headers
|
| 208 |
+
)
|
| 209 |
+
if file_response.status_code == 200:
|
| 210 |
+
file_data = file_response.json()
|
| 211 |
+
if file_data.get('encoding') == 'base64':
|
| 212 |
+
import base64
|
| 213 |
+
content = base64.b64decode(file_data['content']).decode('utf-8', errors='ignore')
|
| 214 |
+
key_files.append(f"\n--- {item['path']} ---\n{content[:1000]}") # First 1000 chars
|
| 215 |
+
except:
|
| 216 |
+
continue
|
| 217 |
+
|
| 218 |
+
if len(key_files) >= 5: # Limit to 5 key files
|
| 219 |
+
break
|
| 220 |
+
|
| 221 |
+
return '\n'.join(key_files)
|
| 222 |
+
|
| 223 |
+
def _parse_github_analysis(self, text: str) -> Dict[str, Any]:
|
| 224 |
+
"""Parse GitHub repository analysis results."""
|
| 225 |
+
result = {
|
| 226 |
+
'project_overview': '',
|
| 227 |
+
'architecture_quality': [],
|
| 228 |
+
'critical_issues': [],
|
| 229 |
+
'improvement_priorities': []
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
sections = {
|
| 233 |
+
'project_overview': r'(?:PROJECT_OVERVIEW|project\s+overview)[:\s]*(.+?)(?=\n\s*(?:\d+\.|[A-Z_]+:)|$)',
|
| 234 |
+
'architecture_quality': r'(?:ARCHITECTURE_QUALITY|architecture|structure)[:\s]*(.+?)(?=\n\s*(?:\d+\.|[A-Z_]+:)|$)',
|
| 235 |
+
'critical_issues': r'(?:CRITICAL_ISSUES|critical|major\s+issue)[:\s]*(.+?)(?=\n\s*(?:\d+\.|[A-Z_]+:)|$)',
|
| 236 |
+
'improvement_priorities': r'(?:IMPROVEMENT_PRIORITIES|improvement|priorit)[:\s]*(.+?)(?=\n\s*(?:\d+\.|[A-Z_]+:)|$)'
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
for key, pattern in sections.items():
|
| 240 |
+
match = re.search(pattern, text, re.IGNORECASE | re.DOTALL)
|
| 241 |
+
if match:
|
| 242 |
+
content = match.group(1).strip()
|
| 243 |
+
|
| 244 |
+
if key == 'project_overview':
|
| 245 |
+
# Clean project overview
|
| 246 |
+
clean_overview = content.split('\n')[0].strip()
|
| 247 |
+
clean_overview = re.sub(r'#+\s*', '', clean_overview) # Remove ### symbols
|
| 248 |
+
clean_overview = re.sub(r'^\*+\s*', '', clean_overview) # Remove ** symbols
|
| 249 |
+
result[key] = clean_overview
|
| 250 |
+
else:
|
| 251 |
+
# Extract and clean bullet points
|
| 252 |
+
items = []
|
| 253 |
+
lines = content.split('\n')
|
| 254 |
+
for line in lines:
|
| 255 |
+
line = line.strip()
|
| 256 |
+
if line and not line.lower() in ['none', 'none found']:
|
| 257 |
+
# Clean up markdown symbols and extra characters
|
| 258 |
+
line = re.sub(r'#+\s*', '', line) # Remove ### symbols
|
| 259 |
+
line = re.sub(r'^\*+\s*', '', line) # Remove ** symbols
|
| 260 |
+
line = re.sub(r'^[-•*]\s*', '', line) # Remove bullet markers
|
| 261 |
+
line = re.sub(r'^[:\-\s]*', '', line) # Remove colons and dashes
|
| 262 |
+
|
| 263 |
+
if len(line) > 10: # Only include substantial content
|
| 264 |
+
items.append(line)
|
| 265 |
+
|
| 266 |
+
# If no structured items found, try to extract sentences
|
| 267 |
+
if not items and content.strip():
|
| 268 |
+
sentences = re.split(r'[.!?]+', content)
|
| 269 |
+
for sentence in sentences:
|
| 270 |
+
clean_sentence = sentence.strip()
|
| 271 |
+
clean_sentence = re.sub(r'#+\s*', '', clean_sentence) # Remove ### symbols
|
| 272 |
+
clean_sentence = re.sub(r'^\*+\s*', '', clean_sentence) # Remove ** symbols
|
| 273 |
+
if clean_sentence and len(clean_sentence) > 15:
|
| 274 |
+
items.append(clean_sentence)
|
| 275 |
+
|
| 276 |
+
result[key] = items[:4] # Limit to 4 items per section
|
| 277 |
+
|
| 278 |
+
return result
|
| 279 |
+
|
| 280 |
+
def analyze_with_all_models(self, code: str, language: Optional[str] = None) -> Dict[str, Dict[str, Any]]:
|
| 281 |
+
"""Analyze code using all available models."""
|
| 282 |
+
results = {}
|
| 283 |
+
|
| 284 |
+
for model_key in self.available_models:
|
| 285 |
+
results[model_key] = self.analyze_code(code, model_key, language)
|
| 286 |
+
|
| 287 |
+
return results
|
| 288 |
+
|
| 289 |
+
def compare_analyses(self, results: Dict[str, Dict[str, Any]]) -> Dict[str, Any]:
|
| 290 |
+
"""Compare results from different models with focus on critical issues."""
|
| 291 |
+
comparison = {
|
| 292 |
+
'average_score': 0,
|
| 293 |
+
'consensus_bugs': [],
|
| 294 |
+
'consensus_security': [],
|
| 295 |
+
'model_scores': {},
|
| 296 |
+
'best_model': None,
|
| 297 |
+
'analysis_time': sum(r['execution_time'] for r in results.values())
|
| 298 |
+
}
|
| 299 |
+
|
| 300 |
+
# Calculate average score and find best model
|
| 301 |
+
scores = []
|
| 302 |
+
for model, result in results.items():
|
| 303 |
+
if 'error' not in result:
|
| 304 |
+
score = result['quality_score']
|
| 305 |
+
scores.append(score)
|
| 306 |
+
comparison['model_scores'][model] = score
|
| 307 |
+
|
| 308 |
+
if scores:
|
| 309 |
+
comparison['average_score'] = round(sum(scores) / len(scores), 1)
|
| 310 |
+
best_model = max(comparison['model_scores'].items(), key=lambda x: x[1])
|
| 311 |
+
comparison['best_model'] = best_model[0]
|
| 312 |
+
|
| 313 |
+
# Find consensus on critical issues
|
| 314 |
+
all_bugs = []
|
| 315 |
+
all_security = []
|
| 316 |
+
|
| 317 |
+
for result in results.values():
|
| 318 |
+
if 'error' not in result:
|
| 319 |
+
all_bugs.extend(result.get('bugs', []))
|
| 320 |
+
all_security.extend(result.get('security_vulnerabilities', []))
|
| 321 |
+
|
| 322 |
+
# Simple consensus: issues mentioned by multiple models
|
| 323 |
+
def find_consensus(items):
|
| 324 |
+
consensus = []
|
| 325 |
+
for item in items:
|
| 326 |
+
if any(item.lower() in other.lower() or other.lower() in item.lower()
|
| 327 |
+
for other in items if other != item):
|
| 328 |
+
if item not in consensus:
|
| 329 |
+
consensus.append(item)
|
| 330 |
+
return consensus[:3] # Top 3 consensus items
|
| 331 |
+
|
| 332 |
+
comparison['consensus_bugs'] = find_consensus(all_bugs)
|
| 333 |
+
comparison['consensus_security'] = find_consensus(all_security)
|
| 334 |
+
|
| 335 |
+
return comparison
|
analyzer/llm_clients.py
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from typing import Optional, Dict, Any
|
| 3 |
+
from dataclasses import dataclass
|
| 4 |
+
import openai
|
| 5 |
+
import anthropic
|
| 6 |
+
import google.generativeai as genai
|
| 7 |
+
from dotenv import load_dotenv
|
| 8 |
+
|
| 9 |
+
load_dotenv()
|
| 10 |
+
|
| 11 |
+
@dataclass
|
| 12 |
+
class LLMResponse:
|
| 13 |
+
content: str
|
| 14 |
+
model: str
|
| 15 |
+
success: bool
|
| 16 |
+
error: Optional[str] = None
|
| 17 |
+
|
| 18 |
+
class LLMClientManager:
|
| 19 |
+
"""Manages connections to different LLM providers."""
|
| 20 |
+
|
| 21 |
+
def __init__(self):
|
| 22 |
+
self.clients = {}
|
| 23 |
+
self._initialize_clients()
|
| 24 |
+
|
| 25 |
+
def _initialize_clients(self):
|
| 26 |
+
"""Initialize available LLM clients based on API keys."""
|
| 27 |
+
# OpenAI
|
| 28 |
+
if os.getenv("OPENAI_API_KEY"):
|
| 29 |
+
self.clients["openai"] = openai.OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
|
| 30 |
+
|
| 31 |
+
# Anthropic
|
| 32 |
+
if os.getenv("ANTHROPIC_API_KEY"):
|
| 33 |
+
self.clients["anthropic"] = anthropic.Anthropic(api_key=os.getenv("ANTHROPIC_API_KEY"))
|
| 34 |
+
|
| 35 |
+
# Google Gemini
|
| 36 |
+
if os.getenv("GEMINI_API_KEY"):
|
| 37 |
+
genai.configure(api_key=os.getenv("GEMINI_API_KEY"))
|
| 38 |
+
self.clients["gemini"] = genai.GenerativeModel('gemini-pro')
|
| 39 |
+
|
| 40 |
+
# DeepSeek (uses OpenAI-compatible API)
|
| 41 |
+
if os.getenv("DEEPSEEK_API_KEY"):
|
| 42 |
+
self.clients["deepseek"] = openai.OpenAI(
|
| 43 |
+
api_key=os.getenv("DEEPSEEK_API_KEY"),
|
| 44 |
+
base_url="https://api.deepseek.com/v1"
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
def get_available_models(self) -> Dict[str, str]:
|
| 48 |
+
"""Return available models with display names."""
|
| 49 |
+
models = {}
|
| 50 |
+
if "openai" in self.clients:
|
| 51 |
+
models["openai"] = "OpenAI GPT-4"
|
| 52 |
+
if "anthropic" in self.clients:
|
| 53 |
+
models["anthropic"] = "Claude 3"
|
| 54 |
+
if "gemini" in self.clients:
|
| 55 |
+
models["gemini"] = "Google Gemini"
|
| 56 |
+
if "deepseek" in self.clients:
|
| 57 |
+
models["deepseek"] = "DeepSeek Coder"
|
| 58 |
+
return models
|
| 59 |
+
|
| 60 |
+
def query(self, model: str, prompt: str, temperature: float = 0.1) -> LLMResponse:
|
| 61 |
+
"""Query a specific LLM model."""
|
| 62 |
+
try:
|
| 63 |
+
if model == "openai" and "openai" in self.clients:
|
| 64 |
+
response = self.clients["openai"].chat.completions.create(
|
| 65 |
+
model="gpt-4o-mini",
|
| 66 |
+
messages=[{"role": "user", "content": prompt}],
|
| 67 |
+
temperature=temperature
|
| 68 |
+
)
|
| 69 |
+
return LLMResponse(
|
| 70 |
+
content=response.choices[0].message.content,
|
| 71 |
+
model="OpenAI GPT-4",
|
| 72 |
+
success=True
|
| 73 |
+
)
|
| 74 |
+
|
| 75 |
+
elif model == "anthropic" and "anthropic" in self.clients:
|
| 76 |
+
response = self.clients["anthropic"].messages.create(
|
| 77 |
+
model="claude-3-haiku-20240307",
|
| 78 |
+
messages=[{"role": "user", "content": prompt}],
|
| 79 |
+
max_tokens=2000,
|
| 80 |
+
temperature=temperature
|
| 81 |
+
)
|
| 82 |
+
return LLMResponse(
|
| 83 |
+
content=response.content[0].text,
|
| 84 |
+
model="Claude 3 Haiku",
|
| 85 |
+
success=True
|
| 86 |
+
)
|
| 87 |
+
|
| 88 |
+
elif model == "gemini" and "gemini" in self.clients:
|
| 89 |
+
response = self.clients["gemini"].generate_content(prompt)
|
| 90 |
+
return LLMResponse(
|
| 91 |
+
content=response.text,
|
| 92 |
+
model="Google Gemini",
|
| 93 |
+
success=True
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
elif model == "deepseek" and "deepseek" in self.clients:
|
| 97 |
+
try:
|
| 98 |
+
response = self.clients["deepseek"].chat.completions.create(
|
| 99 |
+
model="deepseek-coder",
|
| 100 |
+
messages=[{"role": "user", "content": prompt}],
|
| 101 |
+
temperature=temperature
|
| 102 |
+
)
|
| 103 |
+
return LLMResponse(
|
| 104 |
+
content=response.choices[0].message.content,
|
| 105 |
+
model="DeepSeek Coder",
|
| 106 |
+
success=True
|
| 107 |
+
)
|
| 108 |
+
except Exception as deepseek_error:
|
| 109 |
+
# Try with alternative model name if the first one fails
|
| 110 |
+
try:
|
| 111 |
+
response = self.clients["deepseek"].chat.completions.create(
|
| 112 |
+
model="deepseek-chat",
|
| 113 |
+
messages=[{"role": "user", "content": prompt}],
|
| 114 |
+
temperature=temperature
|
| 115 |
+
)
|
| 116 |
+
return LLMResponse(
|
| 117 |
+
content=response.choices[0].message.content,
|
| 118 |
+
model="DeepSeek Coder",
|
| 119 |
+
success=True
|
| 120 |
+
)
|
| 121 |
+
except Exception as second_error:
|
| 122 |
+
return LLMResponse(
|
| 123 |
+
content="",
|
| 124 |
+
model="DeepSeek Coder",
|
| 125 |
+
success=False,
|
| 126 |
+
error=f"DeepSeek API Error: {str(deepseek_error)}. Also tried alternative model: {str(second_error)}"
|
| 127 |
+
)
|
| 128 |
+
|
| 129 |
+
else:
|
| 130 |
+
return LLMResponse(
|
| 131 |
+
content="",
|
| 132 |
+
model=model,
|
| 133 |
+
success=False,
|
| 134 |
+
error=f"Model {model} not available or not configured"
|
| 135 |
+
)
|
| 136 |
+
|
| 137 |
+
except Exception as e:
|
| 138 |
+
return LLMResponse(
|
| 139 |
+
content="",
|
| 140 |
+
model=model,
|
| 141 |
+
success=False,
|
| 142 |
+
error=str(e)
|
| 143 |
+
)
|
analyzer/prompts.py
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
def get_code_analysis_prompt(code: str, language: str = "auto-detect") -> str:
|
| 2 |
+
"""Generate a focused prompt for practical code analysis."""
|
| 3 |
+
return f"""
|
| 4 |
+
You are an expert code reviewer. Analyze this {language} code for practical issues that matter to developers.
|
| 5 |
+
|
| 6 |
+
Code to analyze:
|
| 7 |
+
{code}
|
| 8 |
+
|
| 9 |
+
Provide a focused analysis with complete, readable sentences. Do NOT use markdown symbols like ### or ** in your response.
|
| 10 |
+
|
| 11 |
+
1. QUALITY_SCORE: Rate 0-100 (consider bugs, readability, maintainability)
|
| 12 |
+
|
| 13 |
+
2. SUMMARY: One complete sentence describing what this code does
|
| 14 |
+
|
| 15 |
+
3. BUG_DETECTION:
|
| 16 |
+
- List actual bugs or logical errors found
|
| 17 |
+
- Include potential crashes or exceptions
|
| 18 |
+
- Mention edge cases not handled
|
| 19 |
+
(Write complete sentences, skip if none found)
|
| 20 |
+
|
| 21 |
+
4. CODE_QUALITY_ISSUES:
|
| 22 |
+
- Poor naming or structure problems
|
| 23 |
+
- Code readability issues
|
| 24 |
+
- Maintainability concerns
|
| 25 |
+
(Focus on practical fixes, write complete sentences)
|
| 26 |
+
|
| 27 |
+
5. SECURITY_VULNERABILITIES:
|
| 28 |
+
- Injection risks (SQL, XSS, etc.)
|
| 29 |
+
- Insecure data handling
|
| 30 |
+
- Authentication/authorization flaws
|
| 31 |
+
(Only include actual security risks, write complete sentences)
|
| 32 |
+
|
| 33 |
+
6. QUICK_FIXES:
|
| 34 |
+
- Top 3 specific improvements with examples
|
| 35 |
+
- Focus on high-impact, easy changes
|
| 36 |
+
- Write complete actionable sentences
|
| 37 |
+
|
| 38 |
+
Format each section as clear, complete sentences. Be specific and actionable. Skip sections if no issues found.
|
| 39 |
+
"""
|
| 40 |
+
|
| 41 |
+
def get_github_analysis_prompt(repo_structure: str, main_files: str) -> str:
|
| 42 |
+
"""Generate prompt for GitHub repository analysis."""
|
| 43 |
+
return f"""
|
| 44 |
+
Analyze this GitHub repository structure and key files. Provide clear, complete analysis without using markdown symbols.
|
| 45 |
+
|
| 46 |
+
Repository Structure:
|
| 47 |
+
{repo_structure}
|
| 48 |
+
|
| 49 |
+
Main Files Content:
|
| 50 |
+
{main_files}
|
| 51 |
+
|
| 52 |
+
Provide analysis focusing on:
|
| 53 |
+
|
| 54 |
+
1. PROJECT_OVERVIEW: Write one clear sentence about what this project does
|
| 55 |
+
|
| 56 |
+
2. ARCHITECTURE_QUALITY:
|
| 57 |
+
- Project structure assessment (write complete sentences)
|
| 58 |
+
- Code organization quality (write complete sentences)
|
| 59 |
+
- Missing important files like tests, docs, etc. (write complete sentences)
|
| 60 |
+
|
| 61 |
+
3. CRITICAL_ISSUES:
|
| 62 |
+
- Security vulnerabilities across files (write complete sentences)
|
| 63 |
+
- Major bugs or design flaws (write complete sentences)
|
| 64 |
+
- Dependencies/configuration problems (write complete sentences)
|
| 65 |
+
|
| 66 |
+
4. IMPROVEMENT_PRIORITIES:
|
| 67 |
+
- Top 5 specific things to fix first (write complete sentences)
|
| 68 |
+
- Missing features or best practices (write complete sentences)
|
| 69 |
+
- Code quality improvements needed (write complete sentences)
|
| 70 |
+
|
| 71 |
+
Write clear, complete sentences without markdown symbols. Be practical and focus on actionable feedback for the repository owner.
|
| 72 |
+
"""
|
| 73 |
+
|
| 74 |
+
def get_comparison_prompt(code: str, language: str = "auto-detect") -> str:
|
| 75 |
+
"""Generate a prompt for multi-model comparison."""
|
| 76 |
+
return f"""
|
| 77 |
+
As an expert code reviewer, analyze this {language} code:
|
| 78 |
+
{code}
|
| 79 |
+
|
| 80 |
+
Provide a concise but thorough analysis covering:
|
| 81 |
+
- Main functionality
|
| 82 |
+
- Code quality (rate 0-100)
|
| 83 |
+
- Critical issues
|
| 84 |
+
- Top 3 improvements
|
| 85 |
+
- Security/performance concerns
|
| 86 |
+
|
| 87 |
+
Be specific and actionable in your feedback.
|
| 88 |
+
"""
|
analyzer/utils.py
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import re
|
| 2 |
+
from typing import Dict, Any, Tuple
|
| 3 |
+
|
| 4 |
+
def detect_language(code: str) -> str:
|
| 5 |
+
"""Simple language detection based on syntax patterns."""
|
| 6 |
+
patterns = {
|
| 7 |
+
'python': [r'def\s+\w+\(', r'import\s+\w+', r'if\s+__name__\s*==\s*["\']__main__["\']'],
|
| 8 |
+
'javascript': [r'function\s+\w+\(', r'const\s+\w+\s*=', r'console\.log\('],
|
| 9 |
+
'java': [r'public\s+class\s+\w+', r'public\s+static\s+void\s+main'],
|
| 10 |
+
'cpp': [r'#include\s*<\w+>', r'int\s+main\s*\(', r'std::'],
|
| 11 |
+
'csharp': [r'using\s+System', r'namespace\s+\w+', r'public\s+class\s+\w+'],
|
| 12 |
+
'go': [r'package\s+\w+', r'func\s+\w+\(', r'import\s+\('],
|
| 13 |
+
'rust': [r'fn\s+main\s*\(', r'use\s+\w+', r'let\s+mut\s+\w+'],
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
for lang, patterns_list in patterns.items():
|
| 17 |
+
for pattern in patterns_list:
|
| 18 |
+
if re.search(pattern, code):
|
| 19 |
+
return lang
|
| 20 |
+
|
| 21 |
+
return 'unknown'
|
| 22 |
+
|
| 23 |
+
def parse_analysis_result(text: str) -> Dict[str, Any]:
|
| 24 |
+
"""Parse LLM response into structured format with new focused categories."""
|
| 25 |
+
result = {
|
| 26 |
+
'quality_score': 75, # default
|
| 27 |
+
'summary': '',
|
| 28 |
+
'bugs': [],
|
| 29 |
+
'quality_issues': [],
|
| 30 |
+
'security_vulnerabilities': [],
|
| 31 |
+
'quick_fixes': [],
|
| 32 |
+
# Legacy fields for compatibility
|
| 33 |
+
'strengths': [],
|
| 34 |
+
'issues': [],
|
| 35 |
+
'suggestions': [],
|
| 36 |
+
'security_concerns': [],
|
| 37 |
+
'performance_notes': []
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
# Extract quality score
|
| 41 |
+
score_patterns = [
|
| 42 |
+
r'(?:QUALITY_SCORE|quality[_\s]*score)[:\s]*(\d+)(?:/100)?',
|
| 43 |
+
r'(?:score|rating)[:\s]*(\d+)(?:/100)?'
|
| 44 |
+
]
|
| 45 |
+
|
| 46 |
+
for pattern in score_patterns:
|
| 47 |
+
score_match = re.search(pattern, text, re.IGNORECASE)
|
| 48 |
+
if score_match:
|
| 49 |
+
result['quality_score'] = int(score_match.group(1))
|
| 50 |
+
break
|
| 51 |
+
|
| 52 |
+
# Extract sections with new focused format
|
| 53 |
+
sections = {
|
| 54 |
+
# New focused sections
|
| 55 |
+
'summary': r'(?:SUMMARY|summary)[:\s]*(.+?)(?=\n\s*(?:\d+\.|[A-Z_]+:)|$)',
|
| 56 |
+
'bugs': r'(?:BUG_DETECTION|bug[s]?|logical\s+error)[:\s]*(.+?)(?=\n\s*(?:\d+\.|[A-Z_]+:)|$)',
|
| 57 |
+
'quality_issues': r'(?:CODE_QUALITY_ISSUES|quality\s+issue|readability)[:\s]*(.+?)(?=\n\s*(?:\d+\.|[A-Z_]+:)|$)',
|
| 58 |
+
'security_vulnerabilities': r'(?:SECURITY_VULNERABILITIES|security\s+vulnerabilit|security\s+risk)[:\s]*(.+?)(?=\n\s*(?:\d+\.|[A-Z_]+:)|$)',
|
| 59 |
+
'quick_fixes': r'(?:QUICK_FIXES|improvement|suggestion)[s]?[:\s]*(.+?)(?=\n\s*(?:\d+\.|[A-Z_]+:)|$)',
|
| 60 |
+
|
| 61 |
+
# Legacy sections for backward compatibility
|
| 62 |
+
'strengths': r'(?:strength|positive|good)[s]?[:\s]*(.+?)(?=\n\s*(?:\d+\.|[A-Z_]+:)|$)',
|
| 63 |
+
'issues': r'(?:issue|problem)[s]?[:\s]*(.+?)(?=\n\s*(?:\d+\.|[A-Z_]+:)|$)',
|
| 64 |
+
'suggestions': r'(?:suggestion|recommendation)[s]?[:\s]*(.+?)(?=\n\s*(?:\d+\.|[A-Z_]+:)|$)',
|
| 65 |
+
'security_concerns': r'(?:security\s+concern)[s]?[:\s]*(.+?)(?=\n\s*(?:\d+\.|[A-Z_]+:)|$)',
|
| 66 |
+
'performance_notes': r'(?:performance|optimization)[:\s]*(.+?)(?=\n\s*(?:\d+\.|[A-Z_]+:)|$)'
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
for key, pattern in sections.items():
|
| 70 |
+
match = re.search(pattern, text, re.IGNORECASE | re.DOTALL)
|
| 71 |
+
if match:
|
| 72 |
+
content = match.group(1).strip()
|
| 73 |
+
if key == 'summary':
|
| 74 |
+
# Clean up summary and remove markdown symbols
|
| 75 |
+
clean_summary = re.sub(r'^[:\-\s]*', '', content).split('\n')[0].strip()
|
| 76 |
+
clean_summary = re.sub(r'#+\s*', '', clean_summary) # Remove ### symbols
|
| 77 |
+
result[key] = clean_summary
|
| 78 |
+
else:
|
| 79 |
+
# Extract bullet points and clean them
|
| 80 |
+
items = []
|
| 81 |
+
|
| 82 |
+
# Try different bullet point patterns
|
| 83 |
+
bullet_patterns = [
|
| 84 |
+
r'^\s*[-•*]\s*(.+)$', # Standard bullets
|
| 85 |
+
r'^\s*\d+\.\s*(.+)$', # Numbered lists
|
| 86 |
+
r'^\s*[◦▪▫]\s*(.+)$', # Alternative bullets
|
| 87 |
+
]
|
| 88 |
+
|
| 89 |
+
lines = content.split('\n')
|
| 90 |
+
for line in lines:
|
| 91 |
+
line = line.strip()
|
| 92 |
+
if not line or line.lower() in ['none', 'none found', 'skip if none found']:
|
| 93 |
+
continue
|
| 94 |
+
|
| 95 |
+
# Clean up markdown symbols and extra characters
|
| 96 |
+
line = re.sub(r'#+\s*', '', line) # Remove ### symbols
|
| 97 |
+
line = re.sub(r'^\*+\s*', '', line) # Remove ** symbols
|
| 98 |
+
line = re.sub(r'^[:\-\s]*', '', line) # Remove colons and dashes
|
| 99 |
+
|
| 100 |
+
# Try each bullet pattern
|
| 101 |
+
item_found = False
|
| 102 |
+
for bullet_pattern in bullet_patterns:
|
| 103 |
+
bullet_match = re.match(bullet_pattern, line)
|
| 104 |
+
if bullet_match:
|
| 105 |
+
clean_item = bullet_match.group(1).strip()
|
| 106 |
+
clean_item = re.sub(r'#+\s*', '', clean_item) # Remove ### from items
|
| 107 |
+
if clean_item and len(clean_item) > 5: # Avoid very short items
|
| 108 |
+
items.append(clean_item)
|
| 109 |
+
item_found = True
|
| 110 |
+
break
|
| 111 |
+
|
| 112 |
+
# If no bullet pattern, treat as potential item if it's substantial
|
| 113 |
+
if not item_found and len(line) > 15: # Increased minimum length
|
| 114 |
+
clean_line = re.sub(r'#+\s*', '', line) # Remove ### symbols
|
| 115 |
+
items.append(clean_line)
|
| 116 |
+
|
| 117 |
+
# If no bullet points found, split by sentences and clean
|
| 118 |
+
if not items and content.strip():
|
| 119 |
+
sentences = re.split(r'[.!?]+', content)
|
| 120 |
+
for sentence in sentences:
|
| 121 |
+
clean_sentence = sentence.strip()
|
| 122 |
+
clean_sentence = re.sub(r'#+\s*', '', clean_sentence) # Remove ### symbols
|
| 123 |
+
if clean_sentence and len(clean_sentence) > 15:
|
| 124 |
+
items.append(clean_sentence)
|
| 125 |
+
|
| 126 |
+
result[key] = items[:4] # Limit to 4 items per section
|
| 127 |
+
|
| 128 |
+
return result
|
| 129 |
+
|
| 130 |
+
def format_file_size(size_bytes: int) -> str:
|
| 131 |
+
"""Format file size in human-readable format."""
|
| 132 |
+
for unit in ['B', 'KB', 'MB', 'GB']:
|
| 133 |
+
if size_bytes < 1024.0:
|
| 134 |
+
return f"{size_bytes:.2f} {unit}"
|
| 135 |
+
size_bytes /= 1024.0
|
| 136 |
+
return f"{size_bytes:.2f} TB"
|
| 137 |
+
|
| 138 |
+
def validate_code(code: str, language: str) -> Dict[str, Any]:
|
| 139 |
+
"""
|
| 140 |
+
Perform basic validation on the code.
|
| 141 |
+
|
| 142 |
+
Args:
|
| 143 |
+
code (str): The code to validate
|
| 144 |
+
language (str): The programming language
|
| 145 |
+
|
| 146 |
+
Returns:
|
| 147 |
+
dict: Validation result with 'is_valid' and 'message' keys
|
| 148 |
+
"""
|
| 149 |
+
if not code.strip():
|
| 150 |
+
return {"is_valid": False, "message": "Code is empty"}
|
| 151 |
+
|
| 152 |
+
# Basic validation rules
|
| 153 |
+
validation_rules = {
|
| 154 |
+
'python': [
|
| 155 |
+
(r'^[ \t]*[^\s#]', "Code appears to have inconsistent indentation"),
|
| 156 |
+
],
|
| 157 |
+
'javascript': [
|
| 158 |
+
(r'\{[^}]*$', "Unclosed curly braces detected"),
|
| 159 |
+
(r'\([^)]*$', "Unclosed parentheses detected"),
|
| 160 |
+
],
|
| 161 |
+
'java': [
|
| 162 |
+
(r'public\s+class\s+\w+', "Should contain a public class"),
|
| 163 |
+
],
|
| 164 |
+
'cpp': [
|
| 165 |
+
(r'#include', "Should contain include statements"),
|
| 166 |
+
],
|
| 167 |
+
'c': [
|
| 168 |
+
(r'#include', "Should contain include statements"),
|
| 169 |
+
]
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
# Check for common issues
|
| 173 |
+
lines = code.split('\n')
|
| 174 |
+
|
| 175 |
+
# Check for extremely long lines
|
| 176 |
+
max_line_length = 200
|
| 177 |
+
for i, line in enumerate(lines):
|
| 178 |
+
if len(line) > max_line_length:
|
| 179 |
+
return {
|
| 180 |
+
"is_valid": False,
|
| 181 |
+
"message": f"Line {i+1} is very long ({len(line)} characters). Consider breaking it up."
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
# Language-specific validation
|
| 185 |
+
if language in validation_rules:
|
| 186 |
+
for pattern, message in validation_rules[language]:
|
| 187 |
+
if language == 'python' and pattern == r'^[ \t]*[^\s#]':
|
| 188 |
+
# Check indentation consistency for Python
|
| 189 |
+
indentation_types = set()
|
| 190 |
+
for line in lines:
|
| 191 |
+
if line.strip() and line[0] in [' ', '\t']:
|
| 192 |
+
if line.startswith(' '):
|
| 193 |
+
indentation_types.add('spaces')
|
| 194 |
+
elif line.startswith('\t'):
|
| 195 |
+
indentation_types.add('tabs')
|
| 196 |
+
|
| 197 |
+
if len(indentation_types) > 1:
|
| 198 |
+
return {"is_valid": False, "message": "Mixed tabs and spaces for indentation"}
|
| 199 |
+
|
| 200 |
+
elif not re.search(pattern, code, re.MULTILINE):
|
| 201 |
+
return {"is_valid": False, "message": message}
|
| 202 |
+
|
| 203 |
+
return {"is_valid": True, "message": "Code appears to be well-formed"}
|
| 204 |
+
|
| 205 |
+
def clean_response(response: str) -> str:
|
| 206 |
+
"""
|
| 207 |
+
Clean and format the LLM response.
|
| 208 |
+
|
| 209 |
+
Args:
|
| 210 |
+
response (str): Raw response from LLM
|
| 211 |
+
|
| 212 |
+
Returns:
|
| 213 |
+
str: Cleaned and formatted response
|
| 214 |
+
"""
|
| 215 |
+
if not response:
|
| 216 |
+
return "No response generated"
|
| 217 |
+
|
| 218 |
+
# Remove excessive whitespace
|
| 219 |
+
cleaned = re.sub(r'\n\s*\n\s*\n', '\n\n', response)
|
| 220 |
+
cleaned = cleaned.strip()
|
| 221 |
+
|
| 222 |
+
# Ensure proper markdown formatting
|
| 223 |
+
# Fix bullet points
|
| 224 |
+
cleaned = re.sub(r'^\s*[-*]\s*', '- ', cleaned, flags=re.MULTILINE)
|
| 225 |
+
|
| 226 |
+
# Fix numbered lists
|
| 227 |
+
cleaned = re.sub(r'^\s*(\d+)\.\s*', r'\1. ', cleaned, flags=re.MULTILINE)
|
| 228 |
+
|
| 229 |
+
# Ensure code blocks are properly formatted
|
| 230 |
+
cleaned = re.sub(r'```(\w+)?\s*\n', r'```\1\n', cleaned)
|
| 231 |
+
|
| 232 |
+
return cleaned
|
app.py
ADDED
|
@@ -0,0 +1,293 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import os
|
| 3 |
+
from dotenv import load_dotenv
|
| 4 |
+
from analyzer import CodeAnalyzer
|
| 5 |
+
import json
|
| 6 |
+
|
| 7 |
+
# Load environment variables
|
| 8 |
+
load_dotenv()
|
| 9 |
+
|
| 10 |
+
# Page config
|
| 11 |
+
st.set_page_config(
|
| 12 |
+
page_title="LLM Code Analyzer",
|
| 13 |
+
page_icon="🔍",
|
| 14 |
+
layout="wide",
|
| 15 |
+
initial_sidebar_state="expanded"
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
# Custom CSS for professional look
|
| 19 |
+
st.markdown("""
|
| 20 |
+
<style>
|
| 21 |
+
.main { padding-top: 2rem; }
|
| 22 |
+
.stButton > button {
|
| 23 |
+
width: 100%;
|
| 24 |
+
background-color: #0e1117;
|
| 25 |
+
border: 1px solid #262730;
|
| 26 |
+
font-weight: 500;
|
| 27 |
+
}
|
| 28 |
+
.stButton > button:hover {
|
| 29 |
+
border-color: #4a4b5e;
|
| 30 |
+
}
|
| 31 |
+
.code-editor {
|
| 32 |
+
font-family: 'Monaco', 'Menlo', monospace;
|
| 33 |
+
}
|
| 34 |
+
.metric-card {
|
| 35 |
+
background-color: #1e1e1e;
|
| 36 |
+
padding: 1rem;
|
| 37 |
+
border-radius: 0.5rem;
|
| 38 |
+
border: 1px solid #262730;
|
| 39 |
+
}
|
| 40 |
+
.analysis-section {
|
| 41 |
+
background-color: #1e1e1e;
|
| 42 |
+
padding: 1.5rem;
|
| 43 |
+
border-radius: 0.5rem;
|
| 44 |
+
margin: 1rem 0;
|
| 45 |
+
border: 1px solid #262730;
|
| 46 |
+
}
|
| 47 |
+
.quality-score {
|
| 48 |
+
font-size: 2rem;
|
| 49 |
+
font-weight: bold;
|
| 50 |
+
}
|
| 51 |
+
.model-badge {
|
| 52 |
+
background-color: #262730;
|
| 53 |
+
padding: 0.25rem 0.75rem;
|
| 54 |
+
border-radius: 1rem;
|
| 55 |
+
display: inline-block;
|
| 56 |
+
margin: 0.25rem;
|
| 57 |
+
}
|
| 58 |
+
</style>
|
| 59 |
+
""", unsafe_allow_html=True)
|
| 60 |
+
|
| 61 |
+
# Initialize analyzer
|
| 62 |
+
@st.cache_resource
|
| 63 |
+
def get_analyzer():
|
| 64 |
+
return CodeAnalyzer()
|
| 65 |
+
|
| 66 |
+
analyzer = get_analyzer()
|
| 67 |
+
|
| 68 |
+
def display_analysis_result(result: dict, model_name: str):
|
| 69 |
+
"""Display analysis result in a formatted way."""
|
| 70 |
+
if 'error' in result:
|
| 71 |
+
st.error(f"Analysis failed: {result['error']}")
|
| 72 |
+
return
|
| 73 |
+
|
| 74 |
+
# Quality score with color
|
| 75 |
+
score = result['quality_score']
|
| 76 |
+
score_color = "#00ff00" if score >= 80 else "#ffaa00" if score >= 60 else "#ff4444"
|
| 77 |
+
|
| 78 |
+
st.markdown(f"""
|
| 79 |
+
<div class="analysis-section">
|
| 80 |
+
<h3>{model_name}</h3>
|
| 81 |
+
<div style="display: flex; justify-content: space-between; align-items: center;">
|
| 82 |
+
<div>
|
| 83 |
+
<span class="quality-score" style="color: {score_color};">{score}/100</span>
|
| 84 |
+
<p style="margin: 0; color: #888;">Quality Score</p>
|
| 85 |
+
</div>
|
| 86 |
+
<div style="text-align: right;">
|
| 87 |
+
<p style="margin: 0;"><strong>Language:</strong> {result['language']}</p>
|
| 88 |
+
<p style="margin: 0;"><strong>Analysis Time:</strong> {result['execution_time']}s</p>
|
| 89 |
+
</div>
|
| 90 |
+
</div>
|
| 91 |
+
</div>
|
| 92 |
+
""", unsafe_allow_html=True)
|
| 93 |
+
|
| 94 |
+
# Summary
|
| 95 |
+
if result.get('summary'):
|
| 96 |
+
st.markdown("#### 📋 Summary")
|
| 97 |
+
st.info(result['summary'])
|
| 98 |
+
|
| 99 |
+
# Create columns for different sections
|
| 100 |
+
col1, col2 = st.columns(2)
|
| 101 |
+
|
| 102 |
+
with col1:
|
| 103 |
+
# Strengths
|
| 104 |
+
if result.get('strengths'):
|
| 105 |
+
st.markdown("#### ✅ Strengths")
|
| 106 |
+
for strength in result['strengths']:
|
| 107 |
+
st.success(f"• {strength}")
|
| 108 |
+
|
| 109 |
+
# Suggestions
|
| 110 |
+
if result.get('suggestions'):
|
| 111 |
+
st.markdown("#### 💡 Suggestions")
|
| 112 |
+
for suggestion in result['suggestions']:
|
| 113 |
+
st.info(f"• {suggestion}")
|
| 114 |
+
|
| 115 |
+
with col2:
|
| 116 |
+
# Issues
|
| 117 |
+
if result.get('issues'):
|
| 118 |
+
st.markdown("#### ⚠️ Issues")
|
| 119 |
+
for issue in result['issues']:
|
| 120 |
+
st.warning(f"• {issue}")
|
| 121 |
+
|
| 122 |
+
# Security concerns
|
| 123 |
+
if result.get('security_concerns'):
|
| 124 |
+
st.markdown("#### 🔒 Security")
|
| 125 |
+
for concern in result['security_concerns']:
|
| 126 |
+
st.error(f"• {concern}")
|
| 127 |
+
|
| 128 |
+
# Performance notes
|
| 129 |
+
if result.get('performance_notes'):
|
| 130 |
+
st.markdown("#### ⚡ Performance")
|
| 131 |
+
for note in result['performance_notes']:
|
| 132 |
+
st.info(f"• {note}")
|
| 133 |
+
|
| 134 |
+
# Expandable raw response
|
| 135 |
+
with st.expander("View Raw Response"):
|
| 136 |
+
st.code(result.get('raw_response', 'No raw response available'))
|
| 137 |
+
|
| 138 |
+
# Header
|
| 139 |
+
st.title("🔍 Professional Code Analyzer")
|
| 140 |
+
st.markdown("Analyze your code with multiple state-of-the-art LLMs")
|
| 141 |
+
|
| 142 |
+
# Sidebar
|
| 143 |
+
with st.sidebar:
|
| 144 |
+
st.header("⚙️ Configuration")
|
| 145 |
+
|
| 146 |
+
# Model status
|
| 147 |
+
st.subheader("Available Models")
|
| 148 |
+
available_models = analyzer.available_models
|
| 149 |
+
|
| 150 |
+
if not available_models:
|
| 151 |
+
st.error("No models available. Please check your API keys in .env file")
|
| 152 |
+
st.stop()
|
| 153 |
+
|
| 154 |
+
for model, display_name in available_models.items():
|
| 155 |
+
st.success(f"✅ {display_name}")
|
| 156 |
+
|
| 157 |
+
st.divider()
|
| 158 |
+
|
| 159 |
+
# Analysis options
|
| 160 |
+
st.subheader("Analysis Options")
|
| 161 |
+
selected_model = st.selectbox(
|
| 162 |
+
"Select Model",
|
| 163 |
+
options=list(available_models.keys()),
|
| 164 |
+
format_func=lambda x: available_models[x]
|
| 165 |
+
)
|
| 166 |
+
|
| 167 |
+
analyze_all = st.checkbox("Compare All Models", value=False)
|
| 168 |
+
|
| 169 |
+
# Language selection
|
| 170 |
+
languages = ["auto-detect", "python", "javascript", "java", "cpp", "csharp", "go", "rust"]
|
| 171 |
+
selected_language = st.selectbox("Language", languages)
|
| 172 |
+
|
| 173 |
+
st.divider()
|
| 174 |
+
|
| 175 |
+
# Sample code
|
| 176 |
+
st.subheader("Sample Code")
|
| 177 |
+
if st.button("Load Python Example"):
|
| 178 |
+
st.session_state.code_input = """def fibonacci(n):
|
| 179 |
+
if n <= 1:
|
| 180 |
+
return n
|
| 181 |
+
else:
|
| 182 |
+
return fibonacci(n-1) + fibonacci(n-2)
|
| 183 |
+
|
| 184 |
+
# Calculate fibonacci numbers
|
| 185 |
+
for i in range(10):
|
| 186 |
+
print(f"F({i}) = {fibonacci(i)}")
|
| 187 |
+
"""
|
| 188 |
+
|
| 189 |
+
if st.button("Load JavaScript Example"):
|
| 190 |
+
st.session_state.code_input = """function findDuplicates(arr) {
|
| 191 |
+
let duplicates = [];
|
| 192 |
+
for (let i = 0; i < arr.length; i++) {
|
| 193 |
+
for (let j = i + 1; j < arr.length; j++) {
|
| 194 |
+
if (arr[i] === arr[j]) {
|
| 195 |
+
duplicates.push(arr[i]);
|
| 196 |
+
}
|
| 197 |
+
}
|
| 198 |
+
}
|
| 199 |
+
return duplicates;
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
console.log(findDuplicates([1, 2, 3, 2, 4, 3, 5]));
|
| 203 |
+
"""
|
| 204 |
+
|
| 205 |
+
# Main content
|
| 206 |
+
col1, col2 = st.columns([1, 1])
|
| 207 |
+
|
| 208 |
+
with col1:
|
| 209 |
+
st.subheader("📝 Code Input")
|
| 210 |
+
code_input = st.text_area(
|
| 211 |
+
"Paste your code here",
|
| 212 |
+
value=st.session_state.get('code_input', ''),
|
| 213 |
+
height=400,
|
| 214 |
+
key="code_input",
|
| 215 |
+
help="Paste the code you want to analyze"
|
| 216 |
+
)
|
| 217 |
+
|
| 218 |
+
# Analysis button
|
| 219 |
+
analyze_button = st.button(
|
| 220 |
+
"🚀 Analyze Code",
|
| 221 |
+
type="primary",
|
| 222 |
+
disabled=not code_input.strip()
|
| 223 |
+
)
|
| 224 |
+
|
| 225 |
+
# Results column
|
| 226 |
+
with col2:
|
| 227 |
+
st.subheader("📊 Analysis Results")
|
| 228 |
+
|
| 229 |
+
if analyze_button and code_input.strip():
|
| 230 |
+
with st.spinner("Analyzing code..."):
|
| 231 |
+
if analyze_all:
|
| 232 |
+
# Multi-model analysis
|
| 233 |
+
results = analyzer.analyze_with_all_models(
|
| 234 |
+
code_input,
|
| 235 |
+
selected_language if selected_language != "auto-detect" else None
|
| 236 |
+
)
|
| 237 |
+
|
| 238 |
+
# Display comparison
|
| 239 |
+
comparison = analyzer.compare_analyses(results)
|
| 240 |
+
|
| 241 |
+
# Metrics row
|
| 242 |
+
metrics_cols = st.columns(4)
|
| 243 |
+
with metrics_cols[0]:
|
| 244 |
+
st.metric("Average Score", f"{comparison['average_score']}/100")
|
| 245 |
+
with metrics_cols[1]:
|
| 246 |
+
st.metric("Models Used", len(results))
|
| 247 |
+
with metrics_cols[2]:
|
| 248 |
+
st.metric("Best Score", f"{max(comparison['model_scores'].values())}/100")
|
| 249 |
+
with metrics_cols[3]:
|
| 250 |
+
st.metric("Analysis Time", f"{comparison['analysis_time']:.1f}s")
|
| 251 |
+
|
| 252 |
+
# Tabs for each model
|
| 253 |
+
tabs = st.tabs(list(available_models.values()))
|
| 254 |
+
for idx, (model_key, result) in enumerate(results.items()):
|
| 255 |
+
with tabs[idx]:
|
| 256 |
+
display_analysis_result(result, available_models[model_key])
|
| 257 |
+
|
| 258 |
+
# Consensus findings
|
| 259 |
+
if comparison['consensus_issues']:
|
| 260 |
+
st.markdown("### 🤝 Consensus Issues")
|
| 261 |
+
for issue in comparison['consensus_issues']:
|
| 262 |
+
st.warning(f"• {issue}")
|
| 263 |
+
|
| 264 |
+
else:
|
| 265 |
+
# Single model analysis
|
| 266 |
+
result = analyzer.analyze_code(
|
| 267 |
+
code_input,
|
| 268 |
+
selected_model,
|
| 269 |
+
selected_language if selected_language != "auto-detect" else None
|
| 270 |
+
)
|
| 271 |
+
display_analysis_result(result, available_models[selected_model])
|
| 272 |
+
|
| 273 |
+
# Instructions for empty state
|
| 274 |
+
if not code_input.strip() and not analyze_button:
|
| 275 |
+
st.info("""
|
| 276 |
+
👋 **Welcome to the Professional Code Analyzer!**
|
| 277 |
+
|
| 278 |
+
To get started:
|
| 279 |
+
1. Paste your code in the left panel
|
| 280 |
+
2. Select a model or choose "Compare All Models"
|
| 281 |
+
3. Click "Analyze Code" to get comprehensive insights
|
| 282 |
+
|
| 283 |
+
You can also load sample code from the sidebar to try it out!
|
| 284 |
+
""")
|
| 285 |
+
|
| 286 |
+
# Footer
|
| 287 |
+
st.divider()
|
| 288 |
+
st.markdown("""
|
| 289 |
+
<div style="text-align: center; color: #888; padding: 2rem;">
|
| 290 |
+
<p>Built with Streamlit • Powered by OpenAI, Anthropic, Google, and DeepSeek</p>
|
| 291 |
+
<p>Professional Code Analysis Tool</p>
|
| 292 |
+
</div>
|
| 293 |
+
""", unsafe_allow_html=True)
|
launch.py
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Launch script for LLM Code Analyzer
|
| 4 |
+
Checks system requirements and starts the Streamlit app
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import sys
|
| 8 |
+
import os
|
| 9 |
+
import subprocess
|
| 10 |
+
from pathlib import Path
|
| 11 |
+
|
| 12 |
+
def check_requirements():
|
| 13 |
+
"""Check if all requirements are met."""
|
| 14 |
+
print("🔍 Checking system requirements...")
|
| 15 |
+
|
| 16 |
+
# Check Python version
|
| 17 |
+
if sys.version_info < (3, 11):
|
| 18 |
+
print(f"❌ Python 3.11+ required, found {sys.version}")
|
| 19 |
+
return False
|
| 20 |
+
print(f"✅ Python {sys.version.split()[0]}")
|
| 21 |
+
|
| 22 |
+
# Check if we're in the right directory
|
| 23 |
+
if not Path("app.py").exists():
|
| 24 |
+
print("❌ app.py not found. Please run from project root directory.")
|
| 25 |
+
return False
|
| 26 |
+
print("✅ Project structure verified")
|
| 27 |
+
|
| 28 |
+
# Check if analyzer module can be imported
|
| 29 |
+
try:
|
| 30 |
+
from analyzer import CodeAnalyzer
|
| 31 |
+
analyzer = CodeAnalyzer()
|
| 32 |
+
models = analyzer.available_models
|
| 33 |
+
print(f"✅ Analyzer module loaded successfully")
|
| 34 |
+
print(f"📊 Available models: {len(models)}")
|
| 35 |
+
|
| 36 |
+
if not models:
|
| 37 |
+
print("⚠️ No API keys configured in .env file")
|
| 38 |
+
print(" Add at least one API key to use the analyzer")
|
| 39 |
+
else:
|
| 40 |
+
for key, name in models.items():
|
| 41 |
+
print(f" • {name}")
|
| 42 |
+
|
| 43 |
+
except Exception as e:
|
| 44 |
+
print(f"❌ Failed to load analyzer: {e}")
|
| 45 |
+
return False
|
| 46 |
+
|
| 47 |
+
# Check Streamlit
|
| 48 |
+
try:
|
| 49 |
+
import streamlit
|
| 50 |
+
print(f"✅ Streamlit {streamlit.__version__}")
|
| 51 |
+
except ImportError:
|
| 52 |
+
print("❌ Streamlit not installed")
|
| 53 |
+
return False
|
| 54 |
+
|
| 55 |
+
return True
|
| 56 |
+
|
| 57 |
+
def launch_app():
|
| 58 |
+
"""Launch the Streamlit application."""
|
| 59 |
+
print("\n🚀 Starting LLM Code Analyzer...")
|
| 60 |
+
print("=" * 50)
|
| 61 |
+
|
| 62 |
+
try:
|
| 63 |
+
# Start Streamlit
|
| 64 |
+
cmd = [
|
| 65 |
+
sys.executable, "-m", "streamlit", "run", "app.py",
|
| 66 |
+
"--server.headless", "true",
|
| 67 |
+
"--server.port", "8501",
|
| 68 |
+
"--server.address", "0.0.0.0"
|
| 69 |
+
]
|
| 70 |
+
|
| 71 |
+
print("📱 Application will be available at:")
|
| 72 |
+
print(" • Local: http://localhost:8501")
|
| 73 |
+
print(" • Network: http://0.0.0.0:8501")
|
| 74 |
+
print("\n💡 Press Ctrl+C to stop the application")
|
| 75 |
+
print("=" * 50)
|
| 76 |
+
|
| 77 |
+
subprocess.run(cmd, check=True)
|
| 78 |
+
|
| 79 |
+
except KeyboardInterrupt:
|
| 80 |
+
print("\n👋 Application stopped by user")
|
| 81 |
+
except subprocess.CalledProcessError as e:
|
| 82 |
+
print(f"❌ Failed to start application: {e}")
|
| 83 |
+
return False
|
| 84 |
+
except Exception as e:
|
| 85 |
+
print(f"❌ Unexpected error: {e}")
|
| 86 |
+
return False
|
| 87 |
+
|
| 88 |
+
return True
|
| 89 |
+
|
| 90 |
+
def main():
|
| 91 |
+
"""Main entry point."""
|
| 92 |
+
print("🔍 LLM Code Analyzer - Launcher")
|
| 93 |
+
print("=" * 40)
|
| 94 |
+
|
| 95 |
+
# Check requirements first
|
| 96 |
+
if not check_requirements():
|
| 97 |
+
print("\n❌ Requirements check failed")
|
| 98 |
+
print("\nTo fix issues:")
|
| 99 |
+
print("1. Ensure Python 3.11+ is installed")
|
| 100 |
+
print("2. Run: pip install -r requirements.txt")
|
| 101 |
+
print("3. Configure API keys in .env file")
|
| 102 |
+
sys.exit(1)
|
| 103 |
+
|
| 104 |
+
print("\n✅ All requirements satisfied!")
|
| 105 |
+
|
| 106 |
+
# Launch the app
|
| 107 |
+
if not launch_app():
|
| 108 |
+
sys.exit(1)
|
| 109 |
+
|
| 110 |
+
if __name__ == "__main__":
|
| 111 |
+
main()
|
launch_matrix.py
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
🟢 MATRIX CODE ANALYZER LAUNCHER 🟢
|
| 4 |
+
Enter the Matrix... if you dare.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import sys
|
| 8 |
+
import os
|
| 9 |
+
import subprocess
|
| 10 |
+
from pathlib import Path
|
| 11 |
+
|
| 12 |
+
def matrix_banner():
|
| 13 |
+
"""Display Matrix-style banner."""
|
| 14 |
+
print("""
|
| 15 |
+
🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢
|
| 16 |
+
|
| 17 |
+
███╗ ███╗ █████╗ ████████╗██████╗ ██╗██╗ ██╗
|
| 18 |
+
████╗ ████║██╔══██╗╚══██╔══╝██╔══██╗██║╚██╗██╔╝
|
| 19 |
+
██╔████╔██║███████║ ██║ ██████╔╝██║ ╚███╔╝
|
| 20 |
+
██║╚██╔╝██║██╔══██║ ██║ ██╔══██╗██║ ██╔██╗
|
| 21 |
+
██║ ╚═╝ ██║██║ ██║ ██║ ██║ ██║██║██╔╝ ██╗
|
| 22 |
+
╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝╚═╝ ╚═╝
|
| 23 |
+
|
| 24 |
+
█████╗ ███╗ ██╗ █████╗ ██╗ ██╗ ██╗███████╗███████╗██████╗
|
| 25 |
+
██╔══██╗████╗ ██║██╔══██╗██║ ╚██╗ ██╔╝╚══███╔╝██╔════╝██╔══██╗
|
| 26 |
+
███████║██╔██╗ ██║███████║██║ ╚████╔╝ ███╔╝ █████╗ ██████╔╝
|
| 27 |
+
██╔══██║██║╚██╗██║██╔══██║██║ ╚██╔╝ ███╔╝ ██╔══╝ ██╔══██╗
|
| 28 |
+
██║ ██║██║ ╚████║██║ ██║███████╗██║ ███████╗███████╗██║ ██║
|
| 29 |
+
╚═╝ ╚═╝╚═╝ ╚═══╝╚═╝ ╚═╝╚══════╝╚═╝ ╚══════╝╚══════╝╚═╝ ╚═╝
|
| 30 |
+
|
| 31 |
+
🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢
|
| 32 |
+
""")
|
| 33 |
+
print("🟢 NEURAL NETWORK INITIALIZATION SEQUENCE STARTING...")
|
| 34 |
+
print("🟢 'There is no spoon... only code.'")
|
| 35 |
+
print("🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢")
|
| 36 |
+
|
| 37 |
+
def check_matrix_requirements():
|
| 38 |
+
"""Check if the Matrix is ready."""
|
| 39 |
+
print("\n🟢 SCANNING MATRIX REQUIREMENTS...")
|
| 40 |
+
|
| 41 |
+
# Check Python version
|
| 42 |
+
if sys.version_info < (3, 11):
|
| 43 |
+
print(f"❌ INCOMPATIBLE_PYTHON_VERSION: {sys.version}")
|
| 44 |
+
print("🟢 UPGRADE_TO_PYTHON_3.11+_REQUIRED")
|
| 45 |
+
return False
|
| 46 |
+
print(f"✅ PYTHON_VERSION: {sys.version.split()[0]} [COMPATIBLE]")
|
| 47 |
+
|
| 48 |
+
# Check if we're in the right dimension
|
| 49 |
+
if not Path("matrix_app.py").exists():
|
| 50 |
+
print("❌ MATRIX_APP_NOT_FOUND")
|
| 51 |
+
print("🟢 ENSURE_YOU_ARE_IN_THE_CORRECT_DIRECTORY")
|
| 52 |
+
return False
|
| 53 |
+
print("✅ MATRIX_APPLICATION: LOCATED")
|
| 54 |
+
|
| 55 |
+
# Check if analyzer module is accessible
|
| 56 |
+
try:
|
| 57 |
+
from analyzer import CodeAnalyzer
|
| 58 |
+
analyzer = CodeAnalyzer()
|
| 59 |
+
models = analyzer.available_models
|
| 60 |
+
print(f"✅ NEURAL_NETWORKS: ONLINE")
|
| 61 |
+
print(f"🟢 AVAILABLE_AI_MODELS: {len(models)}")
|
| 62 |
+
|
| 63 |
+
if not models:
|
| 64 |
+
print("⚠️ NO_API_KEYS_DETECTED")
|
| 65 |
+
print("🟢 CONFIGURE_NEURAL_NETWORK_ACCESS_CODES")
|
| 66 |
+
print("🟢 REQUIRED: OPENAI • ANTHROPIC • GEMINI • DEEPSEEK")
|
| 67 |
+
else:
|
| 68 |
+
for key, name in models.items():
|
| 69 |
+
print(f" 🤖 {name} [READY]")
|
| 70 |
+
|
| 71 |
+
except Exception as e:
|
| 72 |
+
print(f"❌ NEURAL_NETWORK_ERROR: {e}")
|
| 73 |
+
return False
|
| 74 |
+
|
| 75 |
+
# Check Streamlit
|
| 76 |
+
try:
|
| 77 |
+
import streamlit
|
| 78 |
+
print(f"✅ MATRIX_INTERFACE: v{streamlit.__version__} [OPERATIONAL]")
|
| 79 |
+
except ImportError:
|
| 80 |
+
print("❌ MATRIX_INTERFACE_NOT_FOUND")
|
| 81 |
+
print("🟢 RUN: pip install streamlit")
|
| 82 |
+
return False
|
| 83 |
+
|
| 84 |
+
return True
|
| 85 |
+
|
| 86 |
+
def enter_matrix():
|
| 87 |
+
"""Enter the Matrix."""
|
| 88 |
+
print("\n🟢 INITIATING_MATRIX_SEQUENCE...")
|
| 89 |
+
print("🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢")
|
| 90 |
+
|
| 91 |
+
try:
|
| 92 |
+
# Start the Matrix interface
|
| 93 |
+
cmd = [
|
| 94 |
+
sys.executable, "-m", "streamlit", "run", "matrix_app.py",
|
| 95 |
+
"--server.headless", "true",
|
| 96 |
+
"--server.port", "8503",
|
| 97 |
+
"--server.address", "0.0.0.0"
|
| 98 |
+
]
|
| 99 |
+
|
| 100 |
+
print("🟢 MATRIX_PORTAL_COORDINATES:")
|
| 101 |
+
print(" 🌐 LOCAL_ACCESS: http://localhost:8503")
|
| 102 |
+
print(" 🌐 NETWORK_ACCESS: http://0.0.0.0:8503")
|
| 103 |
+
print("\n🟢 MATRIX_ACTIVATED...")
|
| 104 |
+
print("🟢 'Welcome to the real world, Neo.'")
|
| 105 |
+
print("🟢 [Press Ctrl+C to exit the Matrix]")
|
| 106 |
+
print("🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢")
|
| 107 |
+
|
| 108 |
+
subprocess.run(cmd, check=True)
|
| 109 |
+
|
| 110 |
+
except KeyboardInterrupt:
|
| 111 |
+
print("\n🟢 MATRIX_SESSION_TERMINATED")
|
| 112 |
+
print("🟢 'Until we meet again in the Matrix...'")
|
| 113 |
+
except subprocess.CalledProcessError as e:
|
| 114 |
+
print(f"❌ MATRIX_INITIALIZATION_FAILED: {e}")
|
| 115 |
+
return False
|
| 116 |
+
except Exception as e:
|
| 117 |
+
print(f"❌ UNEXPECTED_MATRIX_ERROR: {e}")
|
| 118 |
+
return False
|
| 119 |
+
|
| 120 |
+
return True
|
| 121 |
+
|
| 122 |
+
def main():
|
| 123 |
+
"""Main entry point to the Matrix."""
|
| 124 |
+
matrix_banner()
|
| 125 |
+
|
| 126 |
+
# Check if the Matrix is ready
|
| 127 |
+
if not check_matrix_requirements():
|
| 128 |
+
print("\n❌ MATRIX_REQUIREMENTS_NOT_MET")
|
| 129 |
+
print("\n🟢 TROUBLESHOOTING_PROTOCOL:")
|
| 130 |
+
print("1. ENSURE_PYTHON_3.11+_INSTALLED")
|
| 131 |
+
print("2. RUN: pip install -r requirements.txt")
|
| 132 |
+
print("3. CONFIGURE_API_KEYS_IN_.ENV_FILE")
|
| 133 |
+
print("4. RETRY_MATRIX_INITIALIZATION")
|
| 134 |
+
sys.exit(1)
|
| 135 |
+
|
| 136 |
+
print("\n✅ ALL_MATRIX_SYSTEMS_OPERATIONAL")
|
| 137 |
+
print("🟢 READY_TO_ENTER_THE_MATRIX...")
|
| 138 |
+
|
| 139 |
+
# Enter the Matrix
|
| 140 |
+
if not enter_matrix():
|
| 141 |
+
sys.exit(1)
|
| 142 |
+
|
| 143 |
+
if __name__ == "__main__":
|
| 144 |
+
main()
|
matrix_app.py
ADDED
|
@@ -0,0 +1,562 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import os
|
| 3 |
+
import time
|
| 4 |
+
import random
|
| 5 |
+
import sys
|
| 6 |
+
from dotenv import load_dotenv
|
| 7 |
+
from analyzer import CodeAnalyzer
|
| 8 |
+
|
| 9 |
+
# Load environment variables
|
| 10 |
+
load_dotenv()
|
| 11 |
+
|
| 12 |
+
# Page config
|
| 13 |
+
st.set_page_config(
|
| 14 |
+
page_title="Matrix Code Analyzer",
|
| 15 |
+
page_icon="🟢",
|
| 16 |
+
layout="wide",
|
| 17 |
+
initial_sidebar_state="expanded"
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
# Matrix CSS - Cyberpunk Theme
|
| 21 |
+
st.markdown("""
|
| 22 |
+
<style>
|
| 23 |
+
@import url('https://fonts.googleapis.com/css2?family=Share+Tech+Mono:wght@400&display=swap');
|
| 24 |
+
@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700;900&display=swap');
|
| 25 |
+
|
| 26 |
+
/* Matrix Background */
|
| 27 |
+
.stApp {
|
| 28 |
+
background: linear-gradient(135deg, #0d1b0d 0%, #000000 50%, #0d1b0d 100%);
|
| 29 |
+
color: #00ff41;
|
| 30 |
+
font-family: 'Share Tech Mono', monospace;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
/* Matrix Code Rain Animation */
|
| 34 |
+
.matrix-bg {
|
| 35 |
+
position: fixed;
|
| 36 |
+
top: 0;
|
| 37 |
+
left: 0;
|
| 38 |
+
width: 100%;
|
| 39 |
+
height: 100%;
|
| 40 |
+
overflow: hidden;
|
| 41 |
+
z-index: -1;
|
| 42 |
+
opacity: 0.1;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
.matrix-char {
|
| 46 |
+
position: absolute;
|
| 47 |
+
color: #00ff41;
|
| 48 |
+
font-family: 'Share Tech Mono', monospace;
|
| 49 |
+
font-size: 14px;
|
| 50 |
+
animation: matrix-fall linear infinite;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
@keyframes matrix-fall {
|
| 54 |
+
0% { transform: translateY(-100vh); opacity: 1; }
|
| 55 |
+
100% { transform: translateY(100vh); opacity: 0; }
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
/* Main Content Styling */
|
| 59 |
+
.main .block-container {
|
| 60 |
+
padding-top: 2rem;
|
| 61 |
+
background: rgba(0, 0, 0, 0.8);
|
| 62 |
+
border: 1px solid #00ff41;
|
| 63 |
+
border-radius: 10px;
|
| 64 |
+
box-shadow: 0 0 20px rgba(0, 255, 65, 0.3);
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
/* Title Styling */
|
| 68 |
+
h1 {
|
| 69 |
+
font-family: 'Orbitron', monospace !important;
|
| 70 |
+
color: #00ff41 !important;
|
| 71 |
+
text-align: center !important;
|
| 72 |
+
text-shadow: 0 0 10px #00ff41, 0 0 20px #00ff41, 0 0 30px #00ff41;
|
| 73 |
+
font-weight: 900 !important;
|
| 74 |
+
margin-bottom: 2rem !important;
|
| 75 |
+
animation: glow 2s ease-in-out infinite alternate;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
@keyframes glow {
|
| 79 |
+
from { text-shadow: 0 0 5px #00ff41, 0 0 10px #00ff41, 0 0 15px #00ff41; }
|
| 80 |
+
to { text-shadow: 0 0 10px #00ff41, 0 0 20px #00ff41, 0 0 30px #00ff41; }
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
/* Sidebar Styling */
|
| 84 |
+
.css-1d391kg {
|
| 85 |
+
background: rgba(0, 0, 0, 0.9) !important;
|
| 86 |
+
border: 1px solid #00ff41 !important;
|
| 87 |
+
border-radius: 10px !important;
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
/* Buttons */
|
| 91 |
+
.stButton > button {
|
| 92 |
+
background: linear-gradient(45deg, #003300, #006600) !important;
|
| 93 |
+
color: #00ff41 !important;
|
| 94 |
+
border: 2px solid #00ff41 !important;
|
| 95 |
+
border-radius: 5px !important;
|
| 96 |
+
font-family: 'Orbitron', monospace !important;
|
| 97 |
+
font-weight: bold !important;
|
| 98 |
+
text-transform: uppercase !important;
|
| 99 |
+
transition: all 0.3s ease !important;
|
| 100 |
+
box-shadow: 0 0 10px rgba(0, 255, 65, 0.3) !important;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
.stButton > button:hover {
|
| 104 |
+
background: linear-gradient(45deg, #006600, #00aa00) !important;
|
| 105 |
+
box-shadow: 0 0 20px rgba(0, 255, 65, 0.6) !important;
|
| 106 |
+
transform: translateY(-2px) !important;
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
/* Select boxes */
|
| 110 |
+
.stSelectbox > div > div {
|
| 111 |
+
background: rgba(0, 51, 0, 0.8) !important;
|
| 112 |
+
border: 1px solid #00ff41 !important;
|
| 113 |
+
color: #00ff41 !important;
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
/* Text areas */
|
| 117 |
+
.stTextArea > div > div > textarea {
|
| 118 |
+
background: rgba(0, 0, 0, 0.9) !important;
|
| 119 |
+
border: 1px solid #00ff41 !important;
|
| 120 |
+
color: #00ff41 !important;
|
| 121 |
+
font-family: 'Share Tech Mono', monospace !important;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
/* Metrics */
|
| 125 |
+
.css-1xarl3l {
|
| 126 |
+
background: rgba(0, 51, 0, 0.3) !important;
|
| 127 |
+
border: 1px solid #00ff41 !important;
|
| 128 |
+
border-radius: 5px !important;
|
| 129 |
+
box-shadow: 0 0 10px rgba(0, 255, 65, 0.2) !important;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
/* Success/Info/Warning messages */
|
| 133 |
+
.stSuccess {
|
| 134 |
+
background: rgba(0, 255, 65, 0.1) !important;
|
| 135 |
+
border: 1px solid #00ff41 !important;
|
| 136 |
+
color: #00ff41 !important;
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
.stInfo {
|
| 140 |
+
background: rgba(0, 255, 255, 0.1) !important;
|
| 141 |
+
border: 1px solid #00ffff !important;
|
| 142 |
+
color: #00ffff !important;
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
.stWarning {
|
| 146 |
+
background: rgba(255, 255, 0, 0.1) !important;
|
| 147 |
+
border: 1px solid #ffff00 !important;
|
| 148 |
+
color: #ffff00 !important;
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
.stError {
|
| 152 |
+
background: rgba(255, 0, 0, 0.1) !important;
|
| 153 |
+
border: 1px solid #ff0000 !important;
|
| 154 |
+
color: #ff0000 !important;
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
/* Code blocks */
|
| 158 |
+
.stCode {
|
| 159 |
+
background: rgba(0, 0, 0, 0.9) !important;
|
| 160 |
+
border: 1px solid #00ff41 !important;
|
| 161 |
+
color: #00ff41 !important;
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
/* Tabs */
|
| 165 |
+
.stTabs [data-baseweb="tab-list"] {
|
| 166 |
+
background: rgba(0, 0, 0, 0.8) !important;
|
| 167 |
+
border-bottom: 2px solid #00ff41 !important;
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
.stTabs [data-baseweb="tab"] {
|
| 171 |
+
background: rgba(0, 51, 0, 0.3) !important;
|
| 172 |
+
color: #00ff41 !important;
|
| 173 |
+
border: 1px solid #00ff41 !important;
|
| 174 |
+
font-family: 'Orbitron', monospace !important;
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
.stTabs [aria-selected="true"] {
|
| 178 |
+
background: rgba(0, 255, 65, 0.2) !important;
|
| 179 |
+
box-shadow: 0 0 10px rgba(0, 255, 65, 0.5) !important;
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
/* Matrix Terminal Effect */
|
| 183 |
+
.matrix-terminal {
|
| 184 |
+
background: rgba(0, 0, 0, 0.95) !important;
|
| 185 |
+
border: 2px solid #00ff41 !important;
|
| 186 |
+
border-radius: 10px !important;
|
| 187 |
+
padding: 20px !important;
|
| 188 |
+
font-family: 'Share Tech Mono', monospace !important;
|
| 189 |
+
color: #00ff41 !important;
|
| 190 |
+
box-shadow: 0 0 30px rgba(0, 255, 65, 0.4) !important;
|
| 191 |
+
position: relative !important;
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
.matrix-terminal::before {
|
| 195 |
+
content: "MATRIX_ANALYZER_v2.0 > ACTIVE" !important;
|
| 196 |
+
position: absolute !important;
|
| 197 |
+
top: -15px !important;
|
| 198 |
+
left: 20px !important;
|
| 199 |
+
background: #000000 !important;
|
| 200 |
+
padding: 0 10px !important;
|
| 201 |
+
color: #00ff41 !important;
|
| 202 |
+
font-size: 12px !important;
|
| 203 |
+
font-weight: bold !important;
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
/* Scrollbar */
|
| 207 |
+
::-webkit-scrollbar {
|
| 208 |
+
width: 8px;
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
::-webkit-scrollbar-track {
|
| 212 |
+
background: #000000;
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
::-webkit-scrollbar-thumb {
|
| 216 |
+
background: #00ff41;
|
| 217 |
+
border-radius: 4px;
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
::-webkit-scrollbar-thumb:hover {
|
| 221 |
+
background: #00aa00;
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
/* Loading spinner */
|
| 225 |
+
.stSpinner > div {
|
| 226 |
+
border-color: #00ff41 transparent #00ff41 transparent !important;
|
| 227 |
+
}
|
| 228 |
+
|
| 229 |
+
/* Expander */
|
| 230 |
+
.streamlit-expanderHeader {
|
| 231 |
+
background: rgba(0, 51, 0, 0.3) !important;
|
| 232 |
+
border: 1px solid #00ff41 !important;
|
| 233 |
+
color: #00ff41 !important;
|
| 234 |
+
}
|
| 235 |
+
</style>
|
| 236 |
+
|
| 237 |
+
<div class="matrix-bg" id="matrix-bg"></div>
|
| 238 |
+
|
| 239 |
+
<script>
|
| 240 |
+
function createMatrixRain() {
|
| 241 |
+
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#$%^&*()_+-=[]{}|;:,.<>?";
|
| 242 |
+
const container = document.getElementById('matrix-bg');
|
| 243 |
+
|
| 244 |
+
for (let i = 0; i < 50; i++) {
|
| 245 |
+
const char = document.createElement('div');
|
| 246 |
+
char.className = 'matrix-char';
|
| 247 |
+
char.textContent = chars[Math.floor(Math.random() * chars.length)];
|
| 248 |
+
char.style.left = Math.random() * 100 + '%';
|
| 249 |
+
char.style.animationDuration = (Math.random() * 3 + 2) + 's';
|
| 250 |
+
char.style.animationDelay = Math.random() * 2 + 's';
|
| 251 |
+
container.appendChild(char);
|
| 252 |
+
}
|
| 253 |
+
}
|
| 254 |
+
|
| 255 |
+
// Create matrix rain effect
|
| 256 |
+
setTimeout(createMatrixRain, 100);
|
| 257 |
+
</script>
|
| 258 |
+
""", unsafe_allow_html=True)
|
| 259 |
+
|
| 260 |
+
# Initialize analyzer
|
| 261 |
+
@st.cache_resource
|
| 262 |
+
def get_analyzer():
|
| 263 |
+
return CodeAnalyzer()
|
| 264 |
+
|
| 265 |
+
analyzer = get_analyzer()
|
| 266 |
+
|
| 267 |
+
def display_matrix_analysis_result(result: dict, model_name: str):
|
| 268 |
+
"""Display analysis result in Matrix terminal style."""
|
| 269 |
+
if 'error' in result:
|
| 270 |
+
st.error(f"🚨 SYSTEM ERROR: {result['error']}")
|
| 271 |
+
return
|
| 272 |
+
|
| 273 |
+
# Quality score with Matrix styling
|
| 274 |
+
score = result['quality_score']
|
| 275 |
+
if score >= 80:
|
| 276 |
+
score_color = "#00ff41"
|
| 277 |
+
status = "OPTIMAL"
|
| 278 |
+
elif score >= 60:
|
| 279 |
+
score_color = "#ffff00"
|
| 280 |
+
status = "ACCEPTABLE"
|
| 281 |
+
else:
|
| 282 |
+
score_color = "#ff0000"
|
| 283 |
+
status = "CRITICAL"
|
| 284 |
+
|
| 285 |
+
st.markdown(f"""
|
| 286 |
+
<div class="matrix-terminal">
|
| 287 |
+
<h3 style="color: {score_color}; font-family: 'Orbitron', monospace; text-align: center;">
|
| 288 |
+
[{model_name}] ANALYSIS COMPLETE
|
| 289 |
+
</h3>
|
| 290 |
+
<div style="display: flex; justify-content: space-between; margin: 20px 0;">
|
| 291 |
+
<div>
|
| 292 |
+
<span style="font-size: 2.5rem; color: {score_color}; font-weight: bold;">
|
| 293 |
+
{score}/100
|
| 294 |
+
</span>
|
| 295 |
+
<p style="margin: 0; color: {score_color}; font-weight: bold;">
|
| 296 |
+
STATUS: {status}
|
| 297 |
+
</p>
|
| 298 |
+
</div>
|
| 299 |
+
<div style="text-align: right; color: #00ff41;">
|
| 300 |
+
<p style="margin: 0;"><strong>LANGUAGE:</strong> {result['language'].upper()}</p>
|
| 301 |
+
<p style="margin: 0;"><strong>SCAN_TIME:</strong> {result['execution_time']}s</p>
|
| 302 |
+
<p style="margin: 0;"><strong>CODE_LINES:</strong> {result['line_count']}</p>
|
| 303 |
+
</div>
|
| 304 |
+
</div>
|
| 305 |
+
</div>
|
| 306 |
+
""", unsafe_allow_html=True)
|
| 307 |
+
|
| 308 |
+
# Summary in terminal style
|
| 309 |
+
if result.get('summary'):
|
| 310 |
+
st.markdown("#### 📋 SYSTEM ANALYSIS")
|
| 311 |
+
st.markdown(f"""
|
| 312 |
+
<div style="background: rgba(0,0,0,0.8); border: 1px solid #00ff41; padding: 15px; border-radius: 5px; font-family: 'Share Tech Mono', monospace;">
|
| 313 |
+
> {result['summary']}
|
| 314 |
+
</div>
|
| 315 |
+
""", unsafe_allow_html=True)
|
| 316 |
+
|
| 317 |
+
# Create columns for different sections
|
| 318 |
+
col1, col2 = st.columns(2)
|
| 319 |
+
|
| 320 |
+
with col1:
|
| 321 |
+
# Strengths
|
| 322 |
+
if result.get('strengths'):
|
| 323 |
+
st.markdown("#### ✅ SYSTEM STRENGTHS")
|
| 324 |
+
for strength in result['strengths']:
|
| 325 |
+
st.success(f"[+] {strength}")
|
| 326 |
+
|
| 327 |
+
# Suggestions
|
| 328 |
+
if result.get('suggestions'):
|
| 329 |
+
st.markdown("#### 💡 ENHANCEMENT_PROTOCOLS")
|
| 330 |
+
for suggestion in result['suggestions']:
|
| 331 |
+
st.info(f"[*] {suggestion}")
|
| 332 |
+
|
| 333 |
+
with col2:
|
| 334 |
+
# Issues
|
| 335 |
+
if result.get('issues'):
|
| 336 |
+
st.markdown("#### ⚠️ SYSTEM_VULNERABILITIES")
|
| 337 |
+
for issue in result['issues']:
|
| 338 |
+
st.warning(f"[!] {issue}")
|
| 339 |
+
|
| 340 |
+
# Security concerns
|
| 341 |
+
if result.get('security_concerns'):
|
| 342 |
+
st.markdown("#### 🔒 SECURITY_BREACH_DETECTED")
|
| 343 |
+
for concern in result['security_concerns']:
|
| 344 |
+
st.error(f"[ALERT] {concern}")
|
| 345 |
+
|
| 346 |
+
# Performance notes
|
| 347 |
+
if result.get('performance_notes'):
|
| 348 |
+
st.markdown("#### ⚡ PERFORMANCE_OPTIMIZATION")
|
| 349 |
+
for note in result['performance_notes']:
|
| 350 |
+
st.info(f"[PERF] {note}")
|
| 351 |
+
|
| 352 |
+
# Expandable raw response
|
| 353 |
+
with st.expander("VIEW RAW_DATA_STREAM"):
|
| 354 |
+
st.code(result.get('raw_response', 'NO_DATA_AVAILABLE'), language='text')
|
| 355 |
+
|
| 356 |
+
# Header with Matrix effect
|
| 357 |
+
st.markdown("""
|
| 358 |
+
<h1 style="text-align: center;">
|
| 359 |
+
🟢 MATRIX CODE ANALYZER 🟢
|
| 360 |
+
</h1>
|
| 361 |
+
<p style="text-align: center; color: #00ff41; font-family: 'Share Tech Mono', monospace; font-size: 18px;">
|
| 362 |
+
[NEURAL_NETWORK_ACTIVATED] • [MULTI_AI_ANALYSIS_ONLINE] • [SECURITY_LEVEL_9]
|
| 363 |
+
</p>
|
| 364 |
+
""", unsafe_allow_html=True)
|
| 365 |
+
|
| 366 |
+
# Sidebar - The Matrix Control Panel
|
| 367 |
+
with st.sidebar:
|
| 368 |
+
st.markdown("### 🟢 CONTROL_PANEL")
|
| 369 |
+
|
| 370 |
+
# Model status
|
| 371 |
+
st.markdown("#### AVAILABLE_NEURAL_NETWORKS")
|
| 372 |
+
available_models = analyzer.available_models
|
| 373 |
+
|
| 374 |
+
if not available_models:
|
| 375 |
+
st.error("❌ NO_NETWORKS_DETECTED")
|
| 376 |
+
st.info("CONFIGURE_API_KEYS_IN_ENV_FILE")
|
| 377 |
+
st.stop()
|
| 378 |
+
|
| 379 |
+
# Display available models with Matrix styling
|
| 380 |
+
for model, display_name in available_models.items():
|
| 381 |
+
st.markdown(f"""
|
| 382 |
+
<div style="background: rgba(0, 255, 65, 0.1); border: 1px solid #00ff41; padding: 5px; margin: 5px 0; border-radius: 3px;">
|
| 383 |
+
🟢 <strong>{display_name}</strong> [ONLINE]
|
| 384 |
+
</div>
|
| 385 |
+
""", unsafe_allow_html=True)
|
| 386 |
+
|
| 387 |
+
st.markdown("---")
|
| 388 |
+
|
| 389 |
+
# Analysis options
|
| 390 |
+
st.markdown("#### ANALYSIS_PARAMETERS")
|
| 391 |
+
|
| 392 |
+
# Model selector with Matrix styling
|
| 393 |
+
selected_model = st.selectbox(
|
| 394 |
+
"SELECT_NEURAL_NETWORK",
|
| 395 |
+
options=list(available_models.keys()),
|
| 396 |
+
format_func=lambda x: f"🤖 {available_models[x]}"
|
| 397 |
+
)
|
| 398 |
+
|
| 399 |
+
# Multi-model analysis toggle
|
| 400 |
+
analyze_all = st.checkbox("🔄 MULTI_NETWORK_SCAN", value=False)
|
| 401 |
+
|
| 402 |
+
# Language selection
|
| 403 |
+
languages = ["auto-detect", "python", "javascript", "java", "cpp", "csharp", "go", "rust"]
|
| 404 |
+
selected_language = st.selectbox(
|
| 405 |
+
"TARGET_LANGUAGE",
|
| 406 |
+
languages,
|
| 407 |
+
format_func=lambda x: x.upper().replace("-", "_")
|
| 408 |
+
)
|
| 409 |
+
|
| 410 |
+
st.markdown("---")
|
| 411 |
+
|
| 412 |
+
# Sample code injection
|
| 413 |
+
st.markdown("#### CODE_INJECTION_SAMPLES")
|
| 414 |
+
|
| 415 |
+
if st.button("🐍 INJECT_PYTHON_SAMPLE"):
|
| 416 |
+
st.session_state.code_input = """def matrix_hack():
|
| 417 |
+
# The Matrix has you...
|
| 418 |
+
reality = "simulation"
|
| 419 |
+
if reality == "simulation":
|
| 420 |
+
print("Wake up, Neo...")
|
| 421 |
+
return True
|
| 422 |
+
return False
|
| 423 |
+
|
| 424 |
+
# Take the red pill
|
| 425 |
+
choice = matrix_hack()
|
| 426 |
+
for i in range(10):
|
| 427 |
+
print(f"Level {i}: {'🟢' if choice else '🔴'}")
|
| 428 |
+
"""
|
| 429 |
+
|
| 430 |
+
if st.button("🟨 INJECT_JAVASCRIPT_SAMPLE"):
|
| 431 |
+
st.session_state.code_input = """function followTheWhiteRabbit(choice) {
|
| 432 |
+
const matrix = {
|
| 433 |
+
red_pill: "truth",
|
| 434 |
+
blue_pill: "ignorance"
|
| 435 |
+
};
|
| 436 |
+
|
| 437 |
+
if (choice === "red_pill") {
|
| 438 |
+
console.log("Welcome to the real world");
|
| 439 |
+
return matrix[choice];
|
| 440 |
+
}
|
| 441 |
+
|
| 442 |
+
return "The story ends, you wake up in your bed...";
|
| 443 |
+
}
|
| 444 |
+
|
| 445 |
+
// The choice is yours
|
| 446 |
+
const reality = followTheWhiteRabbit("red_pill");
|
| 447 |
+
console.log(`Reality: ${reality}`);
|
| 448 |
+
"""
|
| 449 |
+
|
| 450 |
+
# Main Terminal Interface
|
| 451 |
+
col1, col2 = st.columns([1, 1])
|
| 452 |
+
|
| 453 |
+
with col1:
|
| 454 |
+
st.markdown("### 📟 CODE_INPUT_TERMINAL")
|
| 455 |
+
|
| 456 |
+
# Code input with Matrix styling
|
| 457 |
+
code_input = st.text_area(
|
| 458 |
+
"PASTE_TARGET_CODE",
|
| 459 |
+
value=st.session_state.get('code_input', ''),
|
| 460 |
+
height=400,
|
| 461 |
+
key="code_input",
|
| 462 |
+
help="Insert code for neural network analysis..."
|
| 463 |
+
)
|
| 464 |
+
|
| 465 |
+
# Matrix-styled analyze button
|
| 466 |
+
analyze_button = st.button(
|
| 467 |
+
"🚀 INITIATE_SCAN",
|
| 468 |
+
type="primary",
|
| 469 |
+
disabled=not code_input.strip(),
|
| 470 |
+
help="Begin deep neural analysis of target code"
|
| 471 |
+
)
|
| 472 |
+
|
| 473 |
+
# Results Terminal
|
| 474 |
+
with col2:
|
| 475 |
+
st.markdown("### 📊 ANALYSIS_OUTPUT_TERMINAL")
|
| 476 |
+
|
| 477 |
+
if analyze_button and code_input.strip():
|
| 478 |
+
with st.spinner("🟢 SCANNING... NEURAL_NETWORKS_PROCESSING..."):
|
| 479 |
+
if analyze_all:
|
| 480 |
+
# Multi-model analysis
|
| 481 |
+
st.markdown("#### 🔄 MULTI_NETWORK_ANALYSIS_INITIATED")
|
| 482 |
+
|
| 483 |
+
results = analyzer.analyze_with_all_models(
|
| 484 |
+
code_input,
|
| 485 |
+
selected_language if selected_language != "auto-detect" else None
|
| 486 |
+
)
|
| 487 |
+
|
| 488 |
+
# Display comparison metrics
|
| 489 |
+
comparison = analyzer.compare_analyses(results)
|
| 490 |
+
|
| 491 |
+
# Matrix-styled metrics
|
| 492 |
+
metrics_cols = st.columns(4)
|
| 493 |
+
with metrics_cols[0]:
|
| 494 |
+
st.metric("AVG_SCORE", f"{comparison['average_score']}/100")
|
| 495 |
+
with metrics_cols[1]:
|
| 496 |
+
st.metric("NETWORKS", len(results))
|
| 497 |
+
with metrics_cols[2]:
|
| 498 |
+
st.metric("PEAK_SCORE", f"{max(comparison['model_scores'].values())}/100")
|
| 499 |
+
with metrics_cols[3]:
|
| 500 |
+
st.metric("SCAN_TIME", f"{comparison['analysis_time']:.1f}s")
|
| 501 |
+
|
| 502 |
+
# Create tabs for each neural network
|
| 503 |
+
tab_names = [f"🤖 {available_models[key]}" for key in results.keys()]
|
| 504 |
+
tabs = st.tabs(tab_names)
|
| 505 |
+
|
| 506 |
+
for idx, (model_key, result) in enumerate(results.items()):
|
| 507 |
+
with tabs[idx]:
|
| 508 |
+
display_matrix_analysis_result(result, available_models[model_key])
|
| 509 |
+
|
| 510 |
+
# Consensus findings with Matrix styling
|
| 511 |
+
if comparison['consensus_issues']:
|
| 512 |
+
st.markdown("### 🤝 NEURAL_CONSENSUS_DETECTED")
|
| 513 |
+
st.markdown("""
|
| 514 |
+
<div style="background: rgba(255, 0, 0, 0.1); border: 2px solid #ff0000; padding: 15px; border-radius: 10px;">
|
| 515 |
+
<strong>CRITICAL_PATTERNS_IDENTIFIED_BY_MULTIPLE_NETWORKS:</strong>
|
| 516 |
+
</div>
|
| 517 |
+
""", unsafe_allow_html=True)
|
| 518 |
+
|
| 519 |
+
for issue in comparison['consensus_issues']:
|
| 520 |
+
st.error(f"🚨 CONSENSUS_ALERT: {issue}")
|
| 521 |
+
|
| 522 |
+
else:
|
| 523 |
+
# Single model analysis
|
| 524 |
+
st.markdown(f"#### 🤖 {available_models[selected_model].upper()}_ANALYSIS")
|
| 525 |
+
|
| 526 |
+
result = analyzer.analyze_code(
|
| 527 |
+
code_input,
|
| 528 |
+
selected_model,
|
| 529 |
+
selected_language if selected_language != "auto-detect" else None
|
| 530 |
+
)
|
| 531 |
+
display_matrix_analysis_result(result, available_models[selected_model])
|
| 532 |
+
|
| 533 |
+
# Instructions for new users
|
| 534 |
+
if not code_input.strip() and not analyze_button:
|
| 535 |
+
st.markdown("""
|
| 536 |
+
<div class="matrix-terminal" style="margin: 20px 0;">
|
| 537 |
+
<h3 style="color: #00ff41; text-align: center;">🟢 WELCOME TO THE MATRIX 🟢</h3>
|
| 538 |
+
<p style="color: #00ff41; font-family: 'Share Tech Mono', monospace;">
|
| 539 |
+
> SYSTEM_STATUS: ONLINE<br>
|
| 540 |
+
> NEURAL_NETWORKS: READY<br>
|
| 541 |
+
> AWAITING_CODE_INPUT...<br><br>
|
| 542 |
+
|
| 543 |
+
<strong>INITIALIZATION_PROTOCOL:</strong><br>
|
| 544 |
+
1. PASTE_CODE → Left terminal<br>
|
| 545 |
+
2. SELECT_NEURAL_NETWORK → Control panel<br>
|
| 546 |
+
3. INITIATE_SCAN → Begin analysis<br>
|
| 547 |
+
4. REVIEW_RESULTS → Right terminal<br><br>
|
| 548 |
+
|
| 549 |
+
<em>The Matrix has you... but now you have the power to analyze it. 🟢</em>
|
| 550 |
+
</p>
|
| 551 |
+
</div>
|
| 552 |
+
""", unsafe_allow_html=True)
|
| 553 |
+
|
| 554 |
+
# Footer with Matrix signature
|
| 555 |
+
st.markdown("---")
|
| 556 |
+
st.markdown("""
|
| 557 |
+
<div style="text-align: center; color: #00ff41; font-family: 'Share Tech Mono', monospace; padding: 20px;">
|
| 558 |
+
<p>🟢 POWERED_BY_NEURAL_NETWORKS • OPENAI • ANTHROPIC • DEEPSEEK • GOOGLE 🟢</p>
|
| 559 |
+
<p><em>"There is no spoon... only code."</em></p>
|
| 560 |
+
<p style="font-size: 12px;">MATRIX_ANALYZER_v2.0 • BUILD_2024 • SECURITY_CLEARANCE_OMEGA</p>
|
| 561 |
+
</div>
|
| 562 |
+
""", unsafe_allow_html=True)
|
matrix_final.py
ADDED
|
@@ -0,0 +1,978 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import os
|
| 3 |
+
import time
|
| 4 |
+
import random
|
| 5 |
+
import sys
|
| 6 |
+
from dotenv import load_dotenv
|
| 7 |
+
from analyzer import CodeAnalyzer
|
| 8 |
+
|
| 9 |
+
# Load environment variables
|
| 10 |
+
load_dotenv()
|
| 11 |
+
|
| 12 |
+
# Page config
|
| 13 |
+
st.set_page_config(
|
| 14 |
+
page_title="Matrix Code Analyzer - Final",
|
| 15 |
+
page_icon="🟢",
|
| 16 |
+
layout="wide",
|
| 17 |
+
initial_sidebar_state="expanded"
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
# Matrix CSS - Enhanced with file upload styling
|
| 21 |
+
st.markdown("""
|
| 22 |
+
<style>
|
| 23 |
+
@import url('https://fonts.googleapis.com/css2?family=Share+Tech+Mono:wght@400&display=swap');
|
| 24 |
+
@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700;900&display=swap');
|
| 25 |
+
|
| 26 |
+
/* Matrix Background */
|
| 27 |
+
.stApp {
|
| 28 |
+
background: linear-gradient(135deg, #0d1b0d 0%, #000000 50%, #0d1b0d 100%);
|
| 29 |
+
color: #00ff41;
|
| 30 |
+
font-family: 'Share Tech Mono', monospace;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
/* Matrix Code Rain Animation */
|
| 34 |
+
.matrix-bg {
|
| 35 |
+
position: fixed;
|
| 36 |
+
top: 0;
|
| 37 |
+
left: 0;
|
| 38 |
+
width: 100%;
|
| 39 |
+
height: 100%;
|
| 40 |
+
overflow: hidden;
|
| 41 |
+
z-index: -1;
|
| 42 |
+
opacity: 0.1;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
.matrix-char {
|
| 46 |
+
position: absolute;
|
| 47 |
+
color: #00ff41;
|
| 48 |
+
font-family: 'Share Tech Mono', monospace;
|
| 49 |
+
font-size: 14px;
|
| 50 |
+
animation: matrix-fall linear infinite;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
@keyframes matrix-fall {
|
| 54 |
+
0% { transform: translateY(-100vh); opacity: 1; }
|
| 55 |
+
100% { transform: translateY(100vh); opacity: 0; }
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
/* Main Content Styling */
|
| 59 |
+
.main .block-container {
|
| 60 |
+
padding-top: 2rem;
|
| 61 |
+
background: rgba(0, 0, 0, 0.8);
|
| 62 |
+
border: 1px solid #00ff41;
|
| 63 |
+
border-radius: 10px;
|
| 64 |
+
box-shadow: 0 0 20px rgba(0, 255, 65, 0.3);
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
/* Title Styling */
|
| 68 |
+
h1 {
|
| 69 |
+
font-family: 'Orbitron', monospace !important;
|
| 70 |
+
color: #00ff41 !important;
|
| 71 |
+
text-align: center !important;
|
| 72 |
+
text-shadow: 0 0 10px #00ff41, 0 0 20px #00ff41, 0 0 30px #00ff41;
|
| 73 |
+
font-weight: 900 !important;
|
| 74 |
+
margin-bottom: 2rem !important;
|
| 75 |
+
animation: glow 2s ease-in-out infinite alternate;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
@keyframes glow {
|
| 79 |
+
from { text-shadow: 0 0 5px #00ff41, 0 0 10px #00ff41, 0 0 15px #00ff41; }
|
| 80 |
+
to { text-shadow: 0 0 10px #00ff41, 0 0 20px #00ff41, 0 0 30px #00ff41; }
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
/* Sidebar Styling */
|
| 84 |
+
.css-1d391kg {
|
| 85 |
+
background: rgba(0, 0, 0, 0.9) !important;
|
| 86 |
+
border: 1px solid #00ff41 !important;
|
| 87 |
+
border-radius: 10px !important;
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
/* Buttons */
|
| 91 |
+
.stButton > button {
|
| 92 |
+
background: linear-gradient(45deg, #003300, #006600) !important;
|
| 93 |
+
color: #00ff41 !important;
|
| 94 |
+
border: 2px solid #00ff41 !important;
|
| 95 |
+
border-radius: 5px !important;
|
| 96 |
+
font-family: 'Orbitron', monospace !important;
|
| 97 |
+
font-weight: bold !important;
|
| 98 |
+
text-transform: uppercase !important;
|
| 99 |
+
transition: all 0.3s ease !important;
|
| 100 |
+
box-shadow: 0 0 10px rgba(0, 255, 65, 0.3) !important;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
.stButton > button:hover {
|
| 104 |
+
background: linear-gradient(45deg, #006600, #00aa00) !important;
|
| 105 |
+
box-shadow: 0 0 20px rgba(0, 255, 65, 0.6) !important;
|
| 106 |
+
transform: translateY(-2px) !important;
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
/* File uploader styling */
|
| 110 |
+
.stFileUploader > div {
|
| 111 |
+
background: rgba(0, 51, 0, 0.3) !important;
|
| 112 |
+
border: 2px dashed #00ff41 !important;
|
| 113 |
+
border-radius: 10px !important;
|
| 114 |
+
padding: 20px !important;
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
.stFileUploader label {
|
| 118 |
+
color: #00ff41 !important;
|
| 119 |
+
font-family: 'Orbitron', monospace !important;
|
| 120 |
+
font-weight: bold !important;
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
/* Select boxes */
|
| 124 |
+
.stSelectbox > div > div {
|
| 125 |
+
background: rgba(0, 51, 0, 0.8) !important;
|
| 126 |
+
border: 1px solid #00ff41 !important;
|
| 127 |
+
color: #00ff41 !important;
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
/* Text areas */
|
| 131 |
+
.stTextArea > div > div > textarea {
|
| 132 |
+
background: rgba(0, 0, 0, 0.9) !important;
|
| 133 |
+
border: 1px solid #00ff41 !important;
|
| 134 |
+
color: #00ff41 !important;
|
| 135 |
+
font-family: 'Share Tech Mono', monospace !important;
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
/* Metrics */
|
| 139 |
+
.css-1xarl3l {
|
| 140 |
+
background: rgba(0, 51, 0, 0.3) !important;
|
| 141 |
+
border: 1px solid #00ff41 !important;
|
| 142 |
+
border-radius: 5px !important;
|
| 143 |
+
box-shadow: 0 0 10px rgba(0, 255, 65, 0.2) !important;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
/* Success/Info/Warning messages */
|
| 147 |
+
.stSuccess {
|
| 148 |
+
background: rgba(0, 255, 65, 0.1) !important;
|
| 149 |
+
border: 1px solid #00ff41 !important;
|
| 150 |
+
color: #00ff41 !important;
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
.stInfo {
|
| 154 |
+
background: rgba(0, 255, 255, 0.1) !important;
|
| 155 |
+
border: 1px solid #00ffff !important;
|
| 156 |
+
color: #00ffff !important;
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
.stWarning {
|
| 160 |
+
background: rgba(255, 255, 0, 0.1) !important;
|
| 161 |
+
border: 1px solid #ffff00 !important;
|
| 162 |
+
color: #ffff00 !important;
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
.stError {
|
| 166 |
+
background: rgba(255, 0, 0, 0.1) !important;
|
| 167 |
+
border: 1px solid #ff0000 !important;
|
| 168 |
+
color: #ff0000 !important;
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
/* Code blocks */
|
| 172 |
+
.stCode {
|
| 173 |
+
background: rgba(0, 0, 0, 0.9) !important;
|
| 174 |
+
border: 1px solid #00ff41 !important;
|
| 175 |
+
color: #00ff41 !important;
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
/* Tabs */
|
| 179 |
+
.stTabs [data-baseweb="tab-list"] {
|
| 180 |
+
background: rgba(0, 0, 0, 0.8) !important;
|
| 181 |
+
border-bottom: 2px solid #00ff41 !important;
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
.stTabs [data-baseweb="tab"] {
|
| 185 |
+
background: rgba(0, 51, 0, 0.3) !important;
|
| 186 |
+
color: #00ff41 !important;
|
| 187 |
+
border: 1px solid #00ff41 !important;
|
| 188 |
+
font-family: 'Orbitron', monospace !important;
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
.stTabs [aria-selected="true"] {
|
| 192 |
+
background: rgba(0, 255, 65, 0.2) !important;
|
| 193 |
+
box-shadow: 0 0 10px rgba(0, 255, 65, 0.5) !important;
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
/* Matrix Terminal Effect */
|
| 197 |
+
.matrix-terminal {
|
| 198 |
+
background: rgba(0, 0, 0, 0.95) !important;
|
| 199 |
+
border: 2px solid #00ff41 !important;
|
| 200 |
+
border-radius: 10px !important;
|
| 201 |
+
padding: 20px !important;
|
| 202 |
+
font-family: 'Share Tech Mono', monospace !important;
|
| 203 |
+
color: #00ff41 !important;
|
| 204 |
+
box-shadow: 0 0 30px rgba(0, 255, 65, 0.4) !important;
|
| 205 |
+
position: relative !important;
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
.matrix-terminal::before {
|
| 209 |
+
content: "MATRIX_ANALYZER_v3.0 > OPERATIONAL" !important;
|
| 210 |
+
position: absolute !important;
|
| 211 |
+
top: -15px !important;
|
| 212 |
+
left: 20px !important;
|
| 213 |
+
background: #000000 !important;
|
| 214 |
+
padding: 0 10px !important;
|
| 215 |
+
color: #00ff41 !important;
|
| 216 |
+
font-size: 12px !important;
|
| 217 |
+
font-weight: bold !important;
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
/* Checkbox styling */
|
| 221 |
+
.stCheckbox > label {
|
| 222 |
+
color: #00ff41 !important;
|
| 223 |
+
font-family: 'Orbitron', monospace !important;
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
/* Loading spinner */
|
| 227 |
+
.stSpinner > div {
|
| 228 |
+
border-color: #00ff41 transparent #00ff41 transparent !important;
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
/* Expander */
|
| 232 |
+
.streamlit-expanderHeader {
|
| 233 |
+
background: rgba(0, 51, 0, 0.3) !important;
|
| 234 |
+
border: 1px solid #00ff41 !important;
|
| 235 |
+
color: #00ff41 !important;
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
/* File info styling */
|
| 239 |
+
.file-info {
|
| 240 |
+
background: rgba(0, 255, 65, 0.1);
|
| 241 |
+
border: 1px solid #00ff41;
|
| 242 |
+
padding: 10px;
|
| 243 |
+
border-radius: 5px;
|
| 244 |
+
margin: 10px 0;
|
| 245 |
+
font-family: 'Share Tech Mono', monospace;
|
| 246 |
+
}
|
| 247 |
+
</style>
|
| 248 |
+
|
| 249 |
+
<div class="matrix-bg" id="matrix-bg"></div>
|
| 250 |
+
|
| 251 |
+
<script>
|
| 252 |
+
function createMatrixRain() {
|
| 253 |
+
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#$%^&*()_+-=[]{}|;:,.<>?";
|
| 254 |
+
const container = document.getElementById('matrix-bg');
|
| 255 |
+
|
| 256 |
+
for (let i = 0; i < 50; i++) {
|
| 257 |
+
const char = document.createElement('div');
|
| 258 |
+
char.className = 'matrix-char';
|
| 259 |
+
char.textContent = chars[Math.floor(Math.random() * chars.length)];
|
| 260 |
+
char.style.left = Math.random() * 100 + '%';
|
| 261 |
+
char.style.animationDuration = (Math.random() * 3 + 2) + 's';
|
| 262 |
+
char.style.animationDelay = Math.random() * 2 + 's';
|
| 263 |
+
container.appendChild(char);
|
| 264 |
+
}
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
// Create matrix rain effect
|
| 268 |
+
setTimeout(createMatrixRain, 100);
|
| 269 |
+
</script>
|
| 270 |
+
""", unsafe_allow_html=True)
|
| 271 |
+
|
| 272 |
+
# Initialize analyzer
|
| 273 |
+
def get_analyzer():
|
| 274 |
+
# Force reimport to ensure latest code
|
| 275 |
+
import importlib
|
| 276 |
+
import analyzer.code_analyzer
|
| 277 |
+
importlib.reload(analyzer.code_analyzer)
|
| 278 |
+
from analyzer.code_analyzer import CodeAnalyzer
|
| 279 |
+
return CodeAnalyzer()
|
| 280 |
+
|
| 281 |
+
analyzer = get_analyzer()
|
| 282 |
+
|
| 283 |
+
def display_matrix_analysis_result(result: dict, model_name: str):
|
| 284 |
+
"""Display analysis result in clean, readable horizontal blocks."""
|
| 285 |
+
if 'error' in result:
|
| 286 |
+
st.error(f"🚨 SYSTEM ERROR: {result['error']}")
|
| 287 |
+
return
|
| 288 |
+
|
| 289 |
+
# Quality score with modern styling
|
| 290 |
+
score = result['quality_score']
|
| 291 |
+
if score >= 80:
|
| 292 |
+
score_color = "#00ff41"
|
| 293 |
+
status = "EXCELLENT"
|
| 294 |
+
elif score >= 60:
|
| 295 |
+
score_color = "#ffff00"
|
| 296 |
+
status = "ACCEPTABLE"
|
| 297 |
+
else:
|
| 298 |
+
score_color = "#ff0000"
|
| 299 |
+
status = "NEEDS_WORK"
|
| 300 |
+
|
| 301 |
+
# Header with score
|
| 302 |
+
st.markdown(f"""
|
| 303 |
+
<div style="background: linear-gradient(135deg, rgba(0,255,65,0.15), rgba(0,255,65,0.05));
|
| 304 |
+
border: 2px solid #00ff41; border-radius: 15px; padding: 25px; margin: 20px 0;
|
| 305 |
+
text-align: center;">
|
| 306 |
+
<h2 style="color: {score_color}; margin-bottom: 15px; font-size: 1.8rem;">
|
| 307 |
+
{model_name} Analysis
|
| 308 |
+
</h2>
|
| 309 |
+
<div style="display: flex; justify-content: center; gap: 30px; flex-wrap: wrap; color: #ffffff;">
|
| 310 |
+
<div style="text-align: center;">
|
| 311 |
+
<div style="font-size: 2rem; color: {score_color}; font-weight: bold;">{score}/100</div>
|
| 312 |
+
<div style="font-size: 0.9rem; opacity: 0.8;">{status}</div>
|
| 313 |
+
</div>
|
| 314 |
+
<div style="text-align: center;">
|
| 315 |
+
<div style="font-size: 1.2rem; color: #00ff41; font-weight: bold;">{result['language'].upper()}</div>
|
| 316 |
+
<div style="font-size: 0.9rem; opacity: 0.8;">Language</div>
|
| 317 |
+
</div>
|
| 318 |
+
<div style="text-align: center;">
|
| 319 |
+
<div style="font-size: 1.2rem; color: #00ff41; font-weight: bold;">{result['line_count']}</div>
|
| 320 |
+
<div style="font-size: 0.9rem; opacity: 0.8;">Lines</div>
|
| 321 |
+
</div>
|
| 322 |
+
</div>
|
| 323 |
+
</div>
|
| 324 |
+
""", unsafe_allow_html=True)
|
| 325 |
+
|
| 326 |
+
# Summary
|
| 327 |
+
if result.get('summary'):
|
| 328 |
+
st.markdown("### 📋 Code Overview")
|
| 329 |
+
st.markdown(f"""
|
| 330 |
+
<div style="background: rgba(0,0,0,0.6); border: 1px solid #00ff41; border-radius: 10px;
|
| 331 |
+
padding: 20px; margin: 20px 0;">
|
| 332 |
+
<p style="color: #ffffff; font-size: 18px; line-height: 1.6; text-align: center; margin: 0;">
|
| 333 |
+
{result['summary']}
|
| 334 |
+
</p>
|
| 335 |
+
</div>
|
| 336 |
+
""", unsafe_allow_html=True)
|
| 337 |
+
|
| 338 |
+
# Analysis results in horizontal blocks
|
| 339 |
+
st.markdown("### 📊 Analysis Results")
|
| 340 |
+
|
| 341 |
+
# Bug Detection Block (Full width)
|
| 342 |
+
bug_items = result.get('bugs', [])
|
| 343 |
+
if bug_items:
|
| 344 |
+
bug_text = " • ".join(bug_items[:3]) # Join with bullets for horizontal reading
|
| 345 |
+
else:
|
| 346 |
+
bug_text = "No critical bugs detected • Code logic appears sound • Edge cases handled well"
|
| 347 |
+
|
| 348 |
+
st.markdown(f"""
|
| 349 |
+
<div style="background: linear-gradient(135deg, rgba(255,100,100,0.1), rgba(150,0,0,0.1));
|
| 350 |
+
border: 2px solid #ff6b6b; border-radius: 15px; padding: 25px; margin: 15px 0;">
|
| 351 |
+
<h3 style="color: #ff6b6b; margin-bottom: 15px; text-align: center; font-size: 1.4rem;">
|
| 352 |
+
🐛 Bug Detection
|
| 353 |
+
</h3>
|
| 354 |
+
<p style="color: #ffffff; font-size: 16px; line-height: 1.6; text-align: center; margin: 0;">
|
| 355 |
+
{bug_text}
|
| 356 |
+
</p>
|
| 357 |
+
</div>
|
| 358 |
+
""", unsafe_allow_html=True)
|
| 359 |
+
|
| 360 |
+
# Security Vulnerabilities Block (Full width)
|
| 361 |
+
security_items = result.get('security_vulnerabilities', [])
|
| 362 |
+
if security_items:
|
| 363 |
+
security_text = " • ".join(security_items[:3]) # Join with bullets for horizontal reading
|
| 364 |
+
else:
|
| 365 |
+
security_text = "No security vulnerabilities found • Follows security best practices • Input validation looks good"
|
| 366 |
+
|
| 367 |
+
st.markdown(f"""
|
| 368 |
+
<div style="background: linear-gradient(135deg, rgba(200,0,200,0.1), rgba(100,0,100,0.1));
|
| 369 |
+
border: 2px solid #ff00ff; border-radius: 15px; padding: 25px; margin: 15px 0;">
|
| 370 |
+
<h3 style="color: #ff00ff; margin-bottom: 15px; text-align: center; font-size: 1.4rem;">
|
| 371 |
+
🔒 Security Check
|
| 372 |
+
</h3>
|
| 373 |
+
<p style="color: #ffffff; font-size: 16px; line-height: 1.6; text-align: center; margin: 0;">
|
| 374 |
+
{security_text}
|
| 375 |
+
</p>
|
| 376 |
+
</div>
|
| 377 |
+
""", unsafe_allow_html=True)
|
| 378 |
+
|
| 379 |
+
# Code Quality & Quick Fixes Block (Full width)
|
| 380 |
+
quality_items = result.get('quality_issues', []) + result.get('quick_fixes', [])
|
| 381 |
+
if quality_items:
|
| 382 |
+
quality_text = " • ".join(quality_items[:3]) # Join with bullets for horizontal reading
|
| 383 |
+
else:
|
| 384 |
+
quality_text = "Code is well-structured • Good naming conventions • Easy to read and maintain"
|
| 385 |
+
|
| 386 |
+
st.markdown(f"""
|
| 387 |
+
<div style="background: linear-gradient(135deg, rgba(0,200,255,0.1), rgba(0,100,150,0.1));
|
| 388 |
+
border: 2px solid #00ccff; border-radius: 15px; padding: 25px; margin: 15px 0;">
|
| 389 |
+
<h3 style="color: #00ccff; margin-bottom: 15px; text-align: center; font-size: 1.4rem;">
|
| 390 |
+
📝 Code Quality
|
| 391 |
+
</h3>
|
| 392 |
+
<p style="color: #ffffff; font-size: 16px; line-height: 1.6; text-align: center; margin: 0;">
|
| 393 |
+
{quality_text}
|
| 394 |
+
</p>
|
| 395 |
+
</div>
|
| 396 |
+
""", unsafe_allow_html=True)
|
| 397 |
+
|
| 398 |
+
# Legacy sections (only if new sections are empty)
|
| 399 |
+
if not result.get('bugs') and not result.get('security_vulnerabilities') and not result.get('quality_issues'):
|
| 400 |
+
legacy_col1, legacy_col2 = st.columns(2)
|
| 401 |
+
|
| 402 |
+
with legacy_col1:
|
| 403 |
+
# Legacy strengths
|
| 404 |
+
if result.get('strengths'):
|
| 405 |
+
st.markdown("#### ✅ Strengths")
|
| 406 |
+
for strength in result['strengths'][:3]:
|
| 407 |
+
st.success(f"✓ {strength}")
|
| 408 |
+
|
| 409 |
+
# Legacy issues
|
| 410 |
+
if result.get('issues'):
|
| 411 |
+
st.markdown("#### ⚠️ Issues")
|
| 412 |
+
for issue in result['issues'][:3]:
|
| 413 |
+
st.warning(f"! {issue}")
|
| 414 |
+
|
| 415 |
+
with legacy_col2:
|
| 416 |
+
# Legacy suggestions
|
| 417 |
+
if result.get('suggestions'):
|
| 418 |
+
st.markdown("#### 💡 Suggestions")
|
| 419 |
+
for suggestion in result['suggestions'][:3]:
|
| 420 |
+
st.info(f"→ {suggestion}")
|
| 421 |
+
|
| 422 |
+
# Legacy security concerns
|
| 423 |
+
if result.get('security_concerns'):
|
| 424 |
+
st.markdown("#### 🔒 Security Concerns")
|
| 425 |
+
for concern in result['security_concerns'][:3]:
|
| 426 |
+
st.error(f"⚠ {concern}")
|
| 427 |
+
|
| 428 |
+
# Expandable raw response (moved to bottom and less prominent)
|
| 429 |
+
with st.expander("🔍 View Detailed Analysis", expanded=False):
|
| 430 |
+
st.code(result.get('raw_response', 'NO_DATA_AVAILABLE'), language='text')
|
| 431 |
+
|
| 432 |
+
def display_github_analysis_result(result: dict, model_name: str):
|
| 433 |
+
"""Display GitHub repository analysis result in clean, readable horizontal blocks."""
|
| 434 |
+
if 'error' in result:
|
| 435 |
+
st.error(f"🚨 GITHUB ANALYSIS ERROR: {result['error']}")
|
| 436 |
+
return
|
| 437 |
+
|
| 438 |
+
# Repository info in a clean header
|
| 439 |
+
if result.get('repository_info'):
|
| 440 |
+
repo_info = result['repository_info']
|
| 441 |
+
st.markdown(f"""
|
| 442 |
+
<div style="background: linear-gradient(135deg, rgba(0,255,65,0.15), rgba(0,255,65,0.05));
|
| 443 |
+
border: 2px solid #00ff41; border-radius: 15px; padding: 25px; margin: 20px 0;
|
| 444 |
+
text-align: center;">
|
| 445 |
+
<h2 style="color: #00ff41; margin-bottom: 20px; font-size: 1.8rem;">
|
| 446 |
+
📦 {repo_info['name']}
|
| 447 |
+
</h2>
|
| 448 |
+
<div style="display: flex; justify-content: center; gap: 30px; flex-wrap: wrap; color: #ffffff;">
|
| 449 |
+
<div style="text-align: center;">
|
| 450 |
+
<div style="font-size: 1.5rem; color: #00ff41; font-weight: bold;">{repo_info['language']}</div>
|
| 451 |
+
<div style="font-size: 0.9rem; opacity: 0.8;">Language</div>
|
| 452 |
+
</div>
|
| 453 |
+
<div style="text-align: center;">
|
| 454 |
+
<div style="font-size: 1.5rem; color: #00ff41; font-weight: bold;">⭐ {repo_info['stars']}</div>
|
| 455 |
+
<div style="font-size: 0.9rem; opacity: 0.8;">Stars</div>
|
| 456 |
+
</div>
|
| 457 |
+
<div style="text-align: center;">
|
| 458 |
+
<div style="font-size: 1.5rem; color: #00ff41; font-weight: bold;">🔀 {repo_info['forks']}</div>
|
| 459 |
+
<div style="font-size: 0.9rem; opacity: 0.8;">Forks</div>
|
| 460 |
+
</div>
|
| 461 |
+
</div>
|
| 462 |
+
<p style="color: #ffffff; margin-top: 15px; font-style: italic;">
|
| 463 |
+
"{repo_info['description']}"
|
| 464 |
+
</p>
|
| 465 |
+
</div>
|
| 466 |
+
""", unsafe_allow_html=True)
|
| 467 |
+
|
| 468 |
+
# Analysis results in horizontal blocks
|
| 469 |
+
st.markdown("### 📊 Analysis Results")
|
| 470 |
+
|
| 471 |
+
# Architecture Quality Block (Full width)
|
| 472 |
+
arch_items = result.get('architecture_quality', [])
|
| 473 |
+
if arch_items:
|
| 474 |
+
arch_text = " • ".join(arch_items[:3]) # Join with bullets for horizontal reading
|
| 475 |
+
else:
|
| 476 |
+
arch_text = "Well-structured repository • Good organization • Follows best practices"
|
| 477 |
+
|
| 478 |
+
st.markdown(f"""
|
| 479 |
+
<div style="background: linear-gradient(135deg, rgba(0,255,65,0.1), rgba(0,100,30,0.1));
|
| 480 |
+
border: 2px solid #00ff41; border-radius: 15px; padding: 25px; margin: 15px 0;">
|
| 481 |
+
<h3 style="color: #00ff41; margin-bottom: 15px; text-align: center; font-size: 1.4rem;">
|
| 482 |
+
🏗️ Code Architecture
|
| 483 |
+
</h3>
|
| 484 |
+
<p style="color: #ffffff; font-size: 16px; line-height: 1.6; text-align: center; margin: 0;">
|
| 485 |
+
{arch_text}
|
| 486 |
+
</p>
|
| 487 |
+
</div>
|
| 488 |
+
""", unsafe_allow_html=True)
|
| 489 |
+
|
| 490 |
+
# Critical Issues Block (Full width)
|
| 491 |
+
critical_items = result.get('critical_issues', [])
|
| 492 |
+
if critical_items:
|
| 493 |
+
critical_text = " • ".join(critical_items[:3]) # Join with bullets for horizontal reading
|
| 494 |
+
else:
|
| 495 |
+
critical_text = "No major security vulnerabilities found • Code appears well-maintained • No critical bugs detected"
|
| 496 |
+
|
| 497 |
+
st.markdown(f"""
|
| 498 |
+
<div style="background: linear-gradient(135deg, rgba(255,100,100,0.1), rgba(150,0,0,0.1));
|
| 499 |
+
border: 2px solid #ff6b6b; border-radius: 15px; padding: 25px; margin: 15px 0;">
|
| 500 |
+
<h3 style="color: #ff6b6b; margin-bottom: 15px; text-align: center; font-size: 1.4rem;">
|
| 501 |
+
🚨 Critical Issues
|
| 502 |
+
</h3>
|
| 503 |
+
<p style="color: #ffffff; font-size: 16px; line-height: 1.6; text-align: center; margin: 0;">
|
| 504 |
+
{critical_text}
|
| 505 |
+
</p>
|
| 506 |
+
</div>
|
| 507 |
+
""", unsafe_allow_html=True)
|
| 508 |
+
|
| 509 |
+
# Improvement Priorities Block (Full width)
|
| 510 |
+
improvement_items = result.get('improvement_priorities', [])
|
| 511 |
+
if improvement_items:
|
| 512 |
+
improvement_text = " • ".join(improvement_items[:3]) # Join with bullets for horizontal reading
|
| 513 |
+
else:
|
| 514 |
+
improvement_text = "Add more comprehensive documentation • Consider adding automated tests • Enhance error handling"
|
| 515 |
+
|
| 516 |
+
st.markdown(f"""
|
| 517 |
+
<div style="background: linear-gradient(135deg, rgba(255,200,0,0.1), rgba(150,100,0,0.1));
|
| 518 |
+
border: 2px solid #ffd700; border-radius: 15px; padding: 25px; margin: 15px 0;">
|
| 519 |
+
<h3 style="color: #ffd700; margin-bottom: 15px; text-align: center; font-size: 1.4rem;">
|
| 520 |
+
🎯 Priority Improvements
|
| 521 |
+
</h3>
|
| 522 |
+
<p style="color: #ffffff; font-size: 16px; line-height: 1.6; text-align: center; margin: 0;">
|
| 523 |
+
{improvement_text}
|
| 524 |
+
</p>
|
| 525 |
+
</div>
|
| 526 |
+
""", unsafe_allow_html=True)
|
| 527 |
+
|
| 528 |
+
# Summary section at the bottom (if available)
|
| 529 |
+
if result.get('project_overview'):
|
| 530 |
+
st.markdown("### 💡 Key Insights")
|
| 531 |
+
st.markdown(f"""
|
| 532 |
+
<div style="background: rgba(0,0,0,0.6); border: 1px solid #00ff41; border-radius: 10px;
|
| 533 |
+
padding: 20px; margin: 20px 0;">
|
| 534 |
+
<p style="color: #ffffff; font-size: 18px; line-height: 1.6; text-align: center; margin: 0;">
|
| 535 |
+
{result['project_overview']}
|
| 536 |
+
</p>
|
| 537 |
+
</div>
|
| 538 |
+
""", unsafe_allow_html=True)
|
| 539 |
+
|
| 540 |
+
# Expandable raw response (moved to bottom and less prominent)
|
| 541 |
+
with st.expander("🔍 View Detailed Analysis", expanded=False):
|
| 542 |
+
st.code(result.get('raw_response', 'NO_DATA_AVAILABLE'), language='text')
|
| 543 |
+
|
| 544 |
+
# Header with Matrix effect
|
| 545 |
+
st.markdown("""
|
| 546 |
+
<h1 style="text-align: center;">
|
| 547 |
+
🤖 AI Code Analyzer
|
| 548 |
+
</h1>
|
| 549 |
+
<div style="text-align: center; margin-bottom: 30px;">
|
| 550 |
+
<p style="color: #00ff41; font-family: 'Orbitron', monospace; font-size: 20px; margin-bottom: 10px;">
|
| 551 |
+
<strong>Powered by Advanced AI Models</strong>
|
| 552 |
+
</p>
|
| 553 |
+
<div style="display: flex; justify-content: center; gap: 20px; flex-wrap: wrap;">
|
| 554 |
+
<span style="background: rgba(0,255,65,0.2); border: 1px solid #00ff41; padding: 8px 16px;
|
| 555 |
+
border-radius: 25px; font-size: 14px; color: #00ff41;">
|
| 556 |
+
✨ Bug Detection
|
| 557 |
+
</span>
|
| 558 |
+
<span style="background: rgba(0,255,65,0.2); border: 1px solid #00ff41; padding: 8px 16px;
|
| 559 |
+
border-radius: 25px; font-size: 14px; color: #00ff41;">
|
| 560 |
+
🔒 Security Analysis
|
| 561 |
+
</span>
|
| 562 |
+
<span style="background: rgba(0,255,65,0.2); border: 1px solid #00ff41; padding: 8px 16px;
|
| 563 |
+
border-radius: 25px; font-size: 14px; color: #00ff41;">
|
| 564 |
+
📦 GitHub Integration
|
| 565 |
+
</span>
|
| 566 |
+
<span style="background: rgba(0,255,65,0.2); border: 1px solid #00ff41; padding: 8px 16px;
|
| 567 |
+
border-radius: 25px; font-size: 14px; color: #00ff41;">
|
| 568 |
+
⚡ Instant Results
|
| 569 |
+
</span>
|
| 570 |
+
</div>
|
| 571 |
+
</div>
|
| 572 |
+
""", unsafe_allow_html=True)
|
| 573 |
+
|
| 574 |
+
# Sidebar - The Matrix Control Panel
|
| 575 |
+
with st.sidebar:
|
| 576 |
+
st.markdown("### 🎛️ Control Panel")
|
| 577 |
+
|
| 578 |
+
# Model status
|
| 579 |
+
st.markdown("#### Available AI Models")
|
| 580 |
+
available_models = analyzer.available_models
|
| 581 |
+
|
| 582 |
+
if not available_models:
|
| 583 |
+
st.error("❌ No AI models detected")
|
| 584 |
+
st.info("Please configure API keys in .env file")
|
| 585 |
+
st.stop()
|
| 586 |
+
|
| 587 |
+
# Display available models with modern styling
|
| 588 |
+
for model, display_name in available_models.items():
|
| 589 |
+
st.markdown(f"""
|
| 590 |
+
<div style="background: rgba(0, 255, 65, 0.1); border: 1px solid #00ff41; padding: 10px; margin: 8px 0; border-radius: 8px;">
|
| 591 |
+
✅ <strong>{display_name}</strong> <span style="color: #00ff41; font-size: 12px;">[Ready]</span>
|
| 592 |
+
</div>
|
| 593 |
+
""", unsafe_allow_html=True)
|
| 594 |
+
|
| 595 |
+
st.markdown("---")
|
| 596 |
+
|
| 597 |
+
# Analysis Mode Selection
|
| 598 |
+
st.markdown("#### Analysis Mode")
|
| 599 |
+
analysis_mode = st.radio(
|
| 600 |
+
"Choose what to analyze",
|
| 601 |
+
["Code Analysis", "GitHub Repository"],
|
| 602 |
+
format_func=lambda x: f"📝 {x}" if x == "Code Analysis" else f"📦 {x}"
|
| 603 |
+
)
|
| 604 |
+
|
| 605 |
+
if analysis_mode == "GitHub Repository":
|
| 606 |
+
st.markdown("#### Repository Analysis")
|
| 607 |
+
github_url = st.text_input(
|
| 608 |
+
"GitHub URL",
|
| 609 |
+
placeholder="https://github.com/owner/repo",
|
| 610 |
+
help="Enter a GitHub repository URL for analysis"
|
| 611 |
+
)
|
| 612 |
+
|
| 613 |
+
analyze_github_button = st.button(
|
| 614 |
+
"🔍 Analyze Repository",
|
| 615 |
+
type="primary",
|
| 616 |
+
help="Analyze GitHub repository structure and code"
|
| 617 |
+
)
|
| 618 |
+
|
| 619 |
+
st.markdown("---")
|
| 620 |
+
|
| 621 |
+
# Analysis options
|
| 622 |
+
st.markdown("#### Analysis Settings")
|
| 623 |
+
|
| 624 |
+
# Model selector with modern styling
|
| 625 |
+
selected_model = st.selectbox(
|
| 626 |
+
"Choose AI Model",
|
| 627 |
+
options=list(available_models.keys()),
|
| 628 |
+
format_func=lambda x: f"🤖 {available_models[x]}"
|
| 629 |
+
)
|
| 630 |
+
|
| 631 |
+
# Multi-model analysis toggle
|
| 632 |
+
analyze_all = st.checkbox("🔄 Compare Multiple Models", value=False)
|
| 633 |
+
|
| 634 |
+
# Language selection
|
| 635 |
+
languages = ["auto-detect", "python", "javascript", "java", "cpp", "csharp", "go", "rust", "php", "ruby", "swift", "kotlin"]
|
| 636 |
+
selected_language = st.selectbox(
|
| 637 |
+
"Programming Language",
|
| 638 |
+
languages,
|
| 639 |
+
format_func=lambda x: "🔍 Auto-Detect" if x == "auto-detect" else f"💻 {x.upper()}"
|
| 640 |
+
)
|
| 641 |
+
|
| 642 |
+
st.markdown("---")
|
| 643 |
+
|
| 644 |
+
# Sample code injection
|
| 645 |
+
st.markdown("#### Quick Start Examples")
|
| 646 |
+
|
| 647 |
+
if st.button("🐍 Try Python Example"):
|
| 648 |
+
st.session_state.code_input = """def calculate_total(items):
|
| 649 |
+
total = 0
|
| 650 |
+
for item in items:
|
| 651 |
+
total += item.price # Potential AttributeError
|
| 652 |
+
return total
|
| 653 |
+
|
| 654 |
+
# Missing validation
|
| 655 |
+
items = None
|
| 656 |
+
result = calculate_total(items) # This will crash
|
| 657 |
+
print(f"Total: {result}")
|
| 658 |
+
"""
|
| 659 |
+
|
| 660 |
+
if st.button("🌐 Try JavaScript Example"):
|
| 661 |
+
st.session_state.code_input = """function processUser(user) {
|
| 662 |
+
// Security issue: no input validation
|
| 663 |
+
document.innerHTML = user.name; // XSS vulnerability
|
| 664 |
+
|
| 665 |
+
// Logic error: undefined check
|
| 666 |
+
if (user.age > 18) {
|
| 667 |
+
return user.permissions.admin; // Potential TypeError
|
| 668 |
+
}
|
| 669 |
+
|
| 670 |
+
return false;
|
| 671 |
+
}
|
| 672 |
+
|
| 673 |
+
// Missing error handling
|
| 674 |
+
const userData = getUser(); // Could be undefined
|
| 675 |
+
processUser(userData);
|
| 676 |
+
"""
|
| 677 |
+
|
| 678 |
+
# Main Terminal Interface
|
| 679 |
+
col1, col2 = st.columns([1, 1])
|
| 680 |
+
|
| 681 |
+
with col1:
|
| 682 |
+
if analysis_mode == "Code Analysis":
|
| 683 |
+
st.markdown("### 📝 Code Input")
|
| 684 |
+
|
| 685 |
+
# File upload section
|
| 686 |
+
st.markdown("#### 📁 Upload File")
|
| 687 |
+
uploaded_file = st.file_uploader(
|
| 688 |
+
"Choose a code file",
|
| 689 |
+
type=['py', 'js', 'java', 'cpp', 'c', 'cs', 'go', 'rs', 'php', 'rb', 'swift', 'kt', 'txt'],
|
| 690 |
+
help="Upload code files for AI analysis"
|
| 691 |
+
)
|
| 692 |
+
|
| 693 |
+
code_from_file = ""
|
| 694 |
+
if uploaded_file is not None:
|
| 695 |
+
# Read file content
|
| 696 |
+
try:
|
| 697 |
+
code_from_file = str(uploaded_file.read(), "utf-8")
|
| 698 |
+
file_size = len(code_from_file)
|
| 699 |
+
file_lines = len(code_from_file.splitlines())
|
| 700 |
+
|
| 701 |
+
st.markdown(f"""
|
| 702 |
+
<div class="file-info">
|
| 703 |
+
✅ <strong>File Uploaded Successfully</strong><br>
|
| 704 |
+
📄 <strong>Name:</strong> {uploaded_file.name}<br>
|
| 705 |
+
📏 <strong>Size:</strong> {file_size} bytes<br>
|
| 706 |
+
📊 <strong>Lines:</strong> {file_lines}<br>
|
| 707 |
+
🔍 <strong>Status:</strong> Ready for analysis
|
| 708 |
+
</div>
|
| 709 |
+
""", unsafe_allow_html=True)
|
| 710 |
+
|
| 711 |
+
# Auto-populate the text area
|
| 712 |
+
st.session_state.code_input = code_from_file
|
| 713 |
+
|
| 714 |
+
except UnicodeDecodeError:
|
| 715 |
+
st.error("🚨 File encoding error: Please use UTF-8 encoded files")
|
| 716 |
+
except Exception as e:
|
| 717 |
+
st.error(f"🚨 File read error: {str(e)}")
|
| 718 |
+
|
| 719 |
+
# Code input with modern styling
|
| 720 |
+
code_input = st.text_area(
|
| 721 |
+
"Or paste your code here",
|
| 722 |
+
value=st.session_state.get('code_input', ''),
|
| 723 |
+
height=350,
|
| 724 |
+
key="code_input",
|
| 725 |
+
help="Paste code directly or upload file above"
|
| 726 |
+
)
|
| 727 |
+
|
| 728 |
+
# Modern analyze button
|
| 729 |
+
analyze_button = st.button(
|
| 730 |
+
"🚀 Analyze Code",
|
| 731 |
+
type="primary",
|
| 732 |
+
help="Analyze your code with AI"
|
| 733 |
+
)
|
| 734 |
+
|
| 735 |
+
else: # GitHub Repository mode
|
| 736 |
+
st.markdown("### 📦 GitHub Analysis")
|
| 737 |
+
|
| 738 |
+
if 'github_url' in locals():
|
| 739 |
+
if github_url:
|
| 740 |
+
st.markdown(f"""
|
| 741 |
+
<div class="file-info">
|
| 742 |
+
✅ <strong>Repository Detected</strong><br>
|
| 743 |
+
📦 <strong>URL:</strong> {github_url}<br>
|
| 744 |
+
🔍 <strong>Status:</strong> Ready for analysis
|
| 745 |
+
</div>
|
| 746 |
+
""", unsafe_allow_html=True)
|
| 747 |
+
|
| 748 |
+
st.markdown("""
|
| 749 |
+
#### 📋 What We'll Analyze
|
| 750 |
+
|
| 751 |
+
**Repository Analysis includes:**
|
| 752 |
+
- 🏗️ Project structure and organization
|
| 753 |
+
- 📄 Key files (README, package.json, main source files)
|
| 754 |
+
- 🎯 Code quality and architecture assessment
|
| 755 |
+
- 🔒 Security vulnerabilities across the codebase
|
| 756 |
+
- 💡 Best practices and improvement suggestions
|
| 757 |
+
|
| 758 |
+
**Note:** Only public repositories can be analyzed.
|
| 759 |
+
""")
|
| 760 |
+
|
| 761 |
+
# Show sample repos
|
| 762 |
+
st.markdown("#### 📚 Try These Sample Repositories")
|
| 763 |
+
sample_repos = [
|
| 764 |
+
"https://github.com/microsoft/vscode",
|
| 765 |
+
"https://github.com/facebook/react",
|
| 766 |
+
"https://github.com/python/cpython"
|
| 767 |
+
]
|
| 768 |
+
|
| 769 |
+
for repo in sample_repos:
|
| 770 |
+
if st.button(f"📦 {repo.split('/')[-1]}", key=repo):
|
| 771 |
+
st.session_state.github_url_input = repo
|
| 772 |
+
|
| 773 |
+
# Results Terminal
|
| 774 |
+
with col2:
|
| 775 |
+
st.markdown("### 📊 Analysis Results")
|
| 776 |
+
|
| 777 |
+
# Code Analysis Results
|
| 778 |
+
if analysis_mode == "Code Analysis":
|
| 779 |
+
if analyze_button:
|
| 780 |
+
if not code_input.strip():
|
| 781 |
+
st.error("🚨 Please enter some code to analyze or upload a file!")
|
| 782 |
+
else:
|
| 783 |
+
with st.spinner("🟢 Analyzing your code... Please wait..."):
|
| 784 |
+
if analyze_all:
|
| 785 |
+
# Multi-model analysis
|
| 786 |
+
st.markdown("#### 🔄 MULTI_NETWORK_ANALYSIS_INITIATED")
|
| 787 |
+
|
| 788 |
+
results = analyzer.analyze_with_all_models(
|
| 789 |
+
code_input,
|
| 790 |
+
selected_language if selected_language != "auto-detect" else None
|
| 791 |
+
)
|
| 792 |
+
|
| 793 |
+
# Display comparison metrics
|
| 794 |
+
comparison = analyzer.compare_analyses(results)
|
| 795 |
+
|
| 796 |
+
# Matrix-styled metrics
|
| 797 |
+
metrics_cols = st.columns(4)
|
| 798 |
+
with metrics_cols[0]:
|
| 799 |
+
st.metric("AVG_SCORE", f"{comparison['average_score']}/100")
|
| 800 |
+
with metrics_cols[1]:
|
| 801 |
+
st.metric("NETWORKS", len(results))
|
| 802 |
+
with metrics_cols[2]:
|
| 803 |
+
st.metric("PEAK_SCORE", f"{max(comparison['model_scores'].values())}/100")
|
| 804 |
+
with metrics_cols[3]:
|
| 805 |
+
st.metric("SCAN_TIME", f"{comparison['analysis_time']:.1f}s")
|
| 806 |
+
|
| 807 |
+
# Create tabs for each neural network
|
| 808 |
+
tab_names = [f"🤖 {available_models[key]}" for key in results.keys()]
|
| 809 |
+
tabs = st.tabs(tab_names)
|
| 810 |
+
|
| 811 |
+
for idx, (model_key, result) in enumerate(results.items()):
|
| 812 |
+
with tabs[idx]:
|
| 813 |
+
display_matrix_analysis_result(result, available_models[model_key])
|
| 814 |
+
|
| 815 |
+
# Consensus findings with Matrix styling
|
| 816 |
+
if comparison.get('consensus_bugs') or comparison.get('consensus_security'):
|
| 817 |
+
st.markdown("### 🤝 NEURAL_CONSENSUS_DETECTED")
|
| 818 |
+
st.markdown("""
|
| 819 |
+
<div style="background: rgba(255, 0, 0, 0.1); border: 2px solid #ff0000; padding: 15px; border-radius: 10px;">
|
| 820 |
+
<strong>CRITICAL_PATTERNS_IDENTIFIED_BY_MULTIPLE_NETWORKS:</strong>
|
| 821 |
+
</div>
|
| 822 |
+
""", unsafe_allow_html=True)
|
| 823 |
+
|
| 824 |
+
if comparison.get('consensus_bugs'):
|
| 825 |
+
st.markdown("#### 🐛 CONSENSUS_BUGS")
|
| 826 |
+
for bug in comparison['consensus_bugs']:
|
| 827 |
+
st.error(f"🚨 MULTIPLE_MODELS: {bug}")
|
| 828 |
+
|
| 829 |
+
if comparison.get('consensus_security'):
|
| 830 |
+
st.markdown("#### 🔒 CONSENSUS_SECURITY")
|
| 831 |
+
for vuln in comparison['consensus_security']:
|
| 832 |
+
st.error(f"🚨 SECURITY_ALERT: {vuln}")
|
| 833 |
+
|
| 834 |
+
else:
|
| 835 |
+
# Single model analysis
|
| 836 |
+
st.markdown(f"#### 🤖 {available_models[selected_model].upper()}_ANALYSIS")
|
| 837 |
+
|
| 838 |
+
result = analyzer.analyze_code(
|
| 839 |
+
code_input,
|
| 840 |
+
selected_model,
|
| 841 |
+
selected_language if selected_language != "auto-detect" else None
|
| 842 |
+
)
|
| 843 |
+
display_matrix_analysis_result(result, available_models[selected_model])
|
| 844 |
+
|
| 845 |
+
# GitHub Analysis Results
|
| 846 |
+
else: # GitHub Repository mode
|
| 847 |
+
if 'analyze_github_button' in locals() and analyze_github_button:
|
| 848 |
+
if not github_url.strip():
|
| 849 |
+
st.error("🚨 Please enter a GitHub repository URL!")
|
| 850 |
+
else:
|
| 851 |
+
with st.spinner("🟢 Analyzing GitHub repository... Please wait..."):
|
| 852 |
+
result = analyzer.analyze_github_repo(github_url, selected_model)
|
| 853 |
+
display_github_analysis_result(result, available_models[selected_model])
|
| 854 |
+
|
| 855 |
+
# Instructions for new users
|
| 856 |
+
if (analysis_mode == "Code Analysis" and not code_input.strip() and not analyze_button) or \
|
| 857 |
+
(analysis_mode == "GitHub Repository" and ('github_url' not in locals() or not github_url.strip()) and ('analyze_github_button' not in locals() or not analyze_github_button)):
|
| 858 |
+
|
| 859 |
+
st.markdown("""
|
| 860 |
+
<div class="matrix-terminal" style="margin: 20px 0; text-align: center;">
|
| 861 |
+
<h2 style="color: #00ff41; margin-bottom: 30px; font-size: 2.5rem;">
|
| 862 |
+
🤖 AI Code Analyzer
|
| 863 |
+
</h2>
|
| 864 |
+
<p style="color: #00ff41; font-size: 1.3rem; margin-bottom: 30px;">
|
| 865 |
+
<strong>What can I do for you?</strong>
|
| 866 |
+
</p>
|
| 867 |
+
</div>
|
| 868 |
+
""", unsafe_allow_html=True)
|
| 869 |
+
|
| 870 |
+
# Feature cards in columns
|
| 871 |
+
feature_col1, feature_col2 = st.columns(2)
|
| 872 |
+
|
| 873 |
+
with feature_col1:
|
| 874 |
+
st.markdown("""
|
| 875 |
+
<div style="background: linear-gradient(135deg, rgba(0,255,65,0.1), rgba(0,255,65,0.05));
|
| 876 |
+
border: 2px solid #00ff41; border-radius: 15px; padding: 25px; margin: 10px 0;
|
| 877 |
+
box-shadow: 0 0 20px rgba(0,255,65,0.3);">
|
| 878 |
+
<h3 style="color: #00ff41; margin-bottom: 15px;">🐛 Find Bugs Instantly</h3>
|
| 879 |
+
<p style="color: #ffffff; font-size: 16px; line-height: 1.6;">
|
| 880 |
+
Spot crashes, logical errors, and edge cases before they hit production.
|
| 881 |
+
</p>
|
| 882 |
+
</div>
|
| 883 |
+
""", unsafe_allow_html=True)
|
| 884 |
+
|
| 885 |
+
st.markdown("""
|
| 886 |
+
<div style="background: linear-gradient(135deg, rgba(0,255,65,0.1), rgba(0,255,65,0.05));
|
| 887 |
+
border: 2px solid #00ff41; border-radius: 15px; padding: 25px; margin: 10px 0;
|
| 888 |
+
box-shadow: 0 0 20px rgba(0,255,65,0.3);">
|
| 889 |
+
<h3 style="color: #00ff41; margin-bottom: 15px;">🔒 Security Scanner</h3>
|
| 890 |
+
<p style="color: #ffffff; font-size: 16px; line-height: 1.6;">
|
| 891 |
+
Detect vulnerabilities like SQL injection, XSS, and insecure data handling.
|
| 892 |
+
</p>
|
| 893 |
+
</div>
|
| 894 |
+
""", unsafe_allow_html=True)
|
| 895 |
+
|
| 896 |
+
with feature_col2:
|
| 897 |
+
st.markdown("""
|
| 898 |
+
<div style="background: linear-gradient(135deg, rgba(0,255,65,0.1), rgba(0,255,65,0.05));
|
| 899 |
+
border: 2px solid #00ff41; border-radius: 15px; padding: 25px; margin: 10px 0;
|
| 900 |
+
box-shadow: 0 0 20px rgba(0,255,65,0.3);">
|
| 901 |
+
<h3 style="color: #00ff41; margin-bottom: 15px;">📝 Code Quality Check</h3>
|
| 902 |
+
<p style="color: #ffffff; font-size: 16px; line-height: 1.6;">
|
| 903 |
+
Improve readability, maintainability, and follow best practices.
|
| 904 |
+
</p>
|
| 905 |
+
</div>
|
| 906 |
+
""", unsafe_allow_html=True)
|
| 907 |
+
|
| 908 |
+
st.markdown("""
|
| 909 |
+
<div style="background: linear-gradient(135deg, rgba(0,255,65,0.1), rgba(0,255,65,0.05));
|
| 910 |
+
border: 2px solid #00ff41; border-radius: 15px; padding: 25px; margin: 10px 0;
|
| 911 |
+
box-shadow: 0 0 20px rgba(0,255,65,0.3);">
|
| 912 |
+
<h3 style="color: #00ff41; margin-bottom: 15px;">📦 Repository Analysis</h3>
|
| 913 |
+
<p style="color: #ffffff; font-size: 16px; line-height: 1.6;">
|
| 914 |
+
Analyze entire GitHub repos for structure, issues, and improvements.
|
| 915 |
+
</p>
|
| 916 |
+
</div>
|
| 917 |
+
""", unsafe_allow_html=True)
|
| 918 |
+
|
| 919 |
+
# How to get started section
|
| 920 |
+
st.markdown("""
|
| 921 |
+
<div style="background: rgba(0,0,0,0.7); border: 1px solid #00ff41; border-radius: 10px;
|
| 922 |
+
padding: 20px; margin: 30px 0; text-align: center;">
|
| 923 |
+
<h3 style="color: #00ff41; margin-bottom: 20px;">🚀 Get Started in 3 Steps</h3>
|
| 924 |
+
<div style="display: flex; justify-content: space-around; flex-wrap: wrap;">
|
| 925 |
+
<div style="margin: 10px; color: #ffffff;">
|
| 926 |
+
<div style="background: #00ff41; color: #000; border-radius: 50%; width: 40px; height: 40px;
|
| 927 |
+
display: flex; align-items: center; justify-content: center; margin: 0 auto 10px;
|
| 928 |
+
font-weight: bold; font-size: 20px;">1</div>
|
| 929 |
+
<p><strong>Upload</strong><br>Paste code or GitHub URL</p>
|
| 930 |
+
</div>
|
| 931 |
+
<div style="margin: 10px; color: #ffffff;">
|
| 932 |
+
<div style="background: #00ff41; color: #000; border-radius: 50%; width: 40px; height: 40px;
|
| 933 |
+
display: flex; align-items: center; justify-content: center; margin: 0 auto 10px;
|
| 934 |
+
font-weight: bold; font-size: 20px;">2</div>
|
| 935 |
+
<p><strong>Choose AI</strong><br>Pick your preferred model</p>
|
| 936 |
+
</div>
|
| 937 |
+
<div style="margin: 10px; color: #ffffff;">
|
| 938 |
+
<div style="background: #00ff41; color: #000; border-radius: 50%; width: 40px; height: 40px;
|
| 939 |
+
display: flex; align-items: center; justify-content: center; margin: 0 auto 10px;
|
| 940 |
+
font-weight: bold; font-size: 20px;">3</div>
|
| 941 |
+
<p><strong>Analyze</strong><br>Get instant results</p>
|
| 942 |
+
</div>
|
| 943 |
+
</div>
|
| 944 |
+
</div>
|
| 945 |
+
""", unsafe_allow_html=True)
|
| 946 |
+
|
| 947 |
+
# Supported languages as badges
|
| 948 |
+
st.markdown("""
|
| 949 |
+
<div style="text-align: center; margin: 20px 0;">
|
| 950 |
+
<p style="color: #00ff41; font-size: 18px; margin-bottom: 15px;"><strong>Supported Languages:</strong></p>
|
| 951 |
+
<div style="display: flex; justify-content: center; flex-wrap: wrap; gap: 10px;">
|
| 952 |
+
<span style="background: linear-gradient(45deg, #00ff41, #00cc33); color: #000; padding: 8px 15px;
|
| 953 |
+
border-radius: 20px; font-weight: bold; font-size: 14px;">Python</span>
|
| 954 |
+
<span style="background: linear-gradient(45deg, #00ff41, #00cc33); color: #000; padding: 8px 15px;
|
| 955 |
+
border-radius: 20px; font-weight: bold; font-size: 14px;">JavaScript</span>
|
| 956 |
+
<span style="background: linear-gradient(45deg, #00ff41, #00cc33); color: #000; padding: 8px 15px;
|
| 957 |
+
border-radius: 20px; font-weight: bold; font-size: 14px;">Java</span>
|
| 958 |
+
<span style="background: linear-gradient(45deg, #00ff41, #00cc33); color: #000; padding: 8px 15px;
|
| 959 |
+
border-radius: 20px; font-weight: bold; font-size: 14px;">C++</span>
|
| 960 |
+
<span style="background: linear-gradient(45deg, #00ff41, #00cc33); color: #000; padding: 8px 15px;
|
| 961 |
+
border-radius: 20px; font-weight: bold; font-size: 14px;">Go</span>
|
| 962 |
+
<span style="background: linear-gradient(45deg, #00ff41, #00cc33); color: #000; padding: 8px 15px;
|
| 963 |
+
border-radius: 20px; font-weight: bold; font-size: 14px;">Rust</span>
|
| 964 |
+
<span style="background: linear-gradient(45deg, #00ff41, #00cc33); color: #000; padding: 8px 15px;
|
| 965 |
+
border-radius: 20px; font-weight: bold; font-size: 14px;">+ More</span>
|
| 966 |
+
</div>
|
| 967 |
+
</div>
|
| 968 |
+
""", unsafe_allow_html=True)
|
| 969 |
+
|
| 970 |
+
# Footer with Matrix signature
|
| 971 |
+
st.markdown("---")
|
| 972 |
+
st.markdown("""
|
| 973 |
+
<div style="text-align: center; color: #00ff41; font-family: 'Share Tech Mono', monospace; padding: 20px;">
|
| 974 |
+
<p>🟢 POWERED_BY_NEURAL_NETWORKS • OPENAI • ANTHROPIC • DEEPSEEK • GOOGLE 🟢</p>
|
| 975 |
+
<p><em>"There is no spoon... only code to analyze."</em></p>
|
| 976 |
+
<p style="font-size: 12px;">MATRIX_ANALYZER_v3.0 • BUILD_2024 • SECURITY_CLEARANCE_OMEGA • FILE_UPLOAD_ENABLED</p>
|
| 977 |
+
</div>
|
| 978 |
+
""", unsafe_allow_html=True)
|
matrix_final_backup.py
ADDED
|
@@ -0,0 +1,978 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import os
|
| 3 |
+
import time
|
| 4 |
+
import random
|
| 5 |
+
import sys
|
| 6 |
+
from dotenv import load_dotenv
|
| 7 |
+
from analyzer import CodeAnalyzer
|
| 8 |
+
|
| 9 |
+
# Load environment variables
|
| 10 |
+
load_dotenv()
|
| 11 |
+
|
| 12 |
+
# Page config
|
| 13 |
+
st.set_page_config(
|
| 14 |
+
page_title="Matrix Code Analyzer - Final",
|
| 15 |
+
page_icon="🟢",
|
| 16 |
+
layout="wide",
|
| 17 |
+
initial_sidebar_state="expanded"
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
# Matrix CSS - Enhanced with file upload styling
|
| 21 |
+
st.markdown("""
|
| 22 |
+
<style>
|
| 23 |
+
@import url('https://fonts.googleapis.com/css2?family=Share+Tech+Mono:wght@400&display=swap');
|
| 24 |
+
@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700;900&display=swap');
|
| 25 |
+
|
| 26 |
+
/* Matrix Background */
|
| 27 |
+
.stApp {
|
| 28 |
+
background: linear-gradient(135deg, #0d1b0d 0%, #000000 50%, #0d1b0d 100%);
|
| 29 |
+
color: #00ff41;
|
| 30 |
+
font-family: 'Share Tech Mono', monospace;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
/* Matrix Code Rain Animation */
|
| 34 |
+
.matrix-bg {
|
| 35 |
+
position: fixed;
|
| 36 |
+
top: 0;
|
| 37 |
+
left: 0;
|
| 38 |
+
width: 100%;
|
| 39 |
+
height: 100%;
|
| 40 |
+
overflow: hidden;
|
| 41 |
+
z-index: -1;
|
| 42 |
+
opacity: 0.1;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
.matrix-char {
|
| 46 |
+
position: absolute;
|
| 47 |
+
color: #00ff41;
|
| 48 |
+
font-family: 'Share Tech Mono', monospace;
|
| 49 |
+
font-size: 14px;
|
| 50 |
+
animation: matrix-fall linear infinite;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
@keyframes matrix-fall {
|
| 54 |
+
0% { transform: translateY(-100vh); opacity: 1; }
|
| 55 |
+
100% { transform: translateY(100vh); opacity: 0; }
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
/* Main Content Styling */
|
| 59 |
+
.main .block-container {
|
| 60 |
+
padding-top: 2rem;
|
| 61 |
+
background: rgba(0, 0, 0, 0.8);
|
| 62 |
+
border: 1px solid #00ff41;
|
| 63 |
+
border-radius: 10px;
|
| 64 |
+
box-shadow: 0 0 20px rgba(0, 255, 65, 0.3);
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
/* Title Styling */
|
| 68 |
+
h1 {
|
| 69 |
+
font-family: 'Orbitron', monospace !important;
|
| 70 |
+
color: #00ff41 !important;
|
| 71 |
+
text-align: center !important;
|
| 72 |
+
text-shadow: 0 0 10px #00ff41, 0 0 20px #00ff41, 0 0 30px #00ff41;
|
| 73 |
+
font-weight: 900 !important;
|
| 74 |
+
margin-bottom: 2rem !important;
|
| 75 |
+
animation: glow 2s ease-in-out infinite alternate;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
@keyframes glow {
|
| 79 |
+
from { text-shadow: 0 0 5px #00ff41, 0 0 10px #00ff41, 0 0 15px #00ff41; }
|
| 80 |
+
to { text-shadow: 0 0 10px #00ff41, 0 0 20px #00ff41, 0 0 30px #00ff41; }
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
/* Sidebar Styling */
|
| 84 |
+
.css-1d391kg {
|
| 85 |
+
background: rgba(0, 0, 0, 0.9) !important;
|
| 86 |
+
border: 1px solid #00ff41 !important;
|
| 87 |
+
border-radius: 10px !important;
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
/* Buttons */
|
| 91 |
+
.stButton > button {
|
| 92 |
+
background: linear-gradient(45deg, #003300, #006600) !important;
|
| 93 |
+
color: #00ff41 !important;
|
| 94 |
+
border: 2px solid #00ff41 !important;
|
| 95 |
+
border-radius: 5px !important;
|
| 96 |
+
font-family: 'Orbitron', monospace !important;
|
| 97 |
+
font-weight: bold !important;
|
| 98 |
+
text-transform: uppercase !important;
|
| 99 |
+
transition: all 0.3s ease !important;
|
| 100 |
+
box-shadow: 0 0 10px rgba(0, 255, 65, 0.3) !important;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
.stButton > button:hover {
|
| 104 |
+
background: linear-gradient(45deg, #006600, #00aa00) !important;
|
| 105 |
+
box-shadow: 0 0 20px rgba(0, 255, 65, 0.6) !important;
|
| 106 |
+
transform: translateY(-2px) !important;
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
/* File uploader styling */
|
| 110 |
+
.stFileUploader > div {
|
| 111 |
+
background: rgba(0, 51, 0, 0.3) !important;
|
| 112 |
+
border: 2px dashed #00ff41 !important;
|
| 113 |
+
border-radius: 10px !important;
|
| 114 |
+
padding: 20px !important;
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
.stFileUploader label {
|
| 118 |
+
color: #00ff41 !important;
|
| 119 |
+
font-family: 'Orbitron', monospace !important;
|
| 120 |
+
font-weight: bold !important;
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
/* Select boxes */
|
| 124 |
+
.stSelectbox > div > div {
|
| 125 |
+
background: rgba(0, 51, 0, 0.8) !important;
|
| 126 |
+
border: 1px solid #00ff41 !important;
|
| 127 |
+
color: #00ff41 !important;
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
/* Text areas */
|
| 131 |
+
.stTextArea > div > div > textarea {
|
| 132 |
+
background: rgba(0, 0, 0, 0.9) !important;
|
| 133 |
+
border: 1px solid #00ff41 !important;
|
| 134 |
+
color: #00ff41 !important;
|
| 135 |
+
font-family: 'Share Tech Mono', monospace !important;
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
/* Metrics */
|
| 139 |
+
.css-1xarl3l {
|
| 140 |
+
background: rgba(0, 51, 0, 0.3) !important;
|
| 141 |
+
border: 1px solid #00ff41 !important;
|
| 142 |
+
border-radius: 5px !important;
|
| 143 |
+
box-shadow: 0 0 10px rgba(0, 255, 65, 0.2) !important;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
/* Success/Info/Warning messages */
|
| 147 |
+
.stSuccess {
|
| 148 |
+
background: rgba(0, 255, 65, 0.1) !important;
|
| 149 |
+
border: 1px solid #00ff41 !important;
|
| 150 |
+
color: #00ff41 !important;
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
.stInfo {
|
| 154 |
+
background: rgba(0, 255, 255, 0.1) !important;
|
| 155 |
+
border: 1px solid #00ffff !important;
|
| 156 |
+
color: #00ffff !important;
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
.stWarning {
|
| 160 |
+
background: rgba(255, 255, 0, 0.1) !important;
|
| 161 |
+
border: 1px solid #ffff00 !important;
|
| 162 |
+
color: #ffff00 !important;
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
.stError {
|
| 166 |
+
background: rgba(255, 0, 0, 0.1) !important;
|
| 167 |
+
border: 1px solid #ff0000 !important;
|
| 168 |
+
color: #ff0000 !important;
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
/* Code blocks */
|
| 172 |
+
.stCode {
|
| 173 |
+
background: rgba(0, 0, 0, 0.9) !important;
|
| 174 |
+
border: 1px solid #00ff41 !important;
|
| 175 |
+
color: #00ff41 !important;
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
/* Tabs */
|
| 179 |
+
.stTabs [data-baseweb="tab-list"] {
|
| 180 |
+
background: rgba(0, 0, 0, 0.8) !important;
|
| 181 |
+
border-bottom: 2px solid #00ff41 !important;
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
.stTabs [data-baseweb="tab"] {
|
| 185 |
+
background: rgba(0, 51, 0, 0.3) !important;
|
| 186 |
+
color: #00ff41 !important;
|
| 187 |
+
border: 1px solid #00ff41 !important;
|
| 188 |
+
font-family: 'Orbitron', monospace !important;
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
.stTabs [aria-selected="true"] {
|
| 192 |
+
background: rgba(0, 255, 65, 0.2) !important;
|
| 193 |
+
box-shadow: 0 0 10px rgba(0, 255, 65, 0.5) !important;
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
/* Matrix Terminal Effect */
|
| 197 |
+
.matrix-terminal {
|
| 198 |
+
background: rgba(0, 0, 0, 0.95) !important;
|
| 199 |
+
border: 2px solid #00ff41 !important;
|
| 200 |
+
border-radius: 10px !important;
|
| 201 |
+
padding: 20px !important;
|
| 202 |
+
font-family: 'Share Tech Mono', monospace !important;
|
| 203 |
+
color: #00ff41 !important;
|
| 204 |
+
box-shadow: 0 0 30px rgba(0, 255, 65, 0.4) !important;
|
| 205 |
+
position: relative !important;
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
.matrix-terminal::before {
|
| 209 |
+
content: "MATRIX_ANALYZER_v3.0 > OPERATIONAL" !important;
|
| 210 |
+
position: absolute !important;
|
| 211 |
+
top: -15px !important;
|
| 212 |
+
left: 20px !important;
|
| 213 |
+
background: #000000 !important;
|
| 214 |
+
padding: 0 10px !important;
|
| 215 |
+
color: #00ff41 !important;
|
| 216 |
+
font-size: 12px !important;
|
| 217 |
+
font-weight: bold !important;
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
/* Checkbox styling */
|
| 221 |
+
.stCheckbox > label {
|
| 222 |
+
color: #00ff41 !important;
|
| 223 |
+
font-family: 'Orbitron', monospace !important;
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
/* Loading spinner */
|
| 227 |
+
.stSpinner > div {
|
| 228 |
+
border-color: #00ff41 transparent #00ff41 transparent !important;
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
/* Expander */
|
| 232 |
+
.streamlit-expanderHeader {
|
| 233 |
+
background: rgba(0, 51, 0, 0.3) !important;
|
| 234 |
+
border: 1px solid #00ff41 !important;
|
| 235 |
+
color: #00ff41 !important;
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
/* File info styling */
|
| 239 |
+
.file-info {
|
| 240 |
+
background: rgba(0, 255, 65, 0.1);
|
| 241 |
+
border: 1px solid #00ff41;
|
| 242 |
+
padding: 10px;
|
| 243 |
+
border-radius: 5px;
|
| 244 |
+
margin: 10px 0;
|
| 245 |
+
font-family: 'Share Tech Mono', monospace;
|
| 246 |
+
}
|
| 247 |
+
</style>
|
| 248 |
+
|
| 249 |
+
<div class="matrix-bg" id="matrix-bg"></div>
|
| 250 |
+
|
| 251 |
+
<script>
|
| 252 |
+
function createMatrixRain() {
|
| 253 |
+
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#$%^&*()_+-=[]{}|;:,.<>?";
|
| 254 |
+
const container = document.getElementById('matrix-bg');
|
| 255 |
+
|
| 256 |
+
for (let i = 0; i < 50; i++) {
|
| 257 |
+
const char = document.createElement('div');
|
| 258 |
+
char.className = 'matrix-char';
|
| 259 |
+
char.textContent = chars[Math.floor(Math.random() * chars.length)];
|
| 260 |
+
char.style.left = Math.random() * 100 + '%';
|
| 261 |
+
char.style.animationDuration = (Math.random() * 3 + 2) + 's';
|
| 262 |
+
char.style.animationDelay = Math.random() * 2 + 's';
|
| 263 |
+
container.appendChild(char);
|
| 264 |
+
}
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
// Create matrix rain effect
|
| 268 |
+
setTimeout(createMatrixRain, 100);
|
| 269 |
+
</script>
|
| 270 |
+
""", unsafe_allow_html=True)
|
| 271 |
+
|
| 272 |
+
# Initialize analyzer
|
| 273 |
+
def get_analyzer():
|
| 274 |
+
# Force reimport to ensure latest code
|
| 275 |
+
import importlib
|
| 276 |
+
import analyzer.code_analyzer
|
| 277 |
+
importlib.reload(analyzer.code_analyzer)
|
| 278 |
+
from analyzer.code_analyzer import CodeAnalyzer
|
| 279 |
+
return CodeAnalyzer()
|
| 280 |
+
|
| 281 |
+
analyzer = get_analyzer()
|
| 282 |
+
|
| 283 |
+
def display_matrix_analysis_result(result: dict, model_name: str):
|
| 284 |
+
"""Display analysis result in clean, readable horizontal blocks."""
|
| 285 |
+
if 'error' in result:
|
| 286 |
+
st.error(f"🚨 SYSTEM ERROR: {result['error']}")
|
| 287 |
+
return
|
| 288 |
+
|
| 289 |
+
# Quality score with modern styling
|
| 290 |
+
score = result['quality_score']
|
| 291 |
+
if score >= 80:
|
| 292 |
+
score_color = "#00ff41"
|
| 293 |
+
status = "EXCELLENT"
|
| 294 |
+
elif score >= 60:
|
| 295 |
+
score_color = "#ffff00"
|
| 296 |
+
status = "ACCEPTABLE"
|
| 297 |
+
else:
|
| 298 |
+
score_color = "#ff0000"
|
| 299 |
+
status = "NEEDS_WORK"
|
| 300 |
+
|
| 301 |
+
# Header with score
|
| 302 |
+
st.markdown(f"""
|
| 303 |
+
<div style="background: linear-gradient(135deg, rgba(0,255,65,0.15), rgba(0,255,65,0.05));
|
| 304 |
+
border: 2px solid #00ff41; border-radius: 15px; padding: 25px; margin: 20px 0;
|
| 305 |
+
text-align: center;">
|
| 306 |
+
<h2 style="color: {score_color}; margin-bottom: 15px; font-size: 1.8rem;">
|
| 307 |
+
{model_name} Analysis
|
| 308 |
+
</h2>
|
| 309 |
+
<div style="display: flex; justify-content: center; gap: 30px; flex-wrap: wrap; color: #ffffff;">
|
| 310 |
+
<div style="text-align: center;">
|
| 311 |
+
<div style="font-size: 2rem; color: {score_color}; font-weight: bold;">{score}/100</div>
|
| 312 |
+
<div style="font-size: 0.9rem; opacity: 0.8;">{status}</div>
|
| 313 |
+
</div>
|
| 314 |
+
<div style="text-align: center;">
|
| 315 |
+
<div style="font-size: 1.2rem; color: #00ff41; font-weight: bold;">{result['language'].upper()}</div>
|
| 316 |
+
<div style="font-size: 0.9rem; opacity: 0.8;">Language</div>
|
| 317 |
+
</div>
|
| 318 |
+
<div style="text-align: center;">
|
| 319 |
+
<div style="font-size: 1.2rem; color: #00ff41; font-weight: bold;">{result['line_count']}</div>
|
| 320 |
+
<div style="font-size: 0.9rem; opacity: 0.8;">Lines</div>
|
| 321 |
+
</div>
|
| 322 |
+
</div>
|
| 323 |
+
</div>
|
| 324 |
+
""", unsafe_allow_html=True)
|
| 325 |
+
|
| 326 |
+
# Summary
|
| 327 |
+
if result.get('summary'):
|
| 328 |
+
st.markdown("### 📋 Code Overview")
|
| 329 |
+
st.markdown(f"""
|
| 330 |
+
<div style="background: rgba(0,0,0,0.6); border: 1px solid #00ff41; border-radius: 10px;
|
| 331 |
+
padding: 20px; margin: 20px 0;">
|
| 332 |
+
<p style="color: #ffffff; font-size: 18px; line-height: 1.6; text-align: center; margin: 0;">
|
| 333 |
+
{result['summary']}
|
| 334 |
+
</p>
|
| 335 |
+
</div>
|
| 336 |
+
""", unsafe_allow_html=True)
|
| 337 |
+
|
| 338 |
+
# Analysis results in horizontal blocks
|
| 339 |
+
st.markdown("### 📊 Analysis Results")
|
| 340 |
+
|
| 341 |
+
# Bug Detection Block (Full width)
|
| 342 |
+
bug_items = result.get('bugs', [])
|
| 343 |
+
if bug_items:
|
| 344 |
+
bug_text = " • ".join(bug_items[:3]) # Join with bullets for horizontal reading
|
| 345 |
+
else:
|
| 346 |
+
bug_text = "No critical bugs detected • Code logic appears sound • Edge cases handled well"
|
| 347 |
+
|
| 348 |
+
st.markdown(f"""
|
| 349 |
+
<div style="background: linear-gradient(135deg, rgba(255,100,100,0.1), rgba(150,0,0,0.1));
|
| 350 |
+
border: 2px solid #ff6b6b; border-radius: 15px; padding: 25px; margin: 15px 0;">
|
| 351 |
+
<h3 style="color: #ff6b6b; margin-bottom: 15px; text-align: center; font-size: 1.4rem;">
|
| 352 |
+
🐛 Bug Detection
|
| 353 |
+
</h3>
|
| 354 |
+
<p style="color: #ffffff; font-size: 16px; line-height: 1.6; text-align: center; margin: 0;">
|
| 355 |
+
{bug_text}
|
| 356 |
+
</p>
|
| 357 |
+
</div>
|
| 358 |
+
""", unsafe_allow_html=True)
|
| 359 |
+
|
| 360 |
+
# Security Vulnerabilities Block (Full width)
|
| 361 |
+
security_items = result.get('security_vulnerabilities', [])
|
| 362 |
+
if security_items:
|
| 363 |
+
security_text = " • ".join(security_items[:3]) # Join with bullets for horizontal reading
|
| 364 |
+
else:
|
| 365 |
+
security_text = "No security vulnerabilities found • Follows security best practices • Input validation looks good"
|
| 366 |
+
|
| 367 |
+
st.markdown(f"""
|
| 368 |
+
<div style="background: linear-gradient(135deg, rgba(200,0,200,0.1), rgba(100,0,100,0.1));
|
| 369 |
+
border: 2px solid #ff00ff; border-radius: 15px; padding: 25px; margin: 15px 0;">
|
| 370 |
+
<h3 style="color: #ff00ff; margin-bottom: 15px; text-align: center; font-size: 1.4rem;">
|
| 371 |
+
🔒 Security Check
|
| 372 |
+
</h3>
|
| 373 |
+
<p style="color: #ffffff; font-size: 16px; line-height: 1.6; text-align: center; margin: 0;">
|
| 374 |
+
{security_text}
|
| 375 |
+
</p>
|
| 376 |
+
</div>
|
| 377 |
+
""", unsafe_allow_html=True)
|
| 378 |
+
|
| 379 |
+
# Code Quality & Quick Fixes Block (Full width)
|
| 380 |
+
quality_items = result.get('quality_issues', []) + result.get('quick_fixes', [])
|
| 381 |
+
if quality_items:
|
| 382 |
+
quality_text = " • ".join(quality_items[:3]) # Join with bullets for horizontal reading
|
| 383 |
+
else:
|
| 384 |
+
quality_text = "Code is well-structured • Good naming conventions • Easy to read and maintain"
|
| 385 |
+
|
| 386 |
+
st.markdown(f"""
|
| 387 |
+
<div style="background: linear-gradient(135deg, rgba(0,200,255,0.1), rgba(0,100,150,0.1));
|
| 388 |
+
border: 2px solid #00ccff; border-radius: 15px; padding: 25px; margin: 15px 0;">
|
| 389 |
+
<h3 style="color: #00ccff; margin-bottom: 15px; text-align: center; font-size: 1.4rem;">
|
| 390 |
+
📝 Code Quality
|
| 391 |
+
</h3>
|
| 392 |
+
<p style="color: #ffffff; font-size: 16px; line-height: 1.6; text-align: center; margin: 0;">
|
| 393 |
+
{quality_text}
|
| 394 |
+
</p>
|
| 395 |
+
</div>
|
| 396 |
+
""", unsafe_allow_html=True)
|
| 397 |
+
|
| 398 |
+
# Legacy sections (only if new sections are empty)
|
| 399 |
+
if not result.get('bugs') and not result.get('security_vulnerabilities') and not result.get('quality_issues'):
|
| 400 |
+
legacy_col1, legacy_col2 = st.columns(2)
|
| 401 |
+
|
| 402 |
+
with legacy_col1:
|
| 403 |
+
# Legacy strengths
|
| 404 |
+
if result.get('strengths'):
|
| 405 |
+
st.markdown("#### ✅ Strengths")
|
| 406 |
+
for strength in result['strengths'][:3]:
|
| 407 |
+
st.success(f"✓ {strength}")
|
| 408 |
+
|
| 409 |
+
# Legacy issues
|
| 410 |
+
if result.get('issues'):
|
| 411 |
+
st.markdown("#### ⚠️ Issues")
|
| 412 |
+
for issue in result['issues'][:3]:
|
| 413 |
+
st.warning(f"! {issue}")
|
| 414 |
+
|
| 415 |
+
with legacy_col2:
|
| 416 |
+
# Legacy suggestions
|
| 417 |
+
if result.get('suggestions'):
|
| 418 |
+
st.markdown("#### 💡 Suggestions")
|
| 419 |
+
for suggestion in result['suggestions'][:3]:
|
| 420 |
+
st.info(f"→ {suggestion}")
|
| 421 |
+
|
| 422 |
+
# Legacy security concerns
|
| 423 |
+
if result.get('security_concerns'):
|
| 424 |
+
st.markdown("#### 🔒 Security Concerns")
|
| 425 |
+
for concern in result['security_concerns'][:3]:
|
| 426 |
+
st.error(f"⚠ {concern}")
|
| 427 |
+
|
| 428 |
+
# Expandable raw response (moved to bottom and less prominent)
|
| 429 |
+
with st.expander("🔍 View Detailed Analysis", expanded=False):
|
| 430 |
+
st.code(result.get('raw_response', 'NO_DATA_AVAILABLE'), language='text')
|
| 431 |
+
|
| 432 |
+
def display_github_analysis_result(result: dict, model_name: str):
|
| 433 |
+
"""Display GitHub repository analysis result in clean, readable horizontal blocks."""
|
| 434 |
+
if 'error' in result:
|
| 435 |
+
st.error(f"🚨 GITHUB ANALYSIS ERROR: {result['error']}")
|
| 436 |
+
return
|
| 437 |
+
|
| 438 |
+
# Repository info in a clean header
|
| 439 |
+
if result.get('repository_info'):
|
| 440 |
+
repo_info = result['repository_info']
|
| 441 |
+
st.markdown(f"""
|
| 442 |
+
<div style="background: linear-gradient(135deg, rgba(0,255,65,0.15), rgba(0,255,65,0.05));
|
| 443 |
+
border: 2px solid #00ff41; border-radius: 15px; padding: 25px; margin: 20px 0;
|
| 444 |
+
text-align: center;">
|
| 445 |
+
<h2 style="color: #00ff41; margin-bottom: 20px; font-size: 1.8rem;">
|
| 446 |
+
📦 {repo_info['name']}
|
| 447 |
+
</h2>
|
| 448 |
+
<div style="display: flex; justify-content: center; gap: 30px; flex-wrap: wrap; color: #ffffff;">
|
| 449 |
+
<div style="text-align: center;">
|
| 450 |
+
<div style="font-size: 1.5rem; color: #00ff41; font-weight: bold;">{repo_info['language']}</div>
|
| 451 |
+
<div style="font-size: 0.9rem; opacity: 0.8;">Language</div>
|
| 452 |
+
</div>
|
| 453 |
+
<div style="text-align: center;">
|
| 454 |
+
<div style="font-size: 1.5rem; color: #00ff41; font-weight: bold;">⭐ {repo_info['stars']}</div>
|
| 455 |
+
<div style="font-size: 0.9rem; opacity: 0.8;">Stars</div>
|
| 456 |
+
</div>
|
| 457 |
+
<div style="text-align: center;">
|
| 458 |
+
<div style="font-size: 1.5rem; color: #00ff41; font-weight: bold;">🔀 {repo_info['forks']}</div>
|
| 459 |
+
<div style="font-size: 0.9rem; opacity: 0.8;">Forks</div>
|
| 460 |
+
</div>
|
| 461 |
+
</div>
|
| 462 |
+
<p style="color: #ffffff; margin-top: 15px; font-style: italic;">
|
| 463 |
+
"{repo_info['description']}"
|
| 464 |
+
</p>
|
| 465 |
+
</div>
|
| 466 |
+
""", unsafe_allow_html=True)
|
| 467 |
+
|
| 468 |
+
# Analysis results in horizontal blocks
|
| 469 |
+
st.markdown("### 📊 Analysis Results")
|
| 470 |
+
|
| 471 |
+
# Architecture Quality Block (Full width)
|
| 472 |
+
arch_items = result.get('architecture_quality', [])
|
| 473 |
+
if arch_items:
|
| 474 |
+
arch_text = " • ".join(arch_items[:3]) # Join with bullets for horizontal reading
|
| 475 |
+
else:
|
| 476 |
+
arch_text = "Well-structured repository • Good organization • Follows best practices"
|
| 477 |
+
|
| 478 |
+
st.markdown(f"""
|
| 479 |
+
<div style="background: linear-gradient(135deg, rgba(0,255,65,0.1), rgba(0,100,30,0.1));
|
| 480 |
+
border: 2px solid #00ff41; border-radius: 15px; padding: 25px; margin: 15px 0;">
|
| 481 |
+
<h3 style="color: #00ff41; margin-bottom: 15px; text-align: center; font-size: 1.4rem;">
|
| 482 |
+
🏗️ Code Architecture
|
| 483 |
+
</h3>
|
| 484 |
+
<p style="color: #ffffff; font-size: 16px; line-height: 1.6; text-align: center; margin: 0;">
|
| 485 |
+
{arch_text}
|
| 486 |
+
</p>
|
| 487 |
+
</div>
|
| 488 |
+
""", unsafe_allow_html=True)
|
| 489 |
+
|
| 490 |
+
# Critical Issues Block (Full width)
|
| 491 |
+
critical_items = result.get('critical_issues', [])
|
| 492 |
+
if critical_items:
|
| 493 |
+
critical_text = " • ".join(critical_items[:3]) # Join with bullets for horizontal reading
|
| 494 |
+
else:
|
| 495 |
+
critical_text = "No major security vulnerabilities found • Code appears well-maintained • No critical bugs detected"
|
| 496 |
+
|
| 497 |
+
st.markdown(f"""
|
| 498 |
+
<div style="background: linear-gradient(135deg, rgba(255,100,100,0.1), rgba(150,0,0,0.1));
|
| 499 |
+
border: 2px solid #ff6b6b; border-radius: 15px; padding: 25px; margin: 15px 0;">
|
| 500 |
+
<h3 style="color: #ff6b6b; margin-bottom: 15px; text-align: center; font-size: 1.4rem;">
|
| 501 |
+
🚨 Critical Issues
|
| 502 |
+
</h3>
|
| 503 |
+
<p style="color: #ffffff; font-size: 16px; line-height: 1.6; text-align: center; margin: 0;">
|
| 504 |
+
{critical_text}
|
| 505 |
+
</p>
|
| 506 |
+
</div>
|
| 507 |
+
""", unsafe_allow_html=True)
|
| 508 |
+
|
| 509 |
+
# Improvement Priorities Block (Full width)
|
| 510 |
+
improvement_items = result.get('improvement_priorities', [])
|
| 511 |
+
if improvement_items:
|
| 512 |
+
improvement_text = " • ".join(improvement_items[:3]) # Join with bullets for horizontal reading
|
| 513 |
+
else:
|
| 514 |
+
improvement_text = "Add more comprehensive documentation • Consider adding automated tests • Enhance error handling"
|
| 515 |
+
|
| 516 |
+
st.markdown(f"""
|
| 517 |
+
<div style="background: linear-gradient(135deg, rgba(255,200,0,0.1), rgba(150,100,0,0.1));
|
| 518 |
+
border: 2px solid #ffd700; border-radius: 15px; padding: 25px; margin: 15px 0;">
|
| 519 |
+
<h3 style="color: #ffd700; margin-bottom: 15px; text-align: center; font-size: 1.4rem;">
|
| 520 |
+
🎯 Priority Improvements
|
| 521 |
+
</h3>
|
| 522 |
+
<p style="color: #ffffff; font-size: 16px; line-height: 1.6; text-align: center; margin: 0;">
|
| 523 |
+
{improvement_text}
|
| 524 |
+
</p>
|
| 525 |
+
</div>
|
| 526 |
+
""", unsafe_allow_html=True)
|
| 527 |
+
|
| 528 |
+
# Summary section at the bottom (if available)
|
| 529 |
+
if result.get('project_overview'):
|
| 530 |
+
st.markdown("### 💡 Key Insights")
|
| 531 |
+
st.markdown(f"""
|
| 532 |
+
<div style="background: rgba(0,0,0,0.6); border: 1px solid #00ff41; border-radius: 10px;
|
| 533 |
+
padding: 20px; margin: 20px 0;">
|
| 534 |
+
<p style="color: #ffffff; font-size: 18px; line-height: 1.6; text-align: center; margin: 0;">
|
| 535 |
+
{result['project_overview']}
|
| 536 |
+
</p>
|
| 537 |
+
</div>
|
| 538 |
+
""", unsafe_allow_html=True)
|
| 539 |
+
|
| 540 |
+
# Expandable raw response (moved to bottom and less prominent)
|
| 541 |
+
with st.expander("🔍 View Detailed Analysis", expanded=False):
|
| 542 |
+
st.code(result.get('raw_response', 'NO_DATA_AVAILABLE'), language='text')
|
| 543 |
+
|
| 544 |
+
# Header with Matrix effect
|
| 545 |
+
st.markdown("""
|
| 546 |
+
<h1 style="text-align: center;">
|
| 547 |
+
🤖 AI Code Analyzer
|
| 548 |
+
</h1>
|
| 549 |
+
<div style="text-align: center; margin-bottom: 30px;">
|
| 550 |
+
<p style="color: #00ff41; font-family: 'Orbitron', monospace; font-size: 20px; margin-bottom: 10px;">
|
| 551 |
+
<strong>Powered by Advanced AI Models</strong>
|
| 552 |
+
</p>
|
| 553 |
+
<div style="display: flex; justify-content: center; gap: 20px; flex-wrap: wrap;">
|
| 554 |
+
<span style="background: rgba(0,255,65,0.2); border: 1px solid #00ff41; padding: 8px 16px;
|
| 555 |
+
border-radius: 25px; font-size: 14px; color: #00ff41;">
|
| 556 |
+
✨ Bug Detection
|
| 557 |
+
</span>
|
| 558 |
+
<span style="background: rgba(0,255,65,0.2); border: 1px solid #00ff41; padding: 8px 16px;
|
| 559 |
+
border-radius: 25px; font-size: 14px; color: #00ff41;">
|
| 560 |
+
🔒 Security Analysis
|
| 561 |
+
</span>
|
| 562 |
+
<span style="background: rgba(0,255,65,0.2); border: 1px solid #00ff41; padding: 8px 16px;
|
| 563 |
+
border-radius: 25px; font-size: 14px; color: #00ff41;">
|
| 564 |
+
📦 GitHub Integration
|
| 565 |
+
</span>
|
| 566 |
+
<span style="background: rgba(0,255,65,0.2); border: 1px solid #00ff41; padding: 8px 16px;
|
| 567 |
+
border-radius: 25px; font-size: 14px; color: #00ff41;">
|
| 568 |
+
⚡ Instant Results
|
| 569 |
+
</span>
|
| 570 |
+
</div>
|
| 571 |
+
</div>
|
| 572 |
+
""", unsafe_allow_html=True)
|
| 573 |
+
|
| 574 |
+
# Sidebar - The Matrix Control Panel
|
| 575 |
+
with st.sidebar:
|
| 576 |
+
st.markdown("### 🎛️ Control Panel")
|
| 577 |
+
|
| 578 |
+
# Model status
|
| 579 |
+
st.markdown("#### Available AI Models")
|
| 580 |
+
available_models = analyzer.available_models
|
| 581 |
+
|
| 582 |
+
if not available_models:
|
| 583 |
+
st.error("❌ No AI models detected")
|
| 584 |
+
st.info("Please configure API keys in .env file")
|
| 585 |
+
st.stop()
|
| 586 |
+
|
| 587 |
+
# Display available models with modern styling
|
| 588 |
+
for model, display_name in available_models.items():
|
| 589 |
+
st.markdown(f"""
|
| 590 |
+
<div style="background: rgba(0, 255, 65, 0.1); border: 1px solid #00ff41; padding: 10px; margin: 8px 0; border-radius: 8px;">
|
| 591 |
+
✅ <strong>{display_name}</strong> <span style="color: #00ff41; font-size: 12px;">[Ready]</span>
|
| 592 |
+
</div>
|
| 593 |
+
""", unsafe_allow_html=True)
|
| 594 |
+
|
| 595 |
+
st.markdown("---")
|
| 596 |
+
|
| 597 |
+
# Analysis Mode Selection
|
| 598 |
+
st.markdown("#### Analysis Mode")
|
| 599 |
+
analysis_mode = st.radio(
|
| 600 |
+
"Choose what to analyze",
|
| 601 |
+
["Code Analysis", "GitHub Repository"],
|
| 602 |
+
format_func=lambda x: f"📝 {x}" if x == "Code Analysis" else f"📦 {x}"
|
| 603 |
+
)
|
| 604 |
+
|
| 605 |
+
if analysis_mode == "GitHub Repository":
|
| 606 |
+
st.markdown("#### Repository Analysis")
|
| 607 |
+
github_url = st.text_input(
|
| 608 |
+
"GitHub URL",
|
| 609 |
+
placeholder="https://github.com/owner/repo",
|
| 610 |
+
help="Enter a GitHub repository URL for analysis"
|
| 611 |
+
)
|
| 612 |
+
|
| 613 |
+
analyze_github_button = st.button(
|
| 614 |
+
"🔍 Analyze Repository",
|
| 615 |
+
type="primary",
|
| 616 |
+
help="Analyze GitHub repository structure and code"
|
| 617 |
+
)
|
| 618 |
+
|
| 619 |
+
st.markdown("---")
|
| 620 |
+
|
| 621 |
+
# Analysis options
|
| 622 |
+
st.markdown("#### Analysis Settings")
|
| 623 |
+
|
| 624 |
+
# Model selector with modern styling
|
| 625 |
+
selected_model = st.selectbox(
|
| 626 |
+
"Choose AI Model",
|
| 627 |
+
options=list(available_models.keys()),
|
| 628 |
+
format_func=lambda x: f"🤖 {available_models[x]}"
|
| 629 |
+
)
|
| 630 |
+
|
| 631 |
+
# Multi-model analysis toggle
|
| 632 |
+
analyze_all = st.checkbox("🔄 Compare Multiple Models", value=False)
|
| 633 |
+
|
| 634 |
+
# Language selection
|
| 635 |
+
languages = ["auto-detect", "python", "javascript", "java", "cpp", "csharp", "go", "rust", "php", "ruby", "swift", "kotlin"]
|
| 636 |
+
selected_language = st.selectbox(
|
| 637 |
+
"Programming Language",
|
| 638 |
+
languages,
|
| 639 |
+
format_func=lambda x: "🔍 Auto-Detect" if x == "auto-detect" else f"💻 {x.upper()}"
|
| 640 |
+
)
|
| 641 |
+
|
| 642 |
+
st.markdown("---")
|
| 643 |
+
|
| 644 |
+
# Sample code injection
|
| 645 |
+
st.markdown("#### Quick Start Examples")
|
| 646 |
+
|
| 647 |
+
if st.button("🐍 Try Python Example"):
|
| 648 |
+
st.session_state.code_input = """def calculate_total(items):
|
| 649 |
+
total = 0
|
| 650 |
+
for item in items:
|
| 651 |
+
total += item.price # Potential AttributeError
|
| 652 |
+
return total
|
| 653 |
+
|
| 654 |
+
# Missing validation
|
| 655 |
+
items = None
|
| 656 |
+
result = calculate_total(items) # This will crash
|
| 657 |
+
print(f"Total: {result}")
|
| 658 |
+
"""
|
| 659 |
+
|
| 660 |
+
if st.button("🌐 Try JavaScript Example"):
|
| 661 |
+
st.session_state.code_input = """function processUser(user) {
|
| 662 |
+
// Security issue: no input validation
|
| 663 |
+
document.innerHTML = user.name; // XSS vulnerability
|
| 664 |
+
|
| 665 |
+
// Logic error: undefined check
|
| 666 |
+
if (user.age > 18) {
|
| 667 |
+
return user.permissions.admin; // Potential TypeError
|
| 668 |
+
}
|
| 669 |
+
|
| 670 |
+
return false;
|
| 671 |
+
}
|
| 672 |
+
|
| 673 |
+
// Missing error handling
|
| 674 |
+
const userData = getUser(); // Could be undefined
|
| 675 |
+
processUser(userData);
|
| 676 |
+
"""
|
| 677 |
+
|
| 678 |
+
# Main Terminal Interface
|
| 679 |
+
col1, col2 = st.columns([1, 1])
|
| 680 |
+
|
| 681 |
+
with col1:
|
| 682 |
+
if analysis_mode == "Code Analysis":
|
| 683 |
+
st.markdown("### 📝 Code Input")
|
| 684 |
+
|
| 685 |
+
# File upload section
|
| 686 |
+
st.markdown("#### 📁 Upload File")
|
| 687 |
+
uploaded_file = st.file_uploader(
|
| 688 |
+
"Choose a code file",
|
| 689 |
+
type=['py', 'js', 'java', 'cpp', 'c', 'cs', 'go', 'rs', 'php', 'rb', 'swift', 'kt', 'txt'],
|
| 690 |
+
help="Upload code files for AI analysis"
|
| 691 |
+
)
|
| 692 |
+
|
| 693 |
+
code_from_file = ""
|
| 694 |
+
if uploaded_file is not None:
|
| 695 |
+
# Read file content
|
| 696 |
+
try:
|
| 697 |
+
code_from_file = str(uploaded_file.read(), "utf-8")
|
| 698 |
+
file_size = len(code_from_file)
|
| 699 |
+
file_lines = len(code_from_file.splitlines())
|
| 700 |
+
|
| 701 |
+
st.markdown(f"""
|
| 702 |
+
<div class="file-info">
|
| 703 |
+
✅ <strong>File Uploaded Successfully</strong><br>
|
| 704 |
+
📄 <strong>Name:</strong> {uploaded_file.name}<br>
|
| 705 |
+
📏 <strong>Size:</strong> {file_size} bytes<br>
|
| 706 |
+
📊 <strong>Lines:</strong> {file_lines}<br>
|
| 707 |
+
🔍 <strong>Status:</strong> Ready for analysis
|
| 708 |
+
</div>
|
| 709 |
+
""", unsafe_allow_html=True)
|
| 710 |
+
|
| 711 |
+
# Auto-populate the text area
|
| 712 |
+
st.session_state.code_input = code_from_file
|
| 713 |
+
|
| 714 |
+
except UnicodeDecodeError:
|
| 715 |
+
st.error("🚨 File encoding error: Please use UTF-8 encoded files")
|
| 716 |
+
except Exception as e:
|
| 717 |
+
st.error(f"🚨 File read error: {str(e)}")
|
| 718 |
+
|
| 719 |
+
# Code input with modern styling
|
| 720 |
+
code_input = st.text_area(
|
| 721 |
+
"Or paste your code here",
|
| 722 |
+
value=st.session_state.get('code_input', ''),
|
| 723 |
+
height=350,
|
| 724 |
+
key="code_input",
|
| 725 |
+
help="Paste code directly or upload file above"
|
| 726 |
+
)
|
| 727 |
+
|
| 728 |
+
# Modern analyze button
|
| 729 |
+
analyze_button = st.button(
|
| 730 |
+
"🚀 Analyze Code",
|
| 731 |
+
type="primary",
|
| 732 |
+
help="Analyze your code with AI"
|
| 733 |
+
)
|
| 734 |
+
|
| 735 |
+
else: # GitHub Repository mode
|
| 736 |
+
st.markdown("### 📦 GitHub Analysis")
|
| 737 |
+
|
| 738 |
+
if 'github_url' in locals():
|
| 739 |
+
if github_url:
|
| 740 |
+
st.markdown(f"""
|
| 741 |
+
<div class="file-info">
|
| 742 |
+
✅ <strong>Repository Detected</strong><br>
|
| 743 |
+
📦 <strong>URL:</strong> {github_url}<br>
|
| 744 |
+
🔍 <strong>Status:</strong> Ready for analysis
|
| 745 |
+
</div>
|
| 746 |
+
""", unsafe_allow_html=True)
|
| 747 |
+
|
| 748 |
+
st.markdown("""
|
| 749 |
+
#### 📋 What We'll Analyze
|
| 750 |
+
|
| 751 |
+
**Repository Analysis includes:**
|
| 752 |
+
- 🏗️ Project structure and organization
|
| 753 |
+
- 📄 Key files (README, package.json, main source files)
|
| 754 |
+
- 🎯 Code quality and architecture assessment
|
| 755 |
+
- 🔒 Security vulnerabilities across the codebase
|
| 756 |
+
- 💡 Best practices and improvement suggestions
|
| 757 |
+
|
| 758 |
+
**Note:** Only public repositories can be analyzed.
|
| 759 |
+
""")
|
| 760 |
+
|
| 761 |
+
# Show sample repos
|
| 762 |
+
st.markdown("#### 📚 Try These Sample Repositories")
|
| 763 |
+
sample_repos = [
|
| 764 |
+
"https://github.com/microsoft/vscode",
|
| 765 |
+
"https://github.com/facebook/react",
|
| 766 |
+
"https://github.com/python/cpython"
|
| 767 |
+
]
|
| 768 |
+
|
| 769 |
+
for repo in sample_repos:
|
| 770 |
+
if st.button(f"📦 {repo.split('/')[-1]}", key=repo):
|
| 771 |
+
st.session_state.github_url_input = repo
|
| 772 |
+
|
| 773 |
+
# Results Terminal
|
| 774 |
+
with col2:
|
| 775 |
+
st.markdown("### 📊 Analysis Results")
|
| 776 |
+
|
| 777 |
+
# Code Analysis Results
|
| 778 |
+
if analysis_mode == "Code Analysis":
|
| 779 |
+
if analyze_button:
|
| 780 |
+
if not code_input.strip():
|
| 781 |
+
st.error("🚨 Please enter some code to analyze or upload a file!")
|
| 782 |
+
else:
|
| 783 |
+
with st.spinner("🟢 Analyzing your code... Please wait..."):
|
| 784 |
+
if analyze_all:
|
| 785 |
+
# Multi-model analysis
|
| 786 |
+
st.markdown("#### 🔄 MULTI_NETWORK_ANALYSIS_INITIATED")
|
| 787 |
+
|
| 788 |
+
results = analyzer.analyze_with_all_models(
|
| 789 |
+
code_input,
|
| 790 |
+
selected_language if selected_language != "auto-detect" else None
|
| 791 |
+
)
|
| 792 |
+
|
| 793 |
+
# Display comparison metrics
|
| 794 |
+
comparison = analyzer.compare_analyses(results)
|
| 795 |
+
|
| 796 |
+
# Matrix-styled metrics
|
| 797 |
+
metrics_cols = st.columns(4)
|
| 798 |
+
with metrics_cols[0]:
|
| 799 |
+
st.metric("AVG_SCORE", f"{comparison['average_score']}/100")
|
| 800 |
+
with metrics_cols[1]:
|
| 801 |
+
st.metric("NETWORKS", len(results))
|
| 802 |
+
with metrics_cols[2]:
|
| 803 |
+
st.metric("PEAK_SCORE", f"{max(comparison['model_scores'].values())}/100")
|
| 804 |
+
with metrics_cols[3]:
|
| 805 |
+
st.metric("SCAN_TIME", f"{comparison['analysis_time']:.1f}s")
|
| 806 |
+
|
| 807 |
+
# Create tabs for each neural network
|
| 808 |
+
tab_names = [f"🤖 {available_models[key]}" for key in results.keys()]
|
| 809 |
+
tabs = st.tabs(tab_names)
|
| 810 |
+
|
| 811 |
+
for idx, (model_key, result) in enumerate(results.items()):
|
| 812 |
+
with tabs[idx]:
|
| 813 |
+
display_matrix_analysis_result(result, available_models[model_key])
|
| 814 |
+
|
| 815 |
+
# Consensus findings with Matrix styling
|
| 816 |
+
if comparison.get('consensus_bugs') or comparison.get('consensus_security'):
|
| 817 |
+
st.markdown("### 🤝 NEURAL_CONSENSUS_DETECTED")
|
| 818 |
+
st.markdown("""
|
| 819 |
+
<div style="background: rgba(255, 0, 0, 0.1); border: 2px solid #ff0000; padding: 15px; border-radius: 10px;">
|
| 820 |
+
<strong>CRITICAL_PATTERNS_IDENTIFIED_BY_MULTIPLE_NETWORKS:</strong>
|
| 821 |
+
</div>
|
| 822 |
+
""", unsafe_allow_html=True)
|
| 823 |
+
|
| 824 |
+
if comparison.get('consensus_bugs'):
|
| 825 |
+
st.markdown("#### 🐛 CONSENSUS_BUGS")
|
| 826 |
+
for bug in comparison['consensus_bugs']:
|
| 827 |
+
st.error(f"🚨 MULTIPLE_MODELS: {bug}")
|
| 828 |
+
|
| 829 |
+
if comparison.get('consensus_security'):
|
| 830 |
+
st.markdown("#### 🔒 CONSENSUS_SECURITY")
|
| 831 |
+
for vuln in comparison['consensus_security']:
|
| 832 |
+
st.error(f"🚨 SECURITY_ALERT: {vuln}")
|
| 833 |
+
|
| 834 |
+
else:
|
| 835 |
+
# Single model analysis
|
| 836 |
+
st.markdown(f"#### 🤖 {available_models[selected_model].upper()}_ANALYSIS")
|
| 837 |
+
|
| 838 |
+
result = analyzer.analyze_code(
|
| 839 |
+
code_input,
|
| 840 |
+
selected_model,
|
| 841 |
+
selected_language if selected_language != "auto-detect" else None
|
| 842 |
+
)
|
| 843 |
+
display_matrix_analysis_result(result, available_models[selected_model])
|
| 844 |
+
|
| 845 |
+
# GitHub Analysis Results
|
| 846 |
+
else: # GitHub Repository mode
|
| 847 |
+
if 'analyze_github_button' in locals() and analyze_github_button:
|
| 848 |
+
if not github_url.strip():
|
| 849 |
+
st.error("🚨 Please enter a GitHub repository URL!")
|
| 850 |
+
else:
|
| 851 |
+
with st.spinner("🟢 Analyzing GitHub repository... Please wait..."):
|
| 852 |
+
result = analyzer.analyze_github_repo(github_url, selected_model)
|
| 853 |
+
display_github_analysis_result(result, available_models[selected_model])
|
| 854 |
+
|
| 855 |
+
# Instructions for new users
|
| 856 |
+
if (analysis_mode == "Code Analysis" and not code_input.strip() and not analyze_button) or \
|
| 857 |
+
(analysis_mode == "GitHub Repository" and ('github_url' not in locals() or not github_url.strip()) and ('analyze_github_button' not in locals() or not analyze_github_button)):
|
| 858 |
+
|
| 859 |
+
st.markdown("""
|
| 860 |
+
<div class="matrix-terminal" style="margin: 20px 0; text-align: center;">
|
| 861 |
+
<h2 style="color: #00ff41; margin-bottom: 30px; font-size: 2.5rem;">
|
| 862 |
+
🤖 AI Code Analyzer
|
| 863 |
+
</h2>
|
| 864 |
+
<p style="color: #00ff41; font-size: 1.3rem; margin-bottom: 30px;">
|
| 865 |
+
<strong>What can I do for you?</strong>
|
| 866 |
+
</p>
|
| 867 |
+
</div>
|
| 868 |
+
""", unsafe_allow_html=True)
|
| 869 |
+
|
| 870 |
+
# Feature cards in columns
|
| 871 |
+
feature_col1, feature_col2 = st.columns(2)
|
| 872 |
+
|
| 873 |
+
with feature_col1:
|
| 874 |
+
st.markdown("""
|
| 875 |
+
<div style="background: linear-gradient(135deg, rgba(0,255,65,0.1), rgba(0,255,65,0.05));
|
| 876 |
+
border: 2px solid #00ff41; border-radius: 15px; padding: 25px; margin: 10px 0;
|
| 877 |
+
box-shadow: 0 0 20px rgba(0,255,65,0.3);">
|
| 878 |
+
<h3 style="color: #00ff41; margin-bottom: 15px;">🐛 Find Bugs Instantly</h3>
|
| 879 |
+
<p style="color: #ffffff; font-size: 16px; line-height: 1.6;">
|
| 880 |
+
Spot crashes, logical errors, and edge cases before they hit production.
|
| 881 |
+
</p>
|
| 882 |
+
</div>
|
| 883 |
+
""", unsafe_allow_html=True)
|
| 884 |
+
|
| 885 |
+
st.markdown("""
|
| 886 |
+
<div style="background: linear-gradient(135deg, rgba(0,255,65,0.1), rgba(0,255,65,0.05));
|
| 887 |
+
border: 2px solid #00ff41; border-radius: 15px; padding: 25px; margin: 10px 0;
|
| 888 |
+
box-shadow: 0 0 20px rgba(0,255,65,0.3);">
|
| 889 |
+
<h3 style="color: #00ff41; margin-bottom: 15px;">🔒 Security Scanner</h3>
|
| 890 |
+
<p style="color: #ffffff; font-size: 16px; line-height: 1.6;">
|
| 891 |
+
Detect vulnerabilities like SQL injection, XSS, and insecure data handling.
|
| 892 |
+
</p>
|
| 893 |
+
</div>
|
| 894 |
+
""", unsafe_allow_html=True)
|
| 895 |
+
|
| 896 |
+
with feature_col2:
|
| 897 |
+
st.markdown("""
|
| 898 |
+
<div style="background: linear-gradient(135deg, rgba(0,255,65,0.1), rgba(0,255,65,0.05));
|
| 899 |
+
border: 2px solid #00ff41; border-radius: 15px; padding: 25px; margin: 10px 0;
|
| 900 |
+
box-shadow: 0 0 20px rgba(0,255,65,0.3);">
|
| 901 |
+
<h3 style="color: #00ff41; margin-bottom: 15px;">📝 Code Quality Check</h3>
|
| 902 |
+
<p style="color: #ffffff; font-size: 16px; line-height: 1.6;">
|
| 903 |
+
Improve readability, maintainability, and follow best practices.
|
| 904 |
+
</p>
|
| 905 |
+
</div>
|
| 906 |
+
""", unsafe_allow_html=True)
|
| 907 |
+
|
| 908 |
+
st.markdown("""
|
| 909 |
+
<div style="background: linear-gradient(135deg, rgba(0,255,65,0.1), rgba(0,255,65,0.05));
|
| 910 |
+
border: 2px solid #00ff41; border-radius: 15px; padding: 25px; margin: 10px 0;
|
| 911 |
+
box-shadow: 0 0 20px rgba(0,255,65,0.3);">
|
| 912 |
+
<h3 style="color: #00ff41; margin-bottom: 15px;">📦 Repository Analysis</h3>
|
| 913 |
+
<p style="color: #ffffff; font-size: 16px; line-height: 1.6;">
|
| 914 |
+
Analyze entire GitHub repos for structure, issues, and improvements.
|
| 915 |
+
</p>
|
| 916 |
+
</div>
|
| 917 |
+
""", unsafe_allow_html=True)
|
| 918 |
+
|
| 919 |
+
# How to get started section
|
| 920 |
+
st.markdown("""
|
| 921 |
+
<div style="background: rgba(0,0,0,0.7); border: 1px solid #00ff41; border-radius: 10px;
|
| 922 |
+
padding: 20px; margin: 30px 0; text-align: center;">
|
| 923 |
+
<h3 style="color: #00ff41; margin-bottom: 20px;">🚀 Get Started in 3 Steps</h3>
|
| 924 |
+
<div style="display: flex; justify-content: space-around; flex-wrap: wrap;">
|
| 925 |
+
<div style="margin: 10px; color: #ffffff;">
|
| 926 |
+
<div style="background: #00ff41; color: #000; border-radius: 50%; width: 40px; height: 40px;
|
| 927 |
+
display: flex; align-items: center; justify-content: center; margin: 0 auto 10px;
|
| 928 |
+
font-weight: bold; font-size: 20px;">1</div>
|
| 929 |
+
<p><strong>Upload</strong><br>Paste code or GitHub URL</p>
|
| 930 |
+
</div>
|
| 931 |
+
<div style="margin: 10px; color: #ffffff;">
|
| 932 |
+
<div style="background: #00ff41; color: #000; border-radius: 50%; width: 40px; height: 40px;
|
| 933 |
+
display: flex; align-items: center; justify-content: center; margin: 0 auto 10px;
|
| 934 |
+
font-weight: bold; font-size: 20px;">2</div>
|
| 935 |
+
<p><strong>Choose AI</strong><br>Pick your preferred model</p>
|
| 936 |
+
</div>
|
| 937 |
+
<div style="margin: 10px; color: #ffffff;">
|
| 938 |
+
<div style="background: #00ff41; color: #000; border-radius: 50%; width: 40px; height: 40px;
|
| 939 |
+
display: flex; align-items: center; justify-content: center; margin: 0 auto 10px;
|
| 940 |
+
font-weight: bold; font-size: 20px;">3</div>
|
| 941 |
+
<p><strong>Analyze</strong><br>Get instant results</p>
|
| 942 |
+
</div>
|
| 943 |
+
</div>
|
| 944 |
+
</div>
|
| 945 |
+
""", unsafe_allow_html=True)
|
| 946 |
+
|
| 947 |
+
# Supported languages as badges
|
| 948 |
+
st.markdown("""
|
| 949 |
+
<div style="text-align: center; margin: 20px 0;">
|
| 950 |
+
<p style="color: #00ff41; font-size: 18px; margin-bottom: 15px;"><strong>Supported Languages:</strong></p>
|
| 951 |
+
<div style="display: flex; justify-content: center; flex-wrap: wrap; gap: 10px;">
|
| 952 |
+
<span style="background: linear-gradient(45deg, #00ff41, #00cc33); color: #000; padding: 8px 15px;
|
| 953 |
+
border-radius: 20px; font-weight: bold; font-size: 14px;">Python</span>
|
| 954 |
+
<span style="background: linear-gradient(45deg, #00ff41, #00cc33); color: #000; padding: 8px 15px;
|
| 955 |
+
border-radius: 20px; font-weight: bold; font-size: 14px;">JavaScript</span>
|
| 956 |
+
<span style="background: linear-gradient(45deg, #00ff41, #00cc33); color: #000; padding: 8px 15px;
|
| 957 |
+
border-radius: 20px; font-weight: bold; font-size: 14px;">Java</span>
|
| 958 |
+
<span style="background: linear-gradient(45deg, #00ff41, #00cc33); color: #000; padding: 8px 15px;
|
| 959 |
+
border-radius: 20px; font-weight: bold; font-size: 14px;">C++</span>
|
| 960 |
+
<span style="background: linear-gradient(45deg, #00ff41, #00cc33); color: #000; padding: 8px 15px;
|
| 961 |
+
border-radius: 20px; font-weight: bold; font-size: 14px;">Go</span>
|
| 962 |
+
<span style="background: linear-gradient(45deg, #00ff41, #00cc33); color: #000; padding: 8px 15px;
|
| 963 |
+
border-radius: 20px; font-weight: bold; font-size: 14px;">Rust</span>
|
| 964 |
+
<span style="background: linear-gradient(45deg, #00ff41, #00cc33); color: #000; padding: 8px 15px;
|
| 965 |
+
border-radius: 20px; font-weight: bold; font-size: 14px;">+ More</span>
|
| 966 |
+
</div>
|
| 967 |
+
</div>
|
| 968 |
+
""", unsafe_allow_html=True)
|
| 969 |
+
|
| 970 |
+
# Footer with Matrix signature
|
| 971 |
+
st.markdown("---")
|
| 972 |
+
st.markdown("""
|
| 973 |
+
<div style="text-align: center; color: #00ff41; font-family: 'Share Tech Mono', monospace; padding: 20px;">
|
| 974 |
+
<p>🟢 POWERED_BY_NEURAL_NETWORKS • OPENAI • ANTHROPIC • DEEPSEEK • GOOGLE 🟢</p>
|
| 975 |
+
<p><em>"There is no spoon... only code to analyze."</em></p>
|
| 976 |
+
<p style="font-size: 12px;">MATRIX_ANALYZER_v3.0 • BUILD_2024 • SECURITY_CLEARANCE_OMEGA • FILE_UPLOAD_ENABLED</p>
|
| 977 |
+
</div>
|
| 978 |
+
""", unsafe_allow_html=True)
|
netlify.toml
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[build]
|
| 2 |
+
command = "echo 'This is a Python Streamlit app - deploy to Render, Railway, or Heroku instead'"
|
| 3 |
+
publish = "."
|
| 4 |
+
|
| 5 |
+
[[redirects]]
|
| 6 |
+
from = "/*"
|
| 7 |
+
to = "https://your-app-name.onrender.com/:splat"
|
| 8 |
+
status = 301
|
| 9 |
+
force = true
|
render.yaml
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
services:
|
| 2 |
+
- type: web
|
| 3 |
+
name: llm-code-analyzer
|
| 4 |
+
env: python
|
| 5 |
+
repo: https://github.com/arun3676/ai-code-analyzer.git
|
| 6 |
+
branch: main
|
| 7 |
+
buildCommand: pip install -r requirements.txt
|
| 8 |
+
startCommand: streamlit run app.py --server.port=$PORT --server.address=0.0.0.0
|
| 9 |
+
plan: free
|
| 10 |
+
envVars:
|
| 11 |
+
- key: OPENAI_API_KEY
|
| 12 |
+
sync: false
|
| 13 |
+
- key: ANTHROPIC_API_KEY
|
| 14 |
+
sync: false
|
| 15 |
+
- key: GEMINI_API_KEY
|
| 16 |
+
sync: false
|
| 17 |
+
- key: DEEPSEEK_API_KEY
|
| 18 |
+
sync: false
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit==1.36.0
|
| 2 |
+
openai>=1.0.0
|
| 3 |
+
anthropic>=0.25.0
|
| 4 |
+
google-generativeai>=0.6.0
|
| 5 |
+
python-dotenv>=1.0.0
|
| 6 |
+
requests>=2.32.0
|
runtime.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
python-3.11.9
|
streamlit.bat
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@echo off
|
| 2 |
+
python -m streamlit %*
|
test_app.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from analyzer import CodeAnalyzer
|
| 3 |
+
|
| 4 |
+
# Simple test app
|
| 5 |
+
st.title("🔍 LLM Code Analyzer - Test")
|
| 6 |
+
|
| 7 |
+
try:
|
| 8 |
+
analyzer = CodeAnalyzer()
|
| 9 |
+
available_models = analyzer.available_models
|
| 10 |
+
|
| 11 |
+
st.success(f"✅ Analyzer loaded successfully!")
|
| 12 |
+
st.info(f"📊 Available models: {len(available_models)}")
|
| 13 |
+
|
| 14 |
+
for model_key, model_name in available_models.items():
|
| 15 |
+
st.write(f"• {model_name}")
|
| 16 |
+
|
| 17 |
+
# Simple code input
|
| 18 |
+
code_input = st.text_area("Enter code to analyze:",
|
| 19 |
+
value="def hello():\n print('Hello, World!')",
|
| 20 |
+
height=150)
|
| 21 |
+
|
| 22 |
+
if st.button("Analyze"):
|
| 23 |
+
if code_input.strip():
|
| 24 |
+
with st.spinner("Analyzing..."):
|
| 25 |
+
result = analyzer.analyze_code(code_input, list(available_models.keys())[0])
|
| 26 |
+
st.json(result)
|
| 27 |
+
else:
|
| 28 |
+
st.warning("Please enter some code")
|
| 29 |
+
|
| 30 |
+
except Exception as e:
|
| 31 |
+
st.error(f"Error: {str(e)}")
|
| 32 |
+
st.write("Debug info:")
|
| 33 |
+
st.write(f"Python version: {sys.version}")
|
| 34 |
+
st.write(f"Working directory: {os.getcwd()}")
|