File size: 2,685 Bytes
8fff386
2f6175f
5d11e00
2f6175f
8fff386
5d11e00
 
 
4aaec89
 
4a60449
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4aaec89
4a60449
5d11e00
 
 
8fff386
5d11e00
68eddc7
5d11e00
8fff386
4aaec89
2f6175f
5d11e00
 
4aaec89
2f6175f
5d11e00
4aaec89
2f6175f
 
 
4aaec89
 
4a60449
4aaec89
 
 
2f6175f
4a60449
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import streamlit as st
import tensorflow as tf
import numpy as np
from PIL import Image

MODEL_PATH = "src/flower_model.keras"
IMAGE_SIZE = 224

# DOĞRU 104 class sırası
class_names = sorted([
    "pink primrose","hard-leaved pocket orchid","canterbury bells",
    "sweet pea","english marigold","tiger lily","moon orchid",
    "bird of paradise","monkshood","globe thistle",
    "snapdragon","colt's foot","king protea","spear thistle",
    "yellow iris","globe-flower","purple coneflower",
    "peruvian lily","balloon flower","giant white arum lily",
    "fire lily","pincushion flower","fritillary","red ginger",
    "grape hyacinth","corn poppy","prince of wales feathers",
    "stemless gentian","artichoke","sweet william",
    "carnation","garden phlox","love in the mist","mexican aster",
    "alpine sea holly","ruby-lipped cattleya","cape flower",
    "great masterwort","siam tulip","lenten rose",
    "barbeton daisy","daffodil","sword lily","poinsettia",
    "bolero deep blue","wallflower","marigold","buttercup",
    "oxeye daisy","common dandelion","petunia","wild pansy",
    "primula","sunflower","pelargonium","bishop of llandaff",
    "gaura","geranium","orange dahlia","pink-yellow dahlia",
    "cautleya spicata","japanese anemone","black-eyed susan",
    "silverbush","californian poppy","osteospermum",
    "spring crocus","iris","windflower","tree poppy",
    "gazania","azalea","water lily","rose",
    "thorn apple","morning glory","passion flower","lotus",
    "toad lily","anthurium","frangipani","clematis",
    "hibiscus","columbine","desert-rose","tree mallow",
    "magnolia","cyclamen","watercress","canna lily",
    "hippeastrum","bee balm","ball moss","foxglove",
    "bougainvillea","camellia","mallow","mexican petunia",
    "bromelia","blanket flower","trumpet creeper","blackberry lily"
])

@st.cache_resource
def load_model():
    return tf.keras.models.load_model(MODEL_PATH)

model = load_model()

st.title("🌸 Flower Classifier")

uploaded_file = st.file_uploader("Upload an image", type=["jpg","jpeg","png"])

if uploaded_file:
    image = Image.open(uploaded_file).convert("RGB")
    st.image(image, use_container_width=True)

    image = image.resize((IMAGE_SIZE, IMAGE_SIZE))
    img_array = np.array(image) / 255.0   # Eğitimde bunu kullanmıştık
    img_array = np.expand_dims(img_array, axis=0)

    prediction = model.predict(img_array)
    predicted_index = int(np.argmax(prediction))
    confidence = float(np.max(prediction))

    st.write("Predicted index:", predicted_index)

    flower_name = class_names[predicted_index]

    st.success(f"🌼 Prediction: {flower_name}")
    st.info(f"Confidence: {confidence:.2%}")