tabito12345678910 commited on
Commit
eb9bda6
Β·
1 Parent(s): 574ef11

Fix age range handling and model architecture

Browse files
Files changed (4) hide show
  1. add_debug.js +21 -0
  2. app.py +15 -0
  3. fix_requirements.js +15 -0
  4. inference_yasai_cid.py +19 -4
add_debug.js ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const fs = require('fs');
2
+
3
+ // Read the file
4
+ let content = fs.readFileSync('app.py', 'utf8');
5
+
6
+ // Add more detailed debugging for model loading
7
+ content = content.replace(
8
+ 'if model_files_exist:',
9
+ 'if model_files_exist:\n print(f"πŸ” Checking model files:")\n print(f" - MODEL_PATH: {MODEL_PATH} (exists: {os.path.exists(MODEL_PATH)})")\n print(f" - ENCODERS_DIR: {ENCODERS_DIR} (exists: {os.path.exists(ENCODERS_DIR)})")\n print(f" - PRODUCT_MASTER_PATH: {PRODUCT_MASTER_PATH} (exists: {os.path.exists(PRODUCT_MASTER_PATH)})")\n \n # Check file sizes\n if os.path.exists(MODEL_PATH):\n model_size = os.path.getsize(MODEL_PATH) / (1024*1024) # MB\n print(f" - Model file size: {model_size:.2f} MB")\n \n if os.path.exists(ENCODERS_DIR):\n encoder_files = [f for f in os.listdir(ENCODERS_DIR) if f.endswith(".json")]\n print(f" - Encoder files found: {encoder_files}")'
10
+ );
11
+
12
+ // Add more detailed error logging in the exception handler
13
+ content = content.replace(
14
+ ' except Exception as e:\n print(f"❌ Failed to load Yasai CID model: {e}")',
15
+ ' except Exception as e:\n print(f"❌ Failed to load Yasai CID model: {e}")\n import traceback\n print(f"❌ Full traceback: {traceback.format_exc()}")'
16
+ );
17
+
18
+ // Write the updated content back
19
+ fs.writeFileSync('app.py', content);
20
+
21
+ console.log('Successfully added debugging information to app.py');
app.py CHANGED
@@ -22,6 +22,19 @@ model_files_exist = all([
22
  ])
23
 
24
  if model_files_exist:
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  try:
26
  from inference_yasai_cid import YasaiCIDInferenceEngine
27
  engine = YasaiCIDInferenceEngine(
@@ -32,6 +45,8 @@ if model_files_exist:
32
  print("βœ… Yasai CID model loaded successfully!")
33
  except Exception as e:
34
  print(f"❌ Failed to load Yasai CID model: {e}")
 
 
35
  engine = None
36
  else:
37
  print("⚠️ Model files not found. This is a template - add your model files to:")
 
22
  ])
23
 
24
  if model_files_exist:
25
+ print(f"πŸ” Checking model files:")
26
+ print(f" - MODEL_PATH: {MODEL_PATH} (exists: {os.path.exists(MODEL_PATH)})")
27
+ print(f" - ENCODERS_DIR: {ENCODERS_DIR} (exists: {os.path.exists(ENCODERS_DIR)})")
28
+ print(f" - PRODUCT_MASTER_PATH: {PRODUCT_MASTER_PATH} (exists: {os.path.exists(PRODUCT_MASTER_PATH)})")
29
+
30
+ # Check file sizes
31
+ if os.path.exists(MODEL_PATH):
32
+ model_size = os.path.getsize(MODEL_PATH) / (1024*1024) # MB
33
+ print(f" - Model file size: {model_size:.2f} MB")
34
+
35
+ if os.path.exists(ENCODERS_DIR):
36
+ encoder_files = [f for f in os.listdir(ENCODERS_DIR) if f.endswith(".json")]
37
+ print(f" - Encoder files found: {encoder_files}")
38
  try:
39
  from inference_yasai_cid import YasaiCIDInferenceEngine
40
  engine = YasaiCIDInferenceEngine(
 
45
  print("βœ… Yasai CID model loaded successfully!")
46
  except Exception as e:
47
  print(f"❌ Failed to load Yasai CID model: {e}")
48
+ import traceback
49
+ print(f"❌ Full traceback: {traceback.format_exc()}")
50
  engine = None
51
  else:
52
  print("⚠️ Model files not found. This is a template - add your model files to:")
fix_requirements.js ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const fs = require('fs');
2
+
3
+ // Read the file
4
+ let content = fs.readFileSync('requirements.txt', 'utf8');
5
+
6
+ // Update rtdl to use a specific version that's compatible with Hugging Face
7
+ content = content.replace(
8
+ 'rtdl ',
9
+ 'rtdl>=0.0.1rc0,<0.1.0'
10
+ );
11
+
12
+ // Write the updated content back
13
+ fs.writeFileSync('requirements.txt', content);
14
+
15
+ console.log('Successfully updated requirements.txt with rtdl version');
inference_yasai_cid.py CHANGED
@@ -57,7 +57,7 @@ class YasaiCIDInferenceEngine:
57
  return None
58
  # Use training-script hyperparameters
59
  model = FTTransformer.make_baseline(
60
- n_num_features=8,
61
  cat_cardinalities=self.cat_cardinalities,
62
  d_out=len(self.all_cids),
63
  d_token=768, # Use the actual saved model's d_token
@@ -106,9 +106,24 @@ class YasaiCIDInferenceEngine:
106
  X_cat.append(self._encode_categorical(self.cat_encoders[col], '__UNKNOWN__'))
107
  X_cat = torch.tensor([X_cat], dtype=torch.long)
108
 
109
- # Numerical features (8 features to match training script)
110
- num_cols = ['LAT', 'LONG', 'DELIVERY_NUM', 'MEDIAN_GENDER_RATIO', 'MODE_TOP_AGE_RANGE_1','TOTAL_VOLUME']
111
- X_num = torch.tensor([[float(df.get(c, pd.Series([0])).iloc[0]) for c in num_cols]], dtype=torch.float32)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
  return X_cat, X_num
113
 
114
  def predict(self, data: Dict) -> List[Dict]:
 
57
  return None
58
  # Use training-script hyperparameters
59
  model = FTTransformer.make_baseline(
60
+ n_num_features=5, # Updated: 5 numerical features (age ranges are now categorical)
61
  cat_cardinalities=self.cat_cardinalities,
62
  d_out=len(self.all_cids),
63
  d_token=768, # Use the actual saved model's d_token
 
106
  X_cat.append(self._encode_categorical(self.cat_encoders[col], '__UNKNOWN__'))
107
  X_cat = torch.tensor([X_cat], dtype=torch.long)
108
 
109
+ # Numerical features (5 features to match training script - age ranges are now categorical)
110
+ # Remove age range fields from numerical features since they're now categorical
111
+ num_cols = ['LAT', 'LONG', 'DELIVERY_NUM', 'MEDIAN_GENDER_RATIO', 'TOTAL_VOLUME']
112
+ X_num = []
113
+ for col in num_cols:
114
+ if col in df.columns:
115
+ try:
116
+ X_num.append(float(df[col].iloc[0]))
117
+ except (ValueError, TypeError):
118
+ X_num.append(0.0)
119
+ else:
120
+ # Provide default values for missing fields
121
+ if col == 'TOTAL_VOLUME':
122
+ X_num.append(0.0) # Default total volume
123
+ else:
124
+ X_num.append(0.0)
125
+
126
+ X_num = torch.tensor([X_num], dtype=torch.float32)
127
  return X_cat, X_num
128
 
129
  def predict(self, data: Dict) -> List[Dict]: