sevvaliclal's picture
Update src/app.py
4aaec89 verified
Raw
History Blame Contribute Delete
2.69 kB
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%}")