|
|
import streamlit as st |
|
|
from PIL import Image |
|
|
import numpy as np |
|
|
from tensorflow.keras.models import load_model |
|
|
|
|
|
st.set_page_config(page_title="Sıtma Sınıflandırıcı", page_icon="🦟") |
|
|
|
|
|
st.title("🦟 Sıtma Resmi Sınıflandırma") |
|
|
st.write("Bir mikroskop görüntüsü yükleyin, sıtma olup olmadığını tahmin edelim.") |
|
|
|
|
|
|
|
|
model_path = "src/myn_cnn_model.h5" |
|
|
try: |
|
|
model = load_model(model_path, compile=False) |
|
|
st.success(f"✅ Model yüklendi: `{model_path}`") |
|
|
except Exception as e: |
|
|
st.error(f"❌ Model yüklenemedi: {e}") |
|
|
st.stop() |
|
|
|
|
|
|
|
|
class_names = ["Sıtma", "Sıtma Değil"] |
|
|
|
|
|
|
|
|
file = st.file_uploader("📷 Mikroskop Görüntüsü Seçin", type=["jpg", "jpeg", "png"]) |
|
|
|
|
|
if file: |
|
|
try: |
|
|
image = Image.open(file).convert("RGB") |
|
|
st.image(image, caption="Yüklenen Görsel", use_container_width=True) |
|
|
|
|
|
|
|
|
input_shape = model.input_shape[1:3] |
|
|
st.write(f"Modelin beklediği görsel boyutu: {input_shape}") |
|
|
|
|
|
|
|
|
img = image.resize(input_shape) |
|
|
img = np.array(img) |
|
|
|
|
|
if img.shape != (*input_shape, 3): |
|
|
st.error(f"Görsel boyutu beklenmeyen formatta: {img.shape}") |
|
|
st.stop() |
|
|
|
|
|
img = img / 255.0 |
|
|
img = np.expand_dims(img, axis=0) |
|
|
|
|
|
|
|
|
prediction = model.predict(img) |
|
|
|
|
|
|
|
|
if prediction.shape[-1] == 1: |
|
|
predicted_class = int(prediction[0][0] > 0.5) |
|
|
st.success(f"🧪 Tahmin: **{class_names[predicted_class]}**") |
|
|
st.write(f"Sıtma olasılığı: {prediction[0][0]:.4f}") |
|
|
elif prediction.shape[-1] == 2: |
|
|
predicted_class = int(np.argmax(prediction)) |
|
|
st.success(f"🧪 Tahmin: **{class_names[predicted_class]}**") |
|
|
st.subheader("📈 Sınıf Skorları:") |
|
|
for i, score in enumerate(prediction[0]): |
|
|
st.write(f"{class_names[i]}: {score:.4f}") |
|
|
else: |
|
|
st.error("⚠️ Model çıktısı beklenmeyen formatta.") |
|
|
st.stop() |
|
|
|
|
|
except Exception as e: |
|
|
st.error(f"🚫 Görsel işleme veya tahmin hatası: {e}") |
|
|
|