Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -106,37 +106,40 @@ def predict(image):
|
|
| 106 |
frame_recommendations = recommend_glasses_tree(pred_label)
|
| 107 |
|
| 108 |
description = face_shape_descriptions[pred_label]
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
# Load images for all recommended frames
|
| 112 |
-
for frame in frame_recommendations:
|
| 113 |
-
frame_image_path = glasses_images.get(frame)
|
| 114 |
-
if frame_image_path and os.path.exists(frame_image_path):
|
| 115 |
-
frame_image = Image.open(frame_image_path)
|
| 116 |
-
frame_images.append(frame_image)
|
| 117 |
|
| 118 |
# Build explanation text
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
|
| 125 |
except Exception as e:
|
| 126 |
-
return "Error
|
| 127 |
|
| 128 |
# Gradio Interface
|
| 129 |
iface = gr.Interface(
|
| 130 |
fn=predict,
|
| 131 |
inputs=gr.Image(type="pil"),
|
| 132 |
outputs=[
|
| 133 |
-
gr.
|
| 134 |
-
gr.
|
|
|
|
| 135 |
],
|
| 136 |
title="Rekomendasi Kacamata Berdasarkan Bentuk Wajah",
|
| 137 |
-
description="Upload foto wajahmu untuk mendapatkan rekomendasi bentuk kacamata yang sesuai
|
| 138 |
-
layout="vertical", # Stack components vertically
|
| 139 |
-
theme="compact" # Compact theme for a cleaner design
|
| 140 |
)
|
| 141 |
|
| 142 |
if __name__ == "__main__":
|
|
|
|
| 106 |
frame_recommendations = recommend_glasses_tree(pred_label)
|
| 107 |
|
| 108 |
description = face_shape_descriptions[pred_label]
|
| 109 |
+
frame_image_path = glasses_images.get(pred_label)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
|
| 111 |
# Build explanation text
|
| 112 |
+
if frame_recommendations:
|
| 113 |
+
recommended_frames = ', '.join(frame_recommendations)
|
| 114 |
+
explanation = (f"Bentuk wajah kamu adalah {pred_label} ({pred_prob:.2f}%). "
|
| 115 |
+
f"Kamu memiliki bentuk wajah {description} "
|
| 116 |
+
f"Rekomendasi bentuk kacamata yang sesuai dengan wajah kamu adalah: {recommended_frames}.")
|
| 117 |
+
else:
|
| 118 |
+
explanation = (f"Bentuk wajah kamu adalah {pred_label} ({pred_prob:.2f}%). "
|
| 119 |
+
f"Tidak ada rekomendasi frame untuk bentuk wajah ini.")
|
| 120 |
+
|
| 121 |
+
# Load frame image if available
|
| 122 |
+
if frame_image_path and os.path.exists(frame_image_path):
|
| 123 |
+
frame_image = Image.open(frame_image_path)
|
| 124 |
+
else:
|
| 125 |
+
frame_image = None
|
| 126 |
+
|
| 127 |
+
return pred_label, explanation, frame_image
|
| 128 |
|
| 129 |
except Exception as e:
|
| 130 |
+
return "Error", str(e), None
|
| 131 |
|
| 132 |
# Gradio Interface
|
| 133 |
iface = gr.Interface(
|
| 134 |
fn=predict,
|
| 135 |
inputs=gr.Image(type="pil"),
|
| 136 |
outputs=[
|
| 137 |
+
gr.Textbox(label="Bentuk Wajah Terdeteksi"),
|
| 138 |
+
gr.Textbox(label="Rekomendasi dan Penjelasan"),
|
| 139 |
+
gr.Image(label="Gambar Frame Rekomendasi")
|
| 140 |
],
|
| 141 |
title="Rekomendasi Kacamata Berdasarkan Bentuk Wajah",
|
| 142 |
+
description="Upload foto wajahmu untuk mendapatkan rekomendasi bentuk kacamata yang sesuai!"
|
|
|
|
|
|
|
| 143 |
)
|
| 144 |
|
| 145 |
if __name__ == "__main__":
|