Grape-Leaf-Disease-Detection / src /streamlit_app.py
ESMATUGBA's picture
Update src/streamlit_app.py
a734cd1 verified
Raw
History Blame Contribute Delete
3.61 kB
import streamlit as st
import numpy as np
from PIL import Image
import tensorflow as tf
# Sayfa Genişliği ve Sekme Ayarı
st.set_page_config(page_title="Grape Disease Detection", layout="wide")
# -----------------------------
# MODEL YÜKLEME (Hız için Cache)
# -----------------------------
@st.cache_resource
def load_my_model():
return tf.keras.models.load_model("grape_disease_model.h5")
model = load_my_model()
class_names = ['Black Rot', 'ESCA', 'Healthy', 'Leaf Blight']
# -----------------------------
# SOL PANEL (SIDEBAR) - BİLGİLENDİRME
# -----------------------------
with st.sidebar:
st.header("📌 Hastalık Bilgileri / Info")
st.markdown("### 1. Black Rot")
st.caption("🇹🇷 Kara Leke/Çürüklük: Mantar kaynaklı bir hastalık.")
st.caption("🇺🇸 Fungal disease causing dark spots.")
st.markdown("### 2. ESCA")
st.caption("🇹🇷 Gövde Kanseri: Bağlarda görülen karmaşık bir mantar hastalığı.")
st.caption("🇺🇸 Complex fungal disease affecting the vines.")
st.markdown("### 3. Healthy")
st.caption("🇹🇷 Sağlıklı: Yaprağın herhangi bir hastalık taşımadığını ifade eder.")
st.caption("🇺🇸 Indicates the leaf is free from disease.")
st.markdown("### 4. Leaf Blight")
st.caption("🇹🇷 Yaprak Yanıklığı: Yapraklarda kurumaya ve lekelere neden olur.")
st.caption("🇺🇸 Causes browning and spotting on leaves.")
st.divider()
st.write("Academic Project - 2026")
# -----------------------------
# ANA BAŞLIKLAR (ÇİFT DİLLİ)
# -----------------------------
st.title("🍇 Üzüm Yaprağı Hastalık Tespiti")
st.subheader("Grape Leaf Disease Detection")
st.markdown("---")
# İki Sütunlu Düzen
col1, col2 = st.columns([1, 1])
with col1:
st.markdown("### 📷 Fotoğraf Yükle / Upload Image")
# Titremeyi önlemek için label dolu tutuldu
uploaded_file = st.file_uploader("Bir yaprak fotoğrafı seçin / Select a leaf image", type=["jpg", "png", "jpeg"])
if uploaded_file is not None:
image = Image.open(uploaded_file).convert("RGB")
with col1:
st.image(image, caption="Yüklenen Resim / Uploaded Image", use_container_width=True)
# --- TAHMİN AŞAMASI ---
with col2:
st.markdown("### 🔍 Analiz Sonucu / Analysis Result")
with st.spinner('Analiz ediliyor / Analyzing...'):
# Görüntü Ön İşleme
img_resized = image.resize((170, 170))
img_array = np.array(img_resized) / 255.0
img_array = np.expand_dims(img_array, axis=0)
# Tahmin
prediction = model.predict(img_array)
class_index = np.argmax(prediction)
confidence = np.max(prediction) * 100
# SONUÇ GÖSTERİMİ
st.success(f"**Tahmin / Prediction:** {class_names[class_index]}")
st.metric(label="Güven Oranı / Confidence", value=f"%{confidence:.2f}")
st.progress(int(confidence))
# --- BALON EFEKTİ ---
# Eğer model sağlıklı bulursa veya yüksek güvenle bilirse balon çıkar
if confidence > 50:
st.balloons()
st.toast(f"Tahmin Başarılı: {class_names[class_index]}", icon='🎉')
# Bilgi Notu
st.info("""
**TR:** Bu sistem yapay zeka kullanarak analiz yapmaktadır.
**EN:** This system uses AI for leaf analysis.
""")
else:
with col2:
st.write("👈 Lütfen analiz için bir fotoğraf yükleyin.")
st.write("👈 Please upload a photo for analysis.")