File size: 2,697 Bytes
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
#!/bin/bash

# AI Code Security Scanner - Deployment Script
# Usage: ./deploy.sh [huggingface|docker|local]

set -e  # Exit on error

echo "πŸš€ AI Code Security Scanner - Deployment"
echo "========================================"

DEPLOY_TARGET=${1:-"huggingface"}

case $DEPLOY_TARGET in
    "huggingface")
        echo "🎯 Deploying to Hugging Face Spaces..."
        
        # Check for HF_TOKEN
        if [ -z "$HF_TOKEN" ]; then
            echo "❌ HF_TOKEN environment variable not set"
            echo "Please set your Hugging Face token:"
            echo "export HF_TOKEN=your_token_here"
            exit 1
        fi
        
        # Prepare files
        cp app_hf.py app.py
        cp requirements_hf.txt requirements.txt
        
        # Clone space (assuming it exists)
        git clone https://$HF_TOKEN@huggingface.co/spaces/$HF_USERNAME/code-security-scanner
        cd code-security-scanner
        
        # Copy files
        cp ../app.py .
        cp ../requirements.txt .
        cp ../combined_detector.py .
        cp ../rule_detector.py .
        cp ../fix_generator.py .
        
        # Commit and push
        git add .
        git commit -m "Deploy: $(date)"
        git push origin main
        
        echo "βœ… Deployed to Hugging Face!"
        echo "🌐 Your space: https://huggingface.co/spaces/$HF_USERNAME/code-security-scanner"
        ;;
    
    "docker")
        echo "🐳 Building Docker image..."
        
        # Build image
        docker build -t ai-code-security-scanner:latest .
        
        # Run container
        docker run -d -p 8501:8501 --name code-scanner ai-code-security-scanner:latest
        
        echo "βœ… Docker container running!"
        echo "🌐 Access at: http://localhost:8501"
        ;;
    
    "local")
        echo "πŸ’» Setting up local development..."
        
        # Create virtual environment
        python -m venv venv
        
        # Activate (platform specific)
        if [ "$OSTYPE" = "msys" ] || [ "$OSTYPE" = "cygwin" ]; then
            # Windows
            source venv/Scripts/activate
        else
            # Unix/Linux/Mac
            source venv/bin/activate
        fi
        
        # Install dependencies
        pip install --upgrade pip
        pip install -r requirements.txt
        
        echo "βœ… Local setup complete!"
        echo "πŸ‘‰ Activate: source venv/bin/activate"
        echo "πŸ‘‰ Run: streamlit run app.py"
        ;;
    
    *)
        echo "❌ Unknown deployment target: $DEPLOY_TARGET"
        echo "Usage: ./deploy.sh [huggingface|docker|local]"
        exit 1
        ;;
esac

echo ""
echo "πŸŽ‰ Deployment completed successfully!"