Subata24 commited on
Commit
1d700fe
Β·
verified Β·
1 Parent(s): bfc479e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -11
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 logic
20
- def predict_style(file):
21
- image = Image.open(file).resize((224, 224)).convert("RGB")
22
- img_array = np.expand_dims(np.array(image) / 255.0, axis=0)
23
- prediction = model.predict(img_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
- tip = f"<div class='tip-box'>{tips[class_names[index]]}</div>"
29
- return result, tip
30
 
31
- # Gradio Interface with Mobile-Compatible Upload
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
- file = gr.File(label="πŸ“Έ Upload your outfit (image file)", file_types=["image"])
81
  btn = gr.Button("✨ Detect My Style")
82
  with gr.Column():
83
  result = gr.HTML()
84
  tip = gr.HTML()
85
 
86
- btn.click(fn=predict_style, inputs=file, 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>")
 
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>")