Spaces:
Sleeping
Sleeping
Update src/app.py
Browse files- src/app.py +38 -2
src/app.py
CHANGED
|
@@ -6,6 +6,38 @@ from PIL import Image
|
|
| 6 |
MODEL_PATH = "src/flower_model.keras"
|
| 7 |
IMAGE_SIZE = 224
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
@st.cache_resource
|
| 10 |
def load_model():
|
| 11 |
return tf.keras.models.load_model(MODEL_PATH)
|
|
@@ -19,7 +51,7 @@ uploaded_file = st.file_uploader("Choose an image", type=["jpg", "jpeg", "png"])
|
|
| 19 |
|
| 20 |
if uploaded_file:
|
| 21 |
image = Image.open(uploaded_file).convert("RGB")
|
| 22 |
-
st.image(image, caption="Uploaded Image",
|
| 23 |
|
| 24 |
image = image.resize((IMAGE_SIZE, IMAGE_SIZE))
|
| 25 |
img_array = np.array(image) / 255.0
|
|
@@ -27,5 +59,9 @@ if uploaded_file:
|
|
| 27 |
|
| 28 |
prediction = model.predict(img_array)
|
| 29 |
predicted_class = np.argmax(prediction)
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
-
st.success(f"
|
|
|
|
|
|
| 6 |
MODEL_PATH = "src/flower_model.keras"
|
| 7 |
IMAGE_SIZE = 224
|
| 8 |
|
| 9 |
+
# 104 Flower Names (Kaggle dataset sırasına göre)
|
| 10 |
+
class_names = [
|
| 11 |
+
"pink primrose","hard-leaved pocket orchid","canterbury bells",
|
| 12 |
+
"sweet pea","english marigold","tiger lily","moon orchid",
|
| 13 |
+
"bird of paradise","monkshood","globe thistle",
|
| 14 |
+
"snapdragon","colt's foot","king protea","spear thistle",
|
| 15 |
+
"yellow iris","globe-flower","purple coneflower",
|
| 16 |
+
"peruvian lily","balloon flower","giant white arum lily",
|
| 17 |
+
"fire lily","pincushion flower","fritillary","red ginger",
|
| 18 |
+
"grape hyacinth","corn poppy","prince of wales feathers",
|
| 19 |
+
"stemless gentian","artichoke","sweet william",
|
| 20 |
+
"carnation","garden phlox","love in the mist","mexican aster",
|
| 21 |
+
"alpine sea holly","ruby-lipped cattleya","cape flower",
|
| 22 |
+
"great masterwort","siam tulip","lenten rose",
|
| 23 |
+
"barbeton daisy","daffodil","sword lily","poinsettia",
|
| 24 |
+
"bolero deep blue","wallflower","marigold","buttercup",
|
| 25 |
+
"oxeye daisy","common dandelion","petunia","wild pansy",
|
| 26 |
+
"primula","sunflower","pelargonium","bishop of llandaff",
|
| 27 |
+
"gaura","geranium","orange dahlia","pink-yellow dahlia",
|
| 28 |
+
"cautleya spicata","japanese anemone","black-eyed susan",
|
| 29 |
+
"silverbush","californian poppy","osteospermum",
|
| 30 |
+
"spring crocus","iris","windflower","tree poppy",
|
| 31 |
+
"gazania","azalea","water lily","rose",
|
| 32 |
+
"thorn apple","morning glory","passion flower","lotus",
|
| 33 |
+
"toad lily","anthurium","frangipani","clematis",
|
| 34 |
+
"hibiscus","columbine","desert-rose","tree mallow",
|
| 35 |
+
"magnolia","cyclamen","watercress","canna lily",
|
| 36 |
+
"hippeastrum","bee balm","ball moss","foxglove",
|
| 37 |
+
"bougainvillea","camellia","mallow","mexican petunia",
|
| 38 |
+
"bromelia","blanket flower","trumpet creeper","blackberry lily"
|
| 39 |
+
]
|
| 40 |
+
|
| 41 |
@st.cache_resource
|
| 42 |
def load_model():
|
| 43 |
return tf.keras.models.load_model(MODEL_PATH)
|
|
|
|
| 51 |
|
| 52 |
if uploaded_file:
|
| 53 |
image = Image.open(uploaded_file).convert("RGB")
|
| 54 |
+
st.image(image, caption="Uploaded Image", use_container_width=True)
|
| 55 |
|
| 56 |
image = image.resize((IMAGE_SIZE, IMAGE_SIZE))
|
| 57 |
img_array = np.array(image) / 255.0
|
|
|
|
| 59 |
|
| 60 |
prediction = model.predict(img_array)
|
| 61 |
predicted_class = np.argmax(prediction)
|
| 62 |
+
confidence = np.max(prediction)
|
| 63 |
+
|
| 64 |
+
flower_name = class_names[predicted_class]
|
| 65 |
|
| 66 |
+
st.success(f"🌼 Prediction: {flower_name}")
|
| 67 |
+
st.info(f"Confidence: {confidence:.2%}")
|