| import streamlit as st |
| import tensorflow as tf |
| from tensorflow.keras.applications import VGG16 |
| from tensorflow.keras.models import Sequential |
| from tensorflow.keras.layers import Dense, GlobalAveragePooling2D, Dropout |
| from PIL import Image |
| import numpy as np |
| import os |
|
|
| |
| st.set_page_config(page_title="Bird Identifier / Kuş Tanımlayıcı", layout="wide", page_icon="🐦") |
|
|
| |
| @st.cache_resource |
| def load_bird_model(): |
| |
| current_dir = os.path.dirname(os.path.abspath(__file__)) |
| weights_path = os.path.join(current_dir, "bird_weights.weights.h5") |
| |
| |
| base_model = VGG16(weights=None, include_top=False, input_shape=(128, 128, 3)) |
| model = Sequential([ |
| base_model, |
| GlobalAveragePooling2D(), |
| Dense(256, activation='relu'), |
| Dropout(0.6), |
| Dense(25, activation='softmax') |
| ]) |
| |
| |
| if os.path.exists(weights_path): |
| model.load_weights(weights_path) |
| else: |
| |
| model.load_weights("bird_weights.weights.h5") |
| |
| return model |
|
|
| |
| try: |
| model = load_bird_model() |
| except Exception as e: |
| st.error(f"Model yüklenirken bir hata oluştu / Error loading model: {e}") |
|
|
| |
| class_names = [ |
| 'Alexandrine Parakeet', 'Asian Green Bee-Eater', 'Baya Weaver', 'Black Drongo', |
| 'Black-Crowned Night Heron', 'Blue-Throated Barbet', 'Brown-Headed Barbet', |
| 'Cattle Egret', 'Common Kingfisher', 'Common Myna', 'Common Rosefinch', |
| 'Common Tailorbird', 'Coppersmith Barbet', 'Grey Heron', 'Hoopoe', |
| 'Indian Peafowl', 'Indian Roller', 'Indian Silverbill', 'Jungle Babbler', |
| 'Little Egret', 'Pied Kingfisher', 'Purple Sunbird', 'Red-Wattled Lapwing', |
| 'Slaty-Headed Parakeet', 'White-Throated Kingfisher' |
| ] |
|
|
| |
| with st.sidebar: |
| st.title("Settings / Ayarlar ⚙️") |
| st.divider() |
| st.subheader("Recognized Species / Tanınan Türler 🐦") |
| for name in sorted(class_names): |
| st.write(f"• {name}") |
|
|
| |
| st.title("Bird Species Classifier / Kuş Türü Sınıflandırıcı 🐦") |
| st.write("Identify 25 Indian bird species / 25 farklı Hint kuş türünü tanımlayın.") |
| st.divider() |
|
|
| col1, col2 = st.columns([1, 1]) |
|
|
| with col1: |
| st.subheader("Upload Image / Resim Yükle 📤") |
| uploaded_file = st.file_uploader("Choose a bird photo / Bir kuş fotoğrafı seçin...", type=["jpg", "jpeg", "png"]) |
| |
| if uploaded_file is not None: |
| image = Image.open(uploaded_file) |
| st.image(image, caption="Uploaded Image / Yüklenen Resim", use_container_width=True) |
|
|
| with col2: |
| st.subheader("Analysis Results / Analiz Sonuçları 🔍") |
| |
| if uploaded_file is not None: |
| |
| if st.button("Predict / Tahmin Et"): |
| with st.spinner("Analyzing... / Analiz ediliyor..."): |
| |
| img = image.resize((128, 128)) |
| img_array = np.array(img).astype('float32') / 255.0 |
| img_array = np.expand_dims(img_array, axis=0) |
| |
| |
| preds = model.predict(img_array) |
| class_idx = np.argmax(preds[0]) |
| confidence = np.max(preds[0]) * 100 |
| |
| |
| st.success(f"**Result / Sonuç:** {class_names[class_idx]}") |
| st.write(f"**Confidence / Güven:** %{confidence:.2f}") |
| st.progress(int(confidence)) |
| |
| |
| st.balloons() |
| else: |
| st.info("Waiting for an image to analyze... / Analiz için resim bekleniyor...") |
|
|
| st.divider() |
| st.caption("Developed with TensorFlow & Streamlit | Indian Bird Dataset Project") |