import streamlit as st import tensorflow as tf import numpy as np from PIL import Image import os # 1. SAYFA AYARLARI st.set_page_config(page_title="Meyve & Sebze Tanıma", page_icon="🍎") # 2. MODELİ YÜKLE (Senin klasöründeki gerçek dosya adıyla güncellendi) @st.cache_resource def load_my_model(): # ls çıktısında gördüğümüz gerçek isim budur: model_adi = 'meyve_sebze_resnet50_lstm.keras' # Çalışma dizinini kontrol et ve dosyayı bul if not os.path.exists(model_adi): st.error(f"HATA: '{model_adi}' dosyası bulunamadı! Lütfen dosya adının doğru olduğundan emin olun.") return None return tf.keras.models.load_model(model_adi) model = load_my_model() # 3. SINIF LİSTESİ classes = [ 'apple', 'banana', 'beetroot', 'bell pepper', 'cabbage', 'capsicum', 'carrot', 'cauliflower', 'chilli pepper', 'corn', 'cucumber', 'eggplant', 'garlic', 'ginger', 'grapes', 'jalepeno', 'kiwi', 'lemon', 'lettuce', 'mango', 'onion', 'orange', 'paprika', 'pear', 'peas', 'pineapple', 'pomegranate', 'potato', 'raddish', 'soy beans', 'spinach', 'sweetcorn', 'sweetpotato', 'tomato', 'turnip', 'watermelon' ] # 4. ARAYÜZ st.title("🍎 Fruit and Vegetable Recognition System") st.write("ResNet50 + LSTM Model Test Panel") st.markdown("---") uploaded_file = st.file_uploader("Upload a fruit or vegetable image...", type=["jpg", "jpeg", "png"]) if uploaded_file is not None and model is not None: image = Image.open(uploaded_file) st.image(image, caption='Yüklenen Resim', use_container_width=True) if st.button("ŞİMDİ TAHMİN ET"): with st.spinner('Analiz ediliyor...'): img = image.convert('RGB').resize((170, 170)) img_array = np.array(img).astype('float32') / 255.0 # Normalizasyon img_array = np.expand_dims(img_array, axis=0) predictions = model.predict(img_array) result_index = np.argmax(predictions) st.success(f"### Tahmin: {classes[result_index].upper()}") st.info(f"Güven Oranı: %{np.max(predictions)*100:.2f}") st.markdown("---") st.caption("Developer: Elif Ş. Besiktepe")