Update src/streamlit_app.py
Browse files- src/streamlit_app.py +21 -100
src/streamlit_app.py
CHANGED
|
@@ -1,103 +1,24 @@
|
|
| 1 |
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
model = tf.keras.models.load_model(model_path)
|
| 19 |
-
return model
|
| 20 |
-
|
| 21 |
-
model = load_my_model()
|
| 22 |
-
|
| 23 |
-
# --- SINIF İSİMLERİ (İngilizce - Türkçe) / CLASS NAMES ---
|
| 24 |
-
# Veri setindeki orijinal (klasör) isimleri solda, Türkçe karşılıkları sağdadır
|
| 25 |
-
class_translations = {
|
| 26 |
-
'Apple': 'Elma', 'Banana': 'Muz', 'Beetroot': 'Pancar', 'Bell Pepper': 'Dolmalık Biber',
|
| 27 |
-
'Cabbage': 'Lahana', 'Capsicum': 'Yeşil Biber', 'Carrot': 'Havuç', 'Cauliflower': 'Karnabahar',
|
| 28 |
-
'Chilli Pepper': 'Acı Biber', 'Corn': 'Mısır', 'Cucumber': 'Salatalık', 'Eggplant': 'Patlıcan',
|
| 29 |
-
'Garlic': 'Sarımsak', 'Ginger': 'Zencefil', 'Grapes': 'Üzüm', 'Jalepeno': 'Jalapeno Biberi',
|
| 30 |
-
'Kiwi': 'Kivi', 'Lemon': 'Limon', 'Lettuce': 'Marul', 'Mango': 'Mango',
|
| 31 |
-
'Onion': 'Soğan', 'Orange': 'Portakal', 'Paprika': 'Kırmızı Toz Biber', 'Pear': 'Armut',
|
| 32 |
-
'Peas': 'Bezelye', 'Pineapple': 'Ananas', 'Pomegranate': 'Nar', 'Potato': 'Patates',
|
| 33 |
-
'Raddish': 'Turp', 'Soy Beans': 'Soya Fasulyesi', 'Spinach': 'Ispanak', 'Sweetcorn': 'Tatlı Mısır',
|
| 34 |
-
'Sweetpotato': 'Tatlı Patates', 'Tomato': 'Domates', 'Turnip': 'Şalgam', 'Watermelon': 'Karpuz'
|
| 35 |
-
}
|
| 36 |
-
|
| 37 |
-
# Orijinal klasör isimleri listesi (Tahmin için)
|
| 38 |
-
class_names = list(class_translations.keys())
|
| 39 |
-
|
| 40 |
-
# --- ARAYÜZ / UI ---
|
| 41 |
-
st.title("🍎 Fruit & Veg Classifier / Meyve ve Sebze Sınıflandırıcı")
|
| 42 |
-
st.write("Identify your produce / Ürünlerinizi tanımlayın.")
|
| 43 |
-
st.divider()
|
| 44 |
-
|
| 45 |
-
# --- YAN PANEL / SIDEBAR (Türkçe İsimler Eklendi) ---
|
| 46 |
-
with st.sidebar:
|
| 47 |
-
st.header("Project Info / Proje Bilgisi")
|
| 48 |
-
st.info("Custom 5-Layer CNN / Özel 5 Katmanlı CNN")
|
| 49 |
-
|
| 50 |
-
st.subheader("Species List / Tür Listesi")
|
| 51 |
-
# Türleri yan yana İngilizce / Türkçe olarak listeler
|
| 52 |
-
for eng, tr in class_translations.items():
|
| 53 |
-
st.write(f"• {eng} / {tr}")
|
| 54 |
-
|
| 55 |
-
# --- ANA İÇERİK / MAIN CONTENT ---
|
| 56 |
-
if model is None:
|
| 57 |
-
st.error("Model file 'cnn_model.h5' not found! / 'cnn_model.h5' dosyası bulunamadı!")
|
| 58 |
-
else:
|
| 59 |
-
col1, col2 = st.columns([1, 1])
|
| 60 |
-
|
| 61 |
-
with col1:
|
| 62 |
-
st.subheader("Upload / Yükle 📤")
|
| 63 |
-
uploaded_file = st.file_uploader("Choose a photo / Fotoğraf seçin...", type=["jpg", "jpeg", "png"])
|
| 64 |
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
with col2:
|
| 70 |
-
st.subheader("Result / Sonuç 🔍")
|
| 71 |
|
| 72 |
-
|
| 73 |
-
# Butona basıldığında titreme yapmaması için tüm işlemler bu bloğun içinde kalmalı
|
| 74 |
-
if st.button("Predict / Tahmin Et"):
|
| 75 |
-
with st.spinner("Processing... / İşleniyor..."):
|
| 76 |
-
# Görüntü İşleme
|
| 77 |
-
img = image.resize((128, 128))
|
| 78 |
-
img_array = np.array(img).astype('float32')
|
| 79 |
-
|
| 80 |
-
# Normalizasyon
|
| 81 |
-
if img_array.max() > 1:
|
| 82 |
-
img_array /= 255.0
|
| 83 |
-
|
| 84 |
-
img_array = np.expand_dims(img_array, axis=0)
|
| 85 |
-
|
| 86 |
-
# Tahmin
|
| 87 |
-
predictions = model.predict(img_array, verbose=0)
|
| 88 |
-
score = np.max(predictions[0]) * 100
|
| 89 |
-
class_idx = np.argmax(predictions[0])
|
| 90 |
-
|
| 91 |
-
eng_res = class_names[class_idx]
|
| 92 |
-
tr_res = class_translations[eng_res]
|
| 93 |
-
|
| 94 |
-
# Sonuç Ekranı
|
| 95 |
-
st.success(f"### Result / Sonuç: {eng_res} / {tr_res}")
|
| 96 |
-
st.write(f"**Confidence / Güven:** %{score:.2f}")
|
| 97 |
-
st.progress(int(score))
|
| 98 |
-
st.balloons()
|
| 99 |
-
else:
|
| 100 |
-
st.info("Waiting for image... / Resim bekleniyor...")
|
| 101 |
-
|
| 102 |
-
st.divider()
|
| 103 |
-
st.caption("Deep Learning Course Project / Derin Öğrenme Kurs Projesi")
|
|
|
|
| 1 |
|
| 2 |
+
# app.py içindeki liste Notebook'taki çıktı ile AYNI sırada olmalı
|
| 3 |
+
class_names = [
|
| 4 |
+
'apple', 'banana', 'beetroot', 'bell pepper', 'cabbage', 'capsicum',
|
| 5 |
+
'carrot', 'cauliflower', 'chilli pepper', 'corn', 'cucumber', 'eggplant',
|
| 6 |
+
'garlic', 'ginger', 'grapes', 'jalepeno', 'kiwi', 'lemon', 'lettuce',
|
| 7 |
+
'mango', 'onion', 'orange', 'paprika', 'pear', 'peas', 'pineapple',
|
| 8 |
+
'pomegranate', 'potato', 'raddish', 'soy beans', 'spinach', 'sweetcorn',
|
| 9 |
+
'sweetpotato', 'tomato', 'turnip', 'watermelon'
|
| 10 |
+
]
|
| 11 |
+
|
| 12 |
+
# Tahmin kısmında 'titreme' ve 'yanlış sonuç' engelleme:
|
| 13 |
+
if st.button("Predict / Tahmin Et"):
|
| 14 |
+
with st.spinner("Analyzing..."):
|
| 15 |
+
img = image.resize((128, 128))
|
| 16 |
+
img_array = np.array(img).astype('float32') / 255.0 # <--- UNUTMA!
|
| 17 |
+
img_array = np.expand_dims(img_array, axis=0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
+
preds = model.predict(img_array)
|
| 20 |
+
# Notebook'ta test ederken aldığın sonucun aynısını buraya yansıtır
|
| 21 |
+
class_idx = np.argmax(preds[0])
|
| 22 |
+
result = class_names[class_idx]
|
|
|
|
|
|
|
| 23 |
|
| 24 |
+
st.success(f"Result: {result}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|