Spaces:
Configuration error
Configuration error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,34 +1,50 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import tensorflow as tf
|
| 3 |
-
import cv2
|
| 4 |
-
import numpy as np
|
| 5 |
import pandas as pd
|
| 6 |
-
from sklearn.preprocessing import LabelEncoder
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
#
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import pandas as pd
|
| 2 |
+
from sklearn.preprocessing import LabelEncoder
|
| 3 |
+
from sklearn.ensemble import RandomForestClassifier
|
| 4 |
+
from sklearn.model_selection import train_test_split
|
| 5 |
+
import gradio as gr
|
| 6 |
+
|
| 7 |
+
# Function to load/generate data (replace with your data loading logic)
|
| 8 |
+
def load_data():
|
| 9 |
+
data = {
|
| 10 |
+
'face_shape': ['round', 'oval', 'square', 'heart', 'oval', 'round', 'square', 'heart', 'oval', 'square'],
|
| 11 |
+
'skin_tone': ['fair', 'medium', 'deep', 'cool', 'warm', 'fair', 'medium', 'deep', 'cool', 'warm'],
|
| 12 |
+
'face_size': ['small', 'medium', 'large', 'medium', 'small', 'large', 'small', 'large', 'medium', 'small'],
|
| 13 |
+
'mask_style': ['glitter_cat', 'gold_venetian', 'black_minimal', 'floral_masquerade', 'gold_venetian',
|
| 14 |
+
'glitter_cat', 'black_minimal', 'floral_masquerade', 'gold_venetian', 'black_minimal']
|
| 15 |
+
}
|
| 16 |
+
return pd.DataFrame(data)
|
| 17 |
+
|
| 18 |
+
# Rest of your code (preprocessing, model training, recommend_mask function)
|
| 19 |
+
# Split features and target
|
| 20 |
+
X = df[['face_shape', 'skin_tone', 'face_size']]
|
| 21 |
+
y = df['mask_style']
|
| 22 |
+
|
| 23 |
+
# Split into train and test sets
|
| 24 |
+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5, random_state=42, stratify=y)
|
| 25 |
+
|
| 26 |
+
# Train Random Forest
|
| 27 |
+
rf_model = RandomForestClassifier(n_estimators=100, random_state=42)
|
| 28 |
+
|
| 29 |
+
rf_model.fit(X_train, y_train)
|
| 30 |
+
df = load_data()
|
| 31 |
+
# ... (preprocessing, model training)
|
| 32 |
+
|
| 33 |
+
# ... (recommend_mask function)
|
| 34 |
+
|
| 35 |
+
# ... (Get unique values for dropdown choices)
|
| 36 |
+
|
| 37 |
+
# Define Gradio interface
|
| 38 |
+
iface = gr.Interface(
|
| 39 |
+
fn=recommend_mask,
|
| 40 |
+
inputs=[
|
| 41 |
+
gr.Dropdown(choices=face_shapes_labels, label="Face Shape"),
|
| 42 |
+
gr.Dropdown(choices=skin_tones_labels, label="Skin Tone"),
|
| 43 |
+
gr.Dropdown(choices=face_sizes_labels, label="Face Size"),
|
| 44 |
+
],
|
| 45 |
+
outputs="text",
|
| 46 |
+
title="🎭 Party Face Mask Recommender",
|
| 47 |
+
description="Get personalized party face mask recommendations based on your facial features."
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
+
iface.launch(share=True, server_name="0.0.0.0", server_port=7860) # Updated launch for Hugging Face
|