Devishetty100 commited on
Commit
d6dccea
·
verified ·
1 Parent(s): 06f7406

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +16 -3
app.py CHANGED
@@ -10,7 +10,7 @@ from huggingface_hub import hf_hub_download
10
  # Define the model and username
11
  MODEL_NAME = "XGBoost"
12
  HF_USERNAME = "Devishetty100"
13
- CUSTOM_MODEL_NAME = "neoguardianai"
14
  REPO_ID = f"{HF_USERNAME}/{CUSTOM_MODEL_NAME.lower()}"
15
 
16
  # List of trusted domains that should always be considered safe
@@ -32,7 +32,18 @@ TRUSTED_DOMAINS = [
32
  def load_model_files():
33
  try:
34
  print(f"Attempting to download model from Hugging Face Hub: {REPO_ID}")
35
- model_path = hf_hub_download(repo_id=REPO_ID, filename=f"{MODEL_NAME.lower()}_model.joblib")
 
 
 
 
 
 
 
 
 
 
 
36
  scaler_path = hf_hub_download(repo_id=REPO_ID, filename="scaler.joblib")
37
  feature_names_path = hf_hub_download(repo_id=REPO_ID, filename="feature_names.json")
38
 
@@ -52,7 +63,9 @@ def load_model_files():
52
  # If downloading fails, try to load from local files
53
  try:
54
  print("Attempting to load model from local files...")
55
- model = joblib.load(f"{MODEL_NAME.lower()}_model.joblib")
 
 
56
  scaler = joblib.load("scaler.joblib")
57
 
58
  with open("feature_names.json", 'r') as f:
 
10
  # Define the model and username
11
  MODEL_NAME = "XGBoost"
12
  HF_USERNAME = "Devishetty100"
13
+ CUSTOM_MODEL_NAME = "NeoGuardianAI"
14
  REPO_ID = f"{HF_USERNAME}/{CUSTOM_MODEL_NAME.lower()}"
15
 
16
  # List of trusted domains that should always be considered safe
 
32
  def load_model_files():
33
  try:
34
  print(f"Attempting to download model from Hugging Face Hub: {REPO_ID}")
35
+ # Try to list files in the repository to see what's available
36
+ try:
37
+ from huggingface_hub import list_repo_files
38
+ files = list_repo_files(repo_id=REPO_ID)
39
+ print(f"Files available in the repository: {files}")
40
+ except Exception as list_error:
41
+ print(f"Error listing repository files: {list_error}")
42
+
43
+ # Use lowercase 'xgboost' instead of MODEL_NAME.lower() to match the actual filename
44
+ model_path = hf_hub_download(repo_id=REPO_ID, filename="xgboost_model.joblib")
45
+ print(f"Downloaded model file to: {model_path}")
46
+
47
  scaler_path = hf_hub_download(repo_id=REPO_ID, filename="scaler.joblib")
48
  feature_names_path = hf_hub_download(repo_id=REPO_ID, filename="feature_names.json")
49
 
 
63
  # If downloading fails, try to load from local files
64
  try:
65
  print("Attempting to load model from local files...")
66
+ # Try with the correct lowercase name
67
+ model = joblib.load("xgboost_model.joblib")
68
+ print("Successfully loaded xgboost_model.joblib")
69
  scaler = joblib.load("scaler.joblib")
70
 
71
  with open("feature_names.json", 'r') as f: