Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,7 @@ import tensorflow as tf
|
|
| 3 |
import numpy as np
|
| 4 |
from PIL import Image
|
| 5 |
|
| 6 |
-
# Load model
|
| 7 |
model = tf.keras.models.load_model("fashion_classifier_model.keras")
|
| 8 |
|
| 9 |
# Class labels and tips
|
|
@@ -16,19 +16,19 @@ tips = {
|
|
| 16 |
"traditional": "π‘ Colorful bangles or a bright dupatta will complete your ethnic glam."
|
| 17 |
}
|
| 18 |
|
| 19 |
-
# Prediction
|
| 20 |
-
def predict_style(
|
| 21 |
-
image = Image.open(
|
| 22 |
-
|
| 23 |
-
prediction = model.predict(
|
| 24 |
index = np.argmax(prediction)
|
| 25 |
label = class_names[index].upper()
|
| 26 |
confidence = prediction[0][index] * 100
|
| 27 |
result = f"<div class='result-box'><h2>π Your Style Match: {label}</h2><p>π Confidence: {confidence:.2f}%</p></div>"
|
| 28 |
-
|
| 29 |
-
return result,
|
| 30 |
|
| 31 |
-
# Gradio
|
| 32 |
with gr.Blocks(css="""
|
| 33 |
.result-box {
|
| 34 |
background-color: #fff0f5;
|
|
@@ -77,13 +77,13 @@ body, .gradio-container {
|
|
| 77 |
|
| 78 |
with gr.Row():
|
| 79 |
with gr.Column():
|
| 80 |
-
|
| 81 |
btn = gr.Button("β¨ Detect My Style")
|
| 82 |
with gr.Column():
|
| 83 |
result = gr.HTML()
|
| 84 |
tip = gr.HTML()
|
| 85 |
|
| 86 |
-
btn.click(
|
| 87 |
|
| 88 |
gr.Markdown("---")
|
| 89 |
gr.Markdown("<p style='text-align:center;'>π§΅ Made with π by <a href='https://github.com/subata24' target='_blank'>Subata</a> | Powered by TensorFlow + Gradio</p>")
|
|
|
|
| 3 |
import numpy as np
|
| 4 |
from PIL import Image
|
| 5 |
|
| 6 |
+
# Load the trained model
|
| 7 |
model = tf.keras.models.load_model("fashion_classifier_model.keras")
|
| 8 |
|
| 9 |
# Class labels and tips
|
|
|
|
| 16 |
"traditional": "π‘ Colorful bangles or a bright dupatta will complete your ethnic glam."
|
| 17 |
}
|
| 18 |
|
| 19 |
+
# Prediction function (filepath version for mobile upload fix)
|
| 20 |
+
def predict_style(image_path):
|
| 21 |
+
image = Image.open(image_path).resize((224, 224)).convert("RGB")
|
| 22 |
+
image_array = np.expand_dims(np.array(image) / 255.0, axis=0)
|
| 23 |
+
prediction = model.predict(image_array)
|
| 24 |
index = np.argmax(prediction)
|
| 25 |
label = class_names[index].upper()
|
| 26 |
confidence = prediction[0][index] * 100
|
| 27 |
result = f"<div class='result-box'><h2>π Your Style Match: {label}</h2><p>π Confidence: {confidence:.2f}%</p></div>"
|
| 28 |
+
style_tip = f"<div class='tip-box'>{tips[class_names[index]]}</div>"
|
| 29 |
+
return result, style_tip
|
| 30 |
|
| 31 |
+
# Gradio interface
|
| 32 |
with gr.Blocks(css="""
|
| 33 |
.result-box {
|
| 34 |
background-color: #fff0f5;
|
|
|
|
| 77 |
|
| 78 |
with gr.Row():
|
| 79 |
with gr.Column():
|
| 80 |
+
img = gr.Image(label="πΈ Upload your outfit (for women)", type="filepath", image_mode="RGB")
|
| 81 |
btn = gr.Button("β¨ Detect My Style")
|
| 82 |
with gr.Column():
|
| 83 |
result = gr.HTML()
|
| 84 |
tip = gr.HTML()
|
| 85 |
|
| 86 |
+
btn.click(predict_style, inputs=img, outputs=[result, tip])
|
| 87 |
|
| 88 |
gr.Markdown("---")
|
| 89 |
gr.Markdown("<p style='text-align:center;'>π§΅ Made with π by <a href='https://github.com/subata24' target='_blank'>Subata</a> | Powered by TensorFlow + Gradio</p>")
|