import gradio as gr
import tensorflow as tf
import numpy as np
from PIL import Image
# Load the trained model
model = tf.keras.models.load_model("fashion_classifier_model.keras")
# Class labels and tips
class_names = ['casual', 'formal', 'party', 'sporty', 'traditional']
tips = {
"casual": "๐ก Add a denim jacket or crossbody bag to glow up your everyday look.",
"formal": "๐ก Blazers + sleek ponytail = Powerhouse vibes.",
"party": "๐ก Bold lips or glitter heels will steal the spotlight.",
"sporty": "๐ก Pair it with sneakers, a cap, and bold energy.",
"traditional": "๐ก Colorful bangles or a bright dupatta will complete your ethnic glam."
}
# Prediction function (filepath version for mobile upload fix)
def predict_style(image_path):
image = Image.open(image_path).resize((224, 224)).convert("RGB")
image_array = np.expand_dims(np.array(image) / 255.0, axis=0)
prediction = model.predict(image_array)
index = np.argmax(prediction)
label = class_names[index].upper()
confidence = prediction[0][index] * 100
result = f"
๐ Your Style Match: {label}
๐ Confidence: {confidence:.2f}%
"
style_tip = f"{tips[class_names[index]]}
"
return result, style_tip
# Gradio interface
with gr.Blocks(css="""
.result-box {
background-color: #fff0f5;
border: 2px solid #ffa5ba;
border-radius: 16px;
padding: 20px;
text-align: center;
margin-top: 10px;
font-size: 18px;
}
.tip-box {
background-color: #fffafc;
border-left: 6px solid #ff69b4;
padding: 16px;
margin-top: 10px;
font-style: italic;
font-size: 16px;
}
h1 {
color: #d63384;
text-align: center;
font-size: 36px;
}
body, .gradio-container {
background: linear-gradient(to bottom, #fdf2f8, #ffffff);
}
.description {
background-color: #fff8fc;
border-left: 5px solid #ff69b4;
padding: 14px;
margin: 15px 0 30px 0;
font-size: 16px;
color: #a83279;
}
""") as demo:
gr.Markdown("# ๐ FashionVision AI ๐ ")
gr.Markdown("""
โจ FashionVision AI is your personal **women's fashion stylist** powered by AI.
Upload your outfit photo and let our model classify your style into:
Casual, Formal, Party, Sporty, or Traditional looks.
Ideal for digital wardrobes, e-commerce previews, or just having fun with your style! ๐๐
""")
with gr.Row():
with gr.Column():
img = gr.Image(label="๐ธ Upload your outfit (for women)", type="filepath", image_mode="RGB")
btn = gr.Button("โจ Detect My Style")
with gr.Column():
result = gr.HTML()
tip = gr.HTML()
btn.click(predict_style, inputs=img, outputs=[result, tip])
gr.Markdown("---")
gr.Markdown("๐งต Made with ๐ by Subata | Powered by TensorFlow + Gradio
")
demo.launch()