🔒 AI Code Security Scanner
Real-time vulnerability detection and AI-powered fixes
import streamlit as st import plotly.graph_objects as go from combined_detector import CombinedCodeDetector from rule_detector import RuleBasedCodeDetector from fix_generator import FixSuggestionGenerator import pandas as pd import time import requests import json import torch from transformers import AutoModelForSequenceClassification, AutoTokenizer # 1. Page Config st.set_page_config( page_title="AI Code Security Scanner", page_icon="🔒", layout="wide" ) # 2. Optimized Component Loading for Deployment @st.cache_resource def load_tools(): # Hugging Face Model ID model_path = "mubi-613/ai-code-security-scanner" with st.spinner("🚀 Loading AI Models from Hugging Face... Please wait."): with torch.inference_mode(): # Load Tokenizer and Model from HF Hub tokenizer = AutoTokenizer.from_pretrained(model_path) model = AutoModelForSequenceClassification.from_pretrained(model_path) # Initialize detectors (these internal classes should use the loaded model) detector = CombinedCodeDetector() fix_gen = FixSuggestionGenerator() rules = RuleBasedCodeDetector() # Inject the HF model into the detector if it expects a local one if hasattr(detector, 'model'): detector.model = model detector.model.eval() if hasattr(detector, 'tokenizer'): detector.tokenizer = tokenizer if hasattr(fix_gen, 'model'): fix_gen.model.eval() return { "detector": detector, "fix_gen": fix_gen, "rules": rules, "model": model, "tokenizer": tokenizer } tools = load_tools() # --- 3. CUSTOM STYLING --- st.markdown(""" """, unsafe_allow_html=True) # --- 4. HEADER --- st.markdown('
Real-time vulnerability detection and AI-powered fixes