MSK34's picture
Update src/streamlit_app.py
2f562c6 verified
Raw
History Blame Contribute Delete
1.57 kB
import streamlit as st
import tensorflow as tf
import numpy as np
from PIL import Image
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import (Conv2D, MaxPooling2D, Flatten, Dense, Dropout, Rescaling)
st.title("Üzüm Hastalığı Sınıflandırma")
# Colab'da eğittiğimiz CNN modelinin aynısını burada tekrar kuruyoruz.
model = Sequential()
model.add(Rescaling(1./255, input_shape=(224, 224, 3)))
model.add(Conv2D(32, (3,3), activation="relu"))
model.add(MaxPooling2D())
model.add(Conv2D(64, (3,3), activation="relu"))
model.add(MaxPooling2D())
model.add(Conv2D(128, (3,3), activation="relu"))
model.add(MaxPooling2D())
model.add(Flatten())
model.add(Dense(128, activation="relu"))
model.add(Dropout(0.3))
model.add(Dense(4, activation="softmax"))
model.load_weights("src/grape_disease.weights.h5")
class_names = ['Black Rot', 'ESCA', 'Healthy', 'Leaf Blight']
uploaded_file = st.file_uploader(
"Bir üzüm yaprağı resmi yükleyin",
type=["jpg", "jpeg", "png"]
)
if uploaded_file is not None:
img = Image.open(uploaded_file).convert("RGB")
st.image(img, caption="Yüklenen Görsel", use_container_width=True)
img = img.resize((224, 224))
img_array = np.array(img)
img_array = np.expand_dims(img_array, axis=0)
prediction = model.predict(img_array)
predicted_class = class_names[np.argmax(prediction)]
confidence = np.max(prediction) * 100
st.subheader("Tahmin Sonucu")
st.write("Sınıf:", predicted_class)
st.write("Güven Oranı:", round(confidence, 2), "%")