File size: 3,607 Bytes
75b536e 2051f04 a734cd1 2051f04 a734cd1 2051f04 641932b a734cd1 2051f04 a734cd1 2051f04 a734cd1 2051f04 641932b a734cd1 2051f04 a734cd1 2051f04 a734cd1 2051f04 a734cd1 641932b 2051f04 a734cd1 2051f04 641932b a734cd1 2051f04 641932b 2051f04 a734cd1 2051f04 a734cd1 641932b a734cd1 2051f04 a734cd1 641932b a734cd1 641932b a734cd1 641932b a734cd1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | 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.") |