LT360 commited on
Commit ·
47e416f
1
Parent(s): 3ac594e
Final update
Browse files- app/assets/{email_preprocessor_20250506_203148.joblib → multinomial_nb_email_preprocessor.joblib} +2 -2
- app/assets/{phishing_nb_model_20250506_203148.joblib → trained_multinomial_nb_model.joblib} +1 -1
- app/main.py +15 -1
- app/ml/__init__.py +0 -1
- app/ml/bert_mini_model.py +0 -1
- app/ml/nb_model.py +2 -2
app/assets/{email_preprocessor_20250506_203148.joblib → multinomial_nb_email_preprocessor.joblib}
RENAMED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:453890297bdcb067543815f71d347942e84c893111029823940fd2b59fc81ac9
|
| 3 |
+
size 638994
|
app/assets/{phishing_nb_model_20250506_203148.joblib → trained_multinomial_nb_model.joblib}
RENAMED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 544791
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:bd44dafe90588c8ca8a4a3c02890b23596dba3224a9404e1b4b2e44f564d9027
|
| 3 |
size 544791
|
app/main.py
CHANGED
|
@@ -2,12 +2,26 @@ from fastapi import FastAPI
|
|
| 2 |
from pydantic import BaseModel
|
| 3 |
import os
|
| 4 |
import subprocess
|
| 5 |
-
from fastapi import
|
| 6 |
from typing import List, Tuple, Optional
|
| 7 |
from .ml import get_model_prediction, check_model_status
|
| 8 |
|
| 9 |
app = FastAPI(title="AI-Powered Phishing Email Detection System")
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
# Input data model
|
| 12 |
class EmailInput(BaseModel):
|
| 13 |
subject: Optional[str] = ""
|
|
|
|
| 2 |
from pydantic import BaseModel
|
| 3 |
import os
|
| 4 |
import subprocess
|
| 5 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 6 |
from typing import List, Tuple, Optional
|
| 7 |
from .ml import get_model_prediction, check_model_status
|
| 8 |
|
| 9 |
app = FastAPI(title="AI-Powered Phishing Email Detection System")
|
| 10 |
|
| 11 |
+
# Define allowed origins for CORS
|
| 12 |
+
origins = [
|
| 13 |
+
"https://ai-powered-phishing-email-detection-system.vercel.app",
|
| 14 |
+
"http://localhost:3000",
|
| 15 |
+
]
|
| 16 |
+
|
| 17 |
+
app.add_middleware(
|
| 18 |
+
CORSMiddleware,
|
| 19 |
+
allow_origins=origins, # Allows specific origins
|
| 20 |
+
allow_credentials=True, # Allows cookies to be included in requests
|
| 21 |
+
allow_methods=["*"], # Allows all methods (GET, POST, etc.)
|
| 22 |
+
allow_headers=["*"], # Allows all headers
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
# Input data model
|
| 26 |
class EmailInput(BaseModel):
|
| 27 |
subject: Optional[str] = ""
|
app/ml/__init__.py
CHANGED
|
@@ -21,7 +21,6 @@ def get_model_prediction(subject: str, sender: str, body: str, model_choice: str
|
|
| 21 |
return {"error": f"Invalid model_choice: '{model_choice}'. Choose 'nb' or 'bert-mini'.",
|
| 22 |
"prediction": "Error", "label": -1, "confidence": 0.0, "explanation": []}
|
| 23 |
|
| 24 |
-
# You can also add a health check function here if needed
|
| 25 |
def check_model_status():
|
| 26 |
status = {
|
| 27 |
"naive_bayes": {
|
|
|
|
| 21 |
return {"error": f"Invalid model_choice: '{model_choice}'. Choose 'nb' or 'bert-mini'.",
|
| 22 |
"prediction": "Error", "label": -1, "confidence": 0.0, "explanation": []}
|
| 23 |
|
|
|
|
| 24 |
def check_model_status():
|
| 25 |
status = {
|
| 26 |
"naive_bayes": {
|
app/ml/bert_mini_model.py
CHANGED
|
@@ -69,7 +69,6 @@ def get_prediction_and_explanation_bert_mini(subject: str, sender: str, body: st
|
|
| 69 |
cleaned_body = simple_text_clean(body)
|
| 70 |
|
| 71 |
combined_text_for_prediction = f"{cleaned_sender} {cleaned_subject} {cleaned_body}"
|
| 72 |
-
text_for_lime_explanation = combined_text_for_prediction
|
| 73 |
|
| 74 |
|
| 75 |
try:
|
|
|
|
| 69 |
cleaned_body = simple_text_clean(body)
|
| 70 |
|
| 71 |
combined_text_for_prediction = f"{cleaned_sender} {cleaned_subject} {cleaned_body}"
|
|
|
|
| 72 |
|
| 73 |
|
| 74 |
try:
|
app/ml/nb_model.py
CHANGED
|
@@ -6,8 +6,8 @@ from lime.lime_text import LimeTextExplainer
|
|
| 6 |
from .common import simple_text_clean, CLASS_NAMES
|
| 7 |
|
| 8 |
ASSETS_DIR = os.path.join(os.path.dirname(__file__), '..', 'assets')
|
| 9 |
-
PREPROCESSOR_FILENAME = "
|
| 10 |
-
MODEL_FILENAME = "
|
| 11 |
PREPROCESSOR_PATH = os.path.join(ASSETS_DIR, PREPROCESSOR_FILENAME)
|
| 12 |
MODEL_PATH = os.path.join(ASSETS_DIR, MODEL_FILENAME)
|
| 13 |
|
|
|
|
| 6 |
from .common import simple_text_clean, CLASS_NAMES
|
| 7 |
|
| 8 |
ASSETS_DIR = os.path.join(os.path.dirname(__file__), '..', 'assets')
|
| 9 |
+
PREPROCESSOR_FILENAME = "multinomial_nb_email_preprocessor.joblib"
|
| 10 |
+
MODEL_FILENAME = "trained_multinomial_nb_model.joblib"
|
| 11 |
PREPROCESSOR_PATH = os.path.join(ASSETS_DIR, PREPROCESSOR_FILENAME)
|
| 12 |
MODEL_PATH = os.path.join(ASSETS_DIR, MODEL_FILENAME)
|
| 13 |
|