Spaces:
Configuration error
Configuration error
Update app.py
Browse files
app.py
CHANGED
|
@@ -60,10 +60,18 @@ def recommend_mask(image):
|
|
| 60 |
# Predict
|
| 61 |
prediction = model.predict([[face_encoded, skin_encoded, size_encoded]])[0]
|
| 62 |
return encoders["mask_style"].classes_[prediction]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
except Exception as e:
|
| 65 |
print(f"Prediction error: {str(e)}")
|
| 66 |
-
return
|
|
|
|
| 67 |
|
| 68 |
# Initialize model and encoders
|
| 69 |
model, encoders = safe_load_model()
|
|
@@ -71,8 +79,11 @@ model, encoders = safe_load_model()
|
|
| 71 |
# Create Gradio interface
|
| 72 |
demo = gr.Interface(
|
| 73 |
fn=recommend_mask,
|
| 74 |
-
inputs=gr.Image(
|
| 75 |
-
outputs=
|
|
|
|
|
|
|
|
|
|
| 76 |
title="🎭 AI Party Mask Recommender",
|
| 77 |
description="Upload a photo to get a personalized mask recommendation!",
|
| 78 |
)
|
|
|
|
| 60 |
# Predict
|
| 61 |
prediction = model.predict([[face_encoded, skin_encoded, size_encoded]])[0]
|
| 62 |
return encoders["mask_style"].classes_[prediction]
|
| 63 |
+
|
| 64 |
+
# Get recommended mask image path
|
| 65 |
+
mask_image_path = encoders['mask_images'][prediction]
|
| 66 |
+
return (
|
| 67 |
+
encoders["mask_style"].classes_[prediction], # Text
|
| 68 |
+
mask_image_path # Image
|
| 69 |
+
)
|
| 70 |
|
| 71 |
except Exception as e:
|
| 72 |
print(f"Prediction error: {str(e)}")
|
| 73 |
+
return "Error", "default_mask.png" # Fallback
|
| 74 |
+
|
| 75 |
|
| 76 |
# Initialize model and encoders
|
| 77 |
model, encoders = safe_load_model()
|
|
|
|
| 79 |
# Create Gradio interface
|
| 80 |
demo = gr.Interface(
|
| 81 |
fn=recommend_mask,
|
| 82 |
+
inputs=gr.Image(type="filepath"),
|
| 83 |
+
outputs=[
|
| 84 |
+
gr.Textbox(label="Recommended Style"),
|
| 85 |
+
gr.Image(label="Mask Preview") # Add image output
|
| 86 |
+
],
|
| 87 |
title="🎭 AI Party Mask Recommender",
|
| 88 |
description="Upload a photo to get a personalized mask recommendation!",
|
| 89 |
)
|