ESMATUGBA commited on
Commit
dff9189
·
verified ·
1 Parent(s): 23d4029

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +96 -0
  2. cnn_model.h5 +3 -0
app.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import streamlit as st
3
+ import tensorflow as tf
4
+ from PIL import Image
5
+ import numpy as np
6
+ import os
7
+
8
+ # --- SAYFA AYARLARI / PAGE CONFIG ---
9
+ st.set_page_config(page_title="Fruit & Veg Classifier", layout="wide", page_icon="🍎")
10
+
11
+ # --- MODEL YÜKLEME / LOAD MODEL ---
12
+ @st.cache_resource
13
+ def load_my_model():
14
+ # Model dosya adının 'cnn_model.h5' olduğundan emin olun
15
+ model_path = "cnn_model.h5"
16
+ model = tf.keras.models.load_model(model_path)
17
+ return model
18
+
19
+ try:
20
+ model = load_my_model()
21
+ except Exception as e:
22
+ st.error(f"Model dosyası bulunamadı! / Model file not found!: {e}")
23
+
24
+ # --- SINIF İSİMLERİ / CLASS NAMES ---
25
+ # Veri setindeki klasör sırasına göre burayı güncelleyin
26
+ class_names = [
27
+ 'Apple', 'Banana', 'Beetroot', 'Bell Pepper', 'Cabbage', 'Capsicum',
28
+ 'Carrot', 'Cauliflower', 'Chilli Pepper', 'Corn', 'Cucumber', 'Eggplant',
29
+ 'Garlic', 'Ginger', 'Grapes', 'Jalepeno', 'Kiwi', 'Lemon', 'Lettuce',
30
+ 'Mango', 'Onion', 'Orange', 'Paprika', 'Pear', 'Peas', 'Pineapple',
31
+ 'Pomegranate', 'Potato', 'Raddish', 'Soy Beans', 'Spinach', 'Sweetcorn',
32
+ 'Sweetpotato', 'Tomato', 'Turnip', 'Watermelon'
33
+ ]
34
+
35
+ # --- ARAYÜZ / UI ---
36
+ st.title("🍎 Fruit & Veg Classifier / Meyve ve Sebze Sınıflandırıcı")
37
+ st.write("Identify your produce using Deep Learning / Derin Öğrenme ile ürünlerinizi tanımlayın.")
38
+ st.divider()
39
+
40
+ # Yan Panel / Sidebar
41
+ with st.sidebar:
42
+ st.header("Project Info / Proje Bilgisi")
43
+ st.info("""
44
+ **EN:** This model uses a custom 5-layer CNN architecture trained on fruit and vegetable images.
45
+ \n**TR:** Bu model, meyve ve sebze görüntüleri üzerinde eğitilmiş 5 katmanlı özel bir CNN mimarisi kullanır.
46
+ """)
47
+ st.subheader("Species / Türler")
48
+ st.write(", ".join(class_names))
49
+
50
+ # Ana İçerik / Main Content
51
+ col1, col2 = st.columns([1, 1])
52
+
53
+ with col1:
54
+ st.subheader("Upload / Yükle 📤")
55
+ uploaded_file = st.file_uploader("Choose a photo / Bir fotoğraf seçin...", type=["jpg", "jpeg", "png"])
56
+
57
+ if uploaded_file is not None:
58
+ image = Image.open(uploaded_file)
59
+ st.image(image, caption="Uploaded Image / Yüklenen Resim", use_container_width=True)
60
+
61
+ with col2:
62
+ st.subheader("Result / Sonuç 🔍")
63
+
64
+ if uploaded_file is not None:
65
+ if st.button("Predict / Tahmin Et"):
66
+ with st.spinner("Processing... / İşleniyor..."):
67
+ # Ön İşleme / Preprocessing (Modelin eğitildiği boyuta göre: 128x128)
68
+ img = image.resize((128, 128))
69
+ img_array = np.array(img)
70
+
71
+ # Eğer model 0-1 arası normalizasyon istiyorsa:
72
+ if img_array.max() > 1:
73
+ img_array = img_array.astype('float32') / 255.0
74
+
75
+ img_array = np.expand_dims(img_array, axis=0)
76
+
77
+ # Tahmin / Prediction
78
+ predictions = model.predict(img_array)
79
+ score = np.max(predictions[0]) * 100
80
+ class_idx = np.argmax(predictions[0])
81
+ result = class_names[class_idx]
82
+
83
+ # Sonuç Ekranı / Result Display
84
+ st.success(f"### {result}")
85
+ st.write(f"**Confidence / Güven:** %{score:.2f}")
86
+
87
+ # İlerleme Çubuğu / Progress Bar
88
+ st.progress(int(score))
89
+
90
+ # Kutlama / Celebration
91
+ st.balloons()
92
+ else:
93
+ st.write("Please upload an image to see the result. / Sonucu görmek için lütfen bir resim yükleyin.")
94
+
95
+ st.divider()
96
+ st.caption("Deep Learning Course Project / Derin Öğrenme Kurs Projesi")
cnn_model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d8242d875dc58738e1409ed2f6c071ada5e4a17838966578d4944b62692d92c3
3
+ size 90627560