ESMATUGBA commited on
Commit
9312184
·
verified ·
1 Parent(s): 641932b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +97 -90
app.py CHANGED
@@ -1,90 +1,97 @@
1
- import streamlit as st
2
- import numpy as np
3
- from PIL import Image
4
- import tensorflow as tf
5
-
6
- # Sayfa Genişliği Ayarı
7
- st.set_page_config(page_title="Grape Disease Detection", layout="wide")
8
-
9
- # -----------------------------
10
- # MODEL YÜKLEME
11
- # -----------------------------
12
- @st.cache_resource # Modelin her seferinde tekrar yüklenmesini engeller, hızı artırır
13
- def load_my_model():
14
- return tf.keras.models.load_model("grape_disease_model.h5")
15
-
16
- model = load_my_model()
17
-
18
- # Sınıf İsimleri
19
- class_names = ['Black Rot', 'ESCA', 'Healthy', 'Leaf Blight']
20
-
21
- # -----------------------------
22
- # SOL PANEL (SIDEBAR) - BİLGİLENDİRME
23
- # -----------------------------
24
- with st.sidebar:
25
- st.header("Hastalık Bilgileri / Disease Info")
26
-
27
- st.markdown("""
28
- **1. Black Rot (Kara Leke/Çürüklük):** - 🇹🇷 Mantar kaynaklı bir hastalık.
29
- - 🇺🇸 A fungal disease caused by Guignardia bidwellii.
30
-
31
- ---
32
- **2. ESCA (Gövde Kanseri):** - 🇹🇷 Bağlarda görülen karmaşık bir mantar hastalığı.
33
- - 🇺🇸 A complex fungal disease affecting the trunk and leaves.
34
-
35
- ---
36
- **3. Healthy (Sağlıklı):** - 🇹🇷 Yaprağın herhangi bir hastalık taşımadığını ifade eder.
37
- - 🇺🇸 Indicates that the leaf is healthy and disease-free.
38
-
39
- ---
40
- **4. Leaf Blight (Yaprak Yanıklığı):** - 🇹🇷 Yapraklarda kurumaya ve lekelere neden olan bir hastalık türü.
41
- - 🇺🇸 A disease causing browning and spotting on leaves.
42
- """)
43
-
44
- # -----------------------------
45
- # ANA BAŞLIKLAR (ÇİFT DİLLİ)
46
- # -----------------------------
47
- st.title("🍇 Üzüm Yaprağı Hastalık Tespiti")
48
- st.subheader("Grape Leaf Disease Detection")
49
- st.write("---")
50
-
51
- # Sayfayı iki sütuna bölelim: Sol taraf yükleme, Sağ taraf sonuç
52
- col1, col2 = st.columns(2)
53
-
54
- with col1:
55
- st.markdown("### 📷 Fotoğraf Yükle / Upload Image")
56
- uploaded_file = st.file_uploader("", type=["jpg", "png", "jpeg"])
57
-
58
- if uploaded_file is not None:
59
- image = Image.open(uploaded_file).convert("RGB")
60
- st.image(image, caption="Yüklenen Resim / Uploaded Image", use_container_width=True)
61
-
62
- # Ön İşleme (Preprocess)
63
- img = image.resize((170, 170))
64
- img = np.array(img) / 255.0
65
- img = np.expand_dims(img, axis=0)
66
-
67
- # Tahmin (Prediction)
68
- with st.spinner('Teşhis konuluyor / Diagnosing...'):
69
- pred = model.predict(img)
70
- class_index = np.argmax(pred)
71
- confidence = np.max(pred) * 100
72
-
73
- with col2:
74
- st.markdown("### 🔍 Analiz Sonucu / Analysis Result")
75
-
76
- # Sonuç Kutusu (Görselleştirme)
77
- st.success(f"**Tahmin / Prediction:** {class_names[class_index]}")
78
-
79
- # Güven Skoru Göstergesi
80
- st.metric(label="Güven Oranı / Confidence", value=f"%{confidence:.2f}")
81
-
82
- # İlerleme Çubuğu (Progress Bar)
83
- st.progress(int(confidence))
84
-
85
- # Bilgi Notu
86
- st.info("""
87
- **TR:** Bu sistem yapay zeka kullanarak analiz yapmaktadır. Kesin teşhis için uzman görüşü alınız.
88
-
89
- **EN:** This system uses AI for analysis. Please consult an expert for definitive diagnosis.
90
- """)
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import numpy as np
3
+ from PIL import Image
4
+ import tensorflow as tf
5
+ import cv2
6
+
7
+ # Sayfa ayarları - Titremeyi ve düzen bozukluğunu önlemek için
8
+ st.set_page_config(
9
+ page_title="Grape Disease Detector",
10
+ page_icon="🍇",
11
+ layout="wide",
12
+ initial_sidebar_state="expanded"
13
+ )
14
+
15
+ # -----------------------------
16
+ # MODELİ YÜKLE (Cache kullanarak hızı artırıyoruz)
17
+ # -----------------------------
18
+ @st.cache_resource
19
+ def load_model():
20
+ model = tf.keras.models.load_model("grape_disease_model.h5")
21
+ return model
22
+
23
+ model = load_model()
24
+
25
+ # Sınıf isimleri - Datasetindeki klasör sırasına göre
26
+ class_names = ['Black Rot', 'ESCA', 'Healthy', 'Leaf Blight']
27
+
28
+ # -----------------------------
29
+ # SOL PANEL (SIDEBAR) - BİLGİLENDİRME
30
+ # -----------------------------
31
+ with st.sidebar:
32
+ st.title("🌿 Bilgi Paneli / Info")
33
+ st.info("Hastalık Detayları / Disease Details")
34
+
35
+ st.markdown("""
36
+ - **Black Rot:** Kara Leke/Çürüklük (Mantar)
37
+ - **ESCA:** Gövde Kanseri (Mantar)
38
+ - **Healthy:** Sağlıklı Yaprak
39
+ - **Leaf Blight:** Yaprak Yanıklığı
40
+ """)
41
+ st.divider()
42
+ st.write("Geliştirici: Deep Learning Project")
43
+
44
+ # -----------------------------
45
+ # ANA SAYFA ARAYÜZÜ
46
+ # -----------------------------
47
+ st.title("🍇 Üzüm Yaprağı Hastalık Teşhis Sistemi")
48
+ st.write("Sistem, yüklediğiniz yaprak fotoğraflarını yapay zeka ile analiz eder.")
49
+
50
+ # İki sütunlu yapı
51
+ col1, col2 = st.columns([1, 1])
52
+
53
+ with col1:
54
+ st.subheader("📷 Fotoğraf Yükle / Upload")
55
+ # Label kısmına bir metin ekledik ve boş bırakmadık (Titremeyi önleyen ana yer)
56
+ uploaded_file = st.file_uploader("Bir yaprak resmi seçiniz...", type=["jpg", "png", "jpeg"])
57
+
58
+ if uploaded_file is not None:
59
+ # Resmi aç ve göster
60
+ image = Image.open(uploaded_file).convert("RGB")
61
+
62
+ with col1:
63
+ # Yeni versiyona uygun resim gösterme
64
+ st.image(image, caption="Yüklenen Resim", use_container_width=True)
65
+
66
+ # --- TAHMİN AŞAMASI ---
67
+ with col2:
68
+ st.subheader("🔍 Analiz Sonucu / Result")
69
+
70
+ with st.spinner('Yapay zeka analiz ediyor...'):
71
+ # Görüntü İşleme
72
+ img_resized = image.resize((170, 170))
73
+ img_array = np.array(img_resized) / 255.0
74
+ img_array = np.expand_dims(img_array, axis=0)
75
+
76
+ # Tahmin
77
+ prediction = model.predict(img_array)
78
+ class_index = np.argmax(prediction)
79
+ confidence = np.max(prediction) * 100
80
+
81
+ # Sonuçları ekrana bas
82
+ st.success(f"**Tahmin:** {class_names[class_index]}")
83
+ st.metric(label="Güven Oranı (Confidence)", value=f"%{confidence:.2f}")
84
+
85
+ # İlerleme çubuğu
86
+ st.progress(int(confidence))
87
+
88
+ # Tavsiye mesajı
89
+ if class_names[class_index] == 'Healthy':
90
+ st.balloons()
91
+ st.write("✅ Yaprak sağlıklı görünüyor.")
92
+ else:
93
+ st.warning("⚠️ Hastalık tespit edildi. İlgili bölgeyi kontrol etmeniz önerilir.")
94
+
95
+ else:
96
+ with col2:
97
+ st.info("Lütfen sol taraftan bir fotoğraf yükleyin.")