--- title: AI Code Security Scanner emoji: 🛡️ colorFrom: blue colorTo: indigo sdk: streamlit sdk_version: 1.52.2 app_file: app.py pinned: false app_port: 8501 short_description: AI Python security scanner using CodeBERT and rules. --- # AI Code Security Scanner: Real-time Vulnerability Detection An advanced security orchestration tool that detects critical vulnerabilities (SQLi, XSS, Command Injection) using a **Hybrid Analysis Engine**: combining static rule-based heuristics with deep learning **CodeBERT** models. [![Hugging Face Space](https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Space-yellow)](https://huggingface.co/spaces/mubi-613/ai-code-scanner-ui) > **Live Demo:** [AI Security Scanner on Hugging Face](https://huggingface.co/spaces/mubi-613/ai-code-scanner-ui) --- ## Core Engineering Features * **Hybrid Detection Engine:** Utilizes **AST (Abstract Syntax Tree)** parsing for rule-based detection and fine-tuned **CodeBERT** (Deep Learning) for semantic vulnerability pattern matching. * **Automated Remediation:** Generates context-aware "Fix Suggestions" using AI to provide secure code alternatives for identified risks. * **Security Dashboard:** Real-time visualization of security scores and vulnerability distribution across large codebases. * **Batch Processing:** Optimized for high-throughput scanning of multiple Python files simultaneously using Python's `multiprocessing` capabilities. * **REST API Architecture:** Built with a **FastAPI** backend, allowing for easy integration into existing CI/CD pipelines as a security gate. ## Technical Stack * **Deep Learning:** CodeBERT (Transformers), PyTorch * **Analysis Engine:** Python AST, Custom Rule-based Heuristics * **Backend/Frontend:** FastAPI, Streamlit * **Deployment:** Docker, Hugging Face Spaces (Debian Linux) ## Installation 1. **Clone the repository:** ```bash git clone [https://github.com/mubi0613/AI-Code-Security-Scanner.git](https://github.com/mubi0613/AI-Code-Security-Scanner.git) cd AI-Code-Security-Scanner 2. **Setup environment:** ```bash python -m venv venv # On Windows: .\venv\Scripts\activate # On Mac/Linux: source venv/bin/activate 3. **Install dependencies:** ```bash pip install -r requirements.txt 4. **Run the application:** ```bash streamlit run app.py` ## Docker Deployment * Build and run with Docker Compose * docker-compose up --build ## Access at: * Web UI: http://localhost:8501 * API Docs: http://localhost:8000/docs ## Project Structure AI-Code-Security-Scanner/ * ├── app.py # Main Streamlit Dashboard & UI Logic * ├── api_backend.py # FastAPI Server for REST API Access * ├── combined_detector.py # Hybrid Logic (Rules + CodeBERT Model) * ├── rule_detector.py # Static Analysis & AST-based Heuristics * ├── fix_generator.py # AI-powered Remediation Engine * ├── saved_model/ # Fine-tuned CodeBERT Weights & Config * ├── docker-compose.yml # Container Orchestration for UI & API * ├── requirements.txt # Project Dependencies * └── README.md # Technical Documentation ## Architecture Diagram ```mermaid graph LR subgraph "Frontend Layer" A[Streamlit UI] --> B[User Code Input] end subgraph "Analysis Engine" B --> C{Hybrid Scanner} C --> D[Static Rule Engine] C --> E[CodeBERT DL Model] end subgraph "Remediation & Reporting" D & E --> F[Vulnerability Report] F --> G[AI Fix Generator] G --> H[Final Security Report] end ```