Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance xGitGuard Scanner with BERT Model for Advanced Secret Detection (Generated by Ana - AI SDE) #37

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 5 additions & 15 deletions xgitguard/github-enterprise/enterprise_cred_detections.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,21 +614,11 @@ def run_detection(
search_query_list = format_search_query_list(configs.secondary_keywords)
if search_query_list:
if ml_prediction:
# Train Model if not present Already
model_file = os.path.join(
configs.output_dir, "xgg_cred_rf_model_object.pickle"
)
if os.path.exists(model_file):
logger.info(
f"Detection process will use Already persisted Trained Model present in: {model_file}"
)
else:
logger.info(
f"No persisted Trained Model present. So training and persisting a model now"
)
xgg_train_model(
training_data_file="cred_train.csv", model_name="xgg_cred_rf_"
)
# Load BERT model and tokenizer
bert_model_path = "path_to_bert_model/bert_secret_detection_model"
tokenizer = BertTokenizer.from_pretrained(bert_model_path)
model = BertForSequenceClassification.from_pretrained(bert_model_path)
model.eval() # Set model to evaluation mode
else:
logger.info(f"No Search query to process. Ending.")
sys.exit(1)
Expand Down
20 changes: 5 additions & 15 deletions xgitguard/github-enterprise/enterprise_key_detections.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,21 +593,11 @@ def run_detection(
search_query_list = format_search_query_list(configs.secondary_keywords)
if search_query_list:
if ml_prediction:
# Train Model if not present Already
model_file = os.path.join(
configs.output_dir, "xgg_key_rf_model_object.pickle"
)
if os.path.exists(model_file):
logger.info(
f"Detection process will use Already persisted Trained Model present in: {model_file}"
)
else:
logger.info(
f"No persisted Trained Model present. So training and persisting a model now"
)
xgg_train_model(
training_data_file="key_train.csv", model_name="xgg_key_rf_"
)
# Load BERT model and tokenizer
bert_model_path = "path_to_bert_model/bert_secret_detection_model"
tokenizer = BertTokenizer.from_pretrained(bert_model_path)
model = BertForSequenceClassification.from_pretrained(bert_model_path)
model.eval() # Set model to evaluation mode
else:
logger.info(f"No Search query to process. Ending.")
sys.exit(1)
Expand Down
21 changes: 5 additions & 16 deletions xgitguard/github-public/public_cred_detections.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,22 +628,11 @@ def run_detection(
)
if search_query_list:
if ml_prediction:
# Train Model if not present Already
model_file = os.path.join(
configs.output_dir, "public_xgg_cred_rf_model_object.pickle"
)
if os.path.exists(model_file):
logger.info(
f"Detection process will use Already persisted Trained Model present in: {model_file}"
)
else:
logger.info(
f"No persisted Trained Model present. So training and persisting a model now"
)
xgg_train_model(
training_data_file="public_cred_train.csv",
model_name="public_xgg_cred_rf_",
)
# Load BERT model and tokenizer
bert_model_path = "path_to_bert_model/bert_secret_detection_model"
tokenizer = BertTokenizer.from_pretrained(bert_model_path)
model = BertForSequenceClassification.from_pretrained(bert_model_path)
model.eval() # Set model to evaluation mode
else:
logger.info(f"No Search query to process. Ending.")
sys.exit(1)
Expand Down
21 changes: 5 additions & 16 deletions xgitguard/github-public/public_key_detections.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,22 +603,11 @@ def run_detection(
)
if search_query_list:
if ml_prediction:
# Train Model if not present Already
model_file = os.path.join(
configs.output_dir, "public_xgg_key_rf_model_object.pickle"
)
if os.path.exists(model_file):
logger.info(
f"Detection process will use Already persisted Trained Model present in: {model_file}"
)
else:
logger.info(
f"No persisted Trained Model present. So training and persisting a model now"
)
xgg_train_model(
training_data_file="public_key_train.csv",
model_name="public_xgg_key_rf_",
)
# Load BERT model and tokenizer
bert_model_path = "path_to_bert_model/bert_secret_detection_model"
tokenizer = BertTokenizer.from_pretrained(bert_model_path)
model = BertForSequenceClassification.from_pretrained(bert_model_path)
model.eval() # Set model to evaluation mode
else:
logger.info(f"No Search query to process. Ending.")
sys.exit(1)
Expand Down