Spaces:
Running
Running
File size: 3,634 Bytes
41dde94 747f016 63703ca 41dde94 98b502b 168ae1c 98b502b 168ae1c 7646eac 168ae1c 7646eac 168ae1c 98b502b 168ae1c 98b502b 2b18317 98b502b 2b18317 98b502b 2b18317 98b502b 7877b4e 98b502b 7877b4e 98b502b 168ae1c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | ---
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.
[](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
```
|