RICHERGIRL commited on
Commit
29a3b4c
·
verified ·
1 Parent(s): cd294bb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -21
app.py CHANGED
@@ -6,6 +6,26 @@ from sklearn.ensemble import RandomForestClassifier
6
  from sklearn.preprocessing import LabelEncoder
7
  from utils import extract_features
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  def safe_load_model():
10
  """Safely loads model files with comprehensive fallback"""
11
  try:
@@ -48,27 +68,6 @@ def recommend_mask(image):
48
  # Initialize model and encoders
49
  model, encoders = safe_load_model()
50
 
51
- def initialize_fallback_model():
52
- """Creates and trains a simple fallback model"""
53
- print("Initializing fallback model...")
54
-
55
- # Simple training data
56
- X = np.array([[0,0,0], [1,1,1], [2,2,2]]) # Dummy encoded features
57
- y = np.array([0, 1, 0]) # Dummy target
58
-
59
- model = RandomForestClassifier(n_estimators=10)
60
- model.fit(X, y)
61
-
62
- encoders = {
63
- 'face_shape': LabelEncoder().fit(['Oval', 'Round', 'Square']),
64
- 'skin_tone': LabelEncoder().fit(['Fair', 'Medium', 'Dark']),
65
- 'face_size': LabelEncoder().fit(['Small', 'Medium', 'Large']),
66
- 'mask_style': LabelEncoder().fit(['StyleA', 'StyleB', 'StyleC']) # Added mask_style
67
- }
68
-
69
- return model, encoders
70
-
71
-
72
  # Create Gradio interface
73
  demo = gr.Interface(
74
  fn=recommend_mask,
 
6
  from sklearn.preprocessing import LabelEncoder
7
  from utils import extract_features
8
 
9
+ def initialize_fallback_model():
10
+ """Creates and trains a simple fallback model"""
11
+ print("Initializing fallback model...")
12
+
13
+ # Simple training data
14
+ X = np.array([[0,0,0], [1,1,1], [2,2,2]]) # Dummy encoded features
15
+ y = np.array([0, 1, 0]) # Dummy target
16
+
17
+ model = RandomForestClassifier(n_estimators=10)
18
+ model.fit(X, y)
19
+
20
+ encoders = {
21
+ 'face_shape': LabelEncoder().fit(['Oval', 'Round', 'Square']),
22
+ 'skin_tone': LabelEncoder().fit(['Fair', 'Medium', 'Dark']),
23
+ 'face_size': LabelEncoder().fit(['Small', 'Medium', 'Large']),
24
+ 'mask_style': LabelEncoder().fit(['StyleA', 'StyleB', 'StyleC']) # Added mask_style
25
+ }
26
+
27
+ return model, encoders
28
+
29
  def safe_load_model():
30
  """Safely loads model files with comprehensive fallback"""
31
  try:
 
68
  # Initialize model and encoders
69
  model, encoders = safe_load_model()
70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  # Create Gradio interface
72
  demo = gr.Interface(
73
  fn=recommend_mask,