Spaces:
Sleeping
Sleeping
update gitignore for model files
Browse files- .gitignore +3 -0
- app.py +46 -5
- requirements.txt +2 -1
.gitignore
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
models/
|
| 2 |
+
*.pkl
|
| 3 |
+
model_cache.pkl
|
app.py
CHANGED
|
@@ -9,6 +9,11 @@ Implementation: Private (using pre-trained models)
|
|
| 9 |
"""
|
| 10 |
|
| 11 |
# app.py - Main Gradio interface (PUBLIC)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
import gradio as gr
|
| 13 |
import pickle
|
| 14 |
import numpy as np
|
|
@@ -20,13 +25,49 @@ import warnings
|
|
| 20 |
warnings.filterwarnings('ignore')
|
| 21 |
|
| 22 |
# Load pre-trained detector (implementation hidden in pickle)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
try:
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
except Exception as e:
|
| 28 |
-
print(f"❌ Error loading detector: {e}")
|
| 29 |
detector = None
|
|
|
|
| 30 |
|
| 31 |
# Demo configuration
|
| 32 |
DEMO_CONFIG = {
|
|
@@ -333,4 +374,4 @@ if __name__ == "__main__":
|
|
| 333 |
show_error=True,
|
| 334 |
show_tips=True,
|
| 335 |
enable_queue=True
|
| 336 |
-
)
|
|
|
|
| 9 |
"""
|
| 10 |
|
| 11 |
# app.py - Main Gradio interface (PUBLIC)
|
| 12 |
+
|
| 13 |
+
# Add at the top of app.py
|
| 14 |
+
import requests
|
| 15 |
+
import os
|
| 16 |
+
|
| 17 |
import gradio as gr
|
| 18 |
import pickle
|
| 19 |
import numpy as np
|
|
|
|
| 25 |
warnings.filterwarnings('ignore')
|
| 26 |
|
| 27 |
# Load pre-trained detector (implementation hidden in pickle)
|
| 28 |
+
|
| 29 |
+
def download_model():
|
| 30 |
+
"""Download model from Google Drive if not cached."""
|
| 31 |
+
model_path = "models/ai_security_detector.pkl"
|
| 32 |
+
|
| 33 |
+
if not os.path.exists(model_path):
|
| 34 |
+
print("📥 Downloading AI security model...")
|
| 35 |
+
|
| 36 |
+
# Your Google Drive file ID
|
| 37 |
+
file_id = "1prYcoojiqSpdNzcSm0frrloA3L9lnVC7"
|
| 38 |
+
download_url = f"https://drive.google.com/uc?id={file_id}"
|
| 39 |
+
|
| 40 |
+
os.makedirs("models", exist_ok=True)
|
| 41 |
+
|
| 42 |
+
try:
|
| 43 |
+
response = requests.get(download_url)
|
| 44 |
+
response.raise_for_status() # Raise exception for bad status codes
|
| 45 |
+
|
| 46 |
+
with open(model_path, "wb") as f:
|
| 47 |
+
f.write(response.content)
|
| 48 |
+
|
| 49 |
+
print("✅ Model downloaded successfully!")
|
| 50 |
+
|
| 51 |
+
except Exception as e:
|
| 52 |
+
print(f"❌ Error downloading model: {e}")
|
| 53 |
+
print("⚠️ Using fallback detector...")
|
| 54 |
+
return None
|
| 55 |
+
|
| 56 |
+
return model_path
|
| 57 |
+
|
| 58 |
+
# Load model at startup
|
| 59 |
try:
|
| 60 |
+
model_path = download_model()
|
| 61 |
+
if model_path and os.path.exists(model_path):
|
| 62 |
+
with open(model_path, 'rb') as f:
|
| 63 |
+
detector = pickle.load(f)
|
| 64 |
+
print("✅ AI Security Detector loaded successfully")
|
| 65 |
+
else:
|
| 66 |
+
detector = None
|
| 67 |
+
print("⚠️ Using fallback mode")
|
| 68 |
except Exception as e:
|
|
|
|
| 69 |
detector = None
|
| 70 |
+
print(f"❌ Error loading detector: {e}")
|
| 71 |
|
| 72 |
# Demo configuration
|
| 73 |
DEMO_CONFIG = {
|
|
|
|
| 374 |
show_error=True,
|
| 375 |
show_tips=True,
|
| 376 |
enable_queue=True
|
| 377 |
+
)
|
requirements.txt
CHANGED
|
@@ -3,4 +3,5 @@ numpy==1.24.3
|
|
| 3 |
pandas==2.0.3
|
| 4 |
scikit-learn==1.3.0
|
| 5 |
sentence-transformers==2.2.2
|
| 6 |
-
scipy==1.11.1
|
|
|
|
|
|
| 3 |
pandas==2.0.3
|
| 4 |
scikit-learn==1.3.0
|
| 5 |
sentence-transformers==2.2.2
|
| 6 |
+
scipy==1.11.1
|
| 7 |
+
requests==2.31.0
|