KaiquanMah commited on
Commit
bf13b46
·
verified ·
1 Parent(s): 0d49c8b

Update modelConnector.py

Browse files
Files changed (1) hide show
  1. modelConnector.py +6 -6
modelConnector.py CHANGED
@@ -5,9 +5,9 @@ from huggingface_hub import hf_hub_download, HfApi
5
  from model_trainer import train_models # Assumes model_trainer.py exists with train_models function
6
 
7
  # Hugging Face Model & Dataset Information
8
- MODEL_REPO = "spaces/chagu13/is_click"
9
  MODEL_FILENAME = "models/rf_model.pkl"
10
- DATA_REPO = "datasets/chagu13/is_click_data"
11
  LOCAL_MODEL_PATH = f"models/{MODEL_FILENAME}"
12
 
13
  # Hugging Face API
@@ -23,7 +23,7 @@ class ModelConnector:
23
  def check_model_exists(self):
24
  """Check if the model exists on Hugging Face."""
25
  try:
26
- hf_hub_download(repo_id=MODEL_REPO, filename=MODEL_FILENAME)
27
  return True
28
  except Exception:
29
  return False
@@ -31,7 +31,7 @@ class ModelConnector:
31
  def load_model(self):
32
  """Download and load the model from Hugging Face."""
33
  if self.check_model_exists():
34
- model_path = hf_hub_download(repo_id=MODEL_REPO, filename=MODEL_FILENAME)
35
  return joblib.load(model_path)
36
  return None
37
 
@@ -39,7 +39,7 @@ class ModelConnector:
39
  """Train a new model and upload it to Hugging Face."""
40
  try:
41
  # Load dataset
42
- train_data_path = hf_hub_download(repo_id=DATA_REPO, filename="train_dataset_full.csv")
43
  train_data = pd.read_csv(train_data_path)
44
 
45
  X_train = train_data.drop(columns=["is_click"])
@@ -69,7 +69,7 @@ class ModelConnector:
69
  """Retrain the existing model with new data."""
70
  try:
71
  # Load dataset
72
- train_data_path = hf_hub_download(repo_id=DATA_REPO, filename="train_dataset_full.csv")
73
  train_data = pd.read_csv(train_data_path)
74
 
75
  X_train = train_data.drop(columns=["is_click"])
 
5
  from model_trainer import train_models # Assumes model_trainer.py exists with train_models function
6
 
7
  # Hugging Face Model & Dataset Information
8
+ MODEL_REPO = "chagu13/is_click"
9
  MODEL_FILENAME = "models/rf_model.pkl"
10
+ DATA_REPO = "chagu13/is_click_data"
11
  LOCAL_MODEL_PATH = f"models/{MODEL_FILENAME}"
12
 
13
  # Hugging Face API
 
23
  def check_model_exists(self):
24
  """Check if the model exists on Hugging Face."""
25
  try:
26
+ hf_hub_download(repo_id=MODEL_REPO, repo_type="space", filename=MODEL_FILENAME)
27
  return True
28
  except Exception:
29
  return False
 
31
  def load_model(self):
32
  """Download and load the model from Hugging Face."""
33
  if self.check_model_exists():
34
+ model_path = hf_hub_download(repo_id=MODEL_REPO, repo_type="space", filename=MODEL_FILENAME)
35
  return joblib.load(model_path)
36
  return None
37
 
 
39
  """Train a new model and upload it to Hugging Face."""
40
  try:
41
  # Load dataset
42
+ train_data_path = hf_hub_download(repo_id=DATA_REPO, repo_type="dataset", filename="train_dataset_full.csv")
43
  train_data = pd.read_csv(train_data_path)
44
 
45
  X_train = train_data.drop(columns=["is_click"])
 
69
  """Retrain the existing model with new data."""
70
  try:
71
  # Load dataset
72
+ train_data_path = hf_hub_download(repo_id=DATA_REPO, repo_type="dataset", filename="train_dataset_full.csv")
73
  train_data = pd.read_csv(train_data_path)
74
 
75
  X_train = train_data.drop(columns=["is_click"])