This model classifies dishes based on their ingredients and assigns them either to a Cuisine (20 classes) or a Region (5 classes).
It uses an XGBoost classifier trained on normalized ingredient data.
1from huggingface_hub import hf_hub_download
2import joblib
3
4class CuisineClassifier:
5
6 def __init__(self, classifier="region"):
7 print("Initializing CuisineClassifier...")
8
9 components = ["cuisine_pipeline", "label_encoder"]
10 paths = {}
11
12 print("Downloading files from Hugging Face Hub...")
13 for name in components:
14 print(f"Downloading {name}.joblib ...")
15 try:
16 paths[name] = hf_hub_download(
17 repo_id="NoahMeissner/CuisineClassifier",
18 filename=f"region_classifier/{name}.joblib"
19 if classifier == "cuisine":
20 filename=f"cuisine_classifier/{name}.joblib"
21 )
22 print(f"{name} downloaded.")
23 except Exception as e:
24 print(f"Failed to download {name}: {e}")
25 raise
26
27 print("Loading model components with joblib...")
28 try:
29 self.model = joblib.load(paths["cuisine_pipeline"])
30 print("Model loaded.")
31 self.label_encoder = joblib.load(paths["label_encoder"])
32 print("Label encoder loaded.")
33 except Exception as e:
34 print(f"Failed to load components: {e}")
35 raise
36
37 print("All components loaded successfully.")
38
39 def classify(self, text_input):
40 data = " ".join(text_input)
41 predicted_class = self.model.predict([data])
42 predicted_label = self.label_encoder.inverse_transform(predicted_class)
43 return predicted_label