Update src/streamlit_app.py
Browse files- src/streamlit_app.py +47 -6
src/streamlit_app.py
CHANGED
|
@@ -3,20 +3,61 @@ from PIL import Image
|
|
| 3 |
import numpy as np
|
| 4 |
from tensorflow.keras.models import load_model
|
| 5 |
|
| 6 |
-
# 🔧 CONFIG PANELİ
|
| 7 |
st.set_page_config(page_title="Sıtma Sınıflandırıcı", page_icon="🦟")
|
| 8 |
|
| 9 |
-
st.sidebar.title("⚙️ Ayarlar")
|
| 10 |
-
model_path = st.sidebar.text_input("Model Dosyası Yolu", value="src/myn_cnn_model.h5")
|
| 11 |
-
image_size = st.sidebar.slider("Görsel Boyutu (px)", min_value=32, max_value=256, value=64, step=16)
|
| 12 |
-
|
| 13 |
st.title("🦟 Sıtma Resmi Sınıflandırma")
|
| 14 |
st.write("Bir mikroskop görüntüsü yükleyin, sıtma olup olmadığını tahmin edelim.")
|
| 15 |
|
| 16 |
# MODELİ YÜKLE (compile=False kritik!)
|
| 17 |
try:
|
| 18 |
-
model = load_model(
|
| 19 |
st.success("✅ Model başarıyla yüklendi.")
|
| 20 |
except Exception as e:
|
| 21 |
st.error(f"❌ Model yüklenemedi: {e}")
|
| 22 |
st.stop()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
import numpy as np
|
| 4 |
from tensorflow.keras.models import load_model
|
| 5 |
|
|
|
|
| 6 |
st.set_page_config(page_title="Sıtma Sınıflandırıcı", page_icon="🦟")
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
st.title("🦟 Sıtma Resmi Sınıflandırma")
|
| 9 |
st.write("Bir mikroskop görüntüsü yükleyin, sıtma olup olmadığını tahmin edelim.")
|
| 10 |
|
| 11 |
# MODELİ YÜKLE (compile=False kritik!)
|
| 12 |
try:
|
| 13 |
+
model = load_model("src/myn_cnn_model.h5", compile=False)
|
| 14 |
st.success("✅ Model başarıyla yüklendi.")
|
| 15 |
except Exception as e:
|
| 16 |
st.error(f"❌ Model yüklenemedi: {e}")
|
| 17 |
st.stop()
|
| 18 |
+
|
| 19 |
+
# SINIFLAR
|
| 20 |
+
class_names = ["Sıtma Değil", "Sıtma"]
|
| 21 |
+
|
| 22 |
+
# GÖRSEL SEÇİCİ
|
| 23 |
+
file = st.file_uploader("📷 Mikroskop Görüntüsü Seçin", type=["jpg", "jpeg", "png"])
|
| 24 |
+
|
| 25 |
+
# TAHMİN İŞLEMİ
|
| 26 |
+
if file:
|
| 27 |
+
try:
|
| 28 |
+
image = Image.open(file).convert("RGB")
|
| 29 |
+
st.image(image, caption="Yüklenen Resim", use_container_width=True)
|
| 30 |
+
|
| 31 |
+
img = image.resize((170, 170))
|
| 32 |
+
img = np.array(img) / 255.0
|
| 33 |
+
img = np.expand_dims(img, axis=0)
|
| 34 |
+
|
| 35 |
+
# 📌 TAHMİN
|
| 36 |
+
prediction = model.predict(img)
|
| 37 |
+
|
| 38 |
+
# RAW ÇIKTIYI GÖSTER (debug için)
|
| 39 |
+
st.write("📊 Model çıktısı (şekil):", prediction.shape)
|
| 40 |
+
st.write("📊 Model çıktısı (değer):", prediction.tolist())
|
| 41 |
+
|
| 42 |
+
# SHAPE KONTROLÜ VE YORUMLAMA
|
| 43 |
+
if prediction.shape[-1] == 1:
|
| 44 |
+
predicted_class = int(prediction[0][0] > 0.5)
|
| 45 |
+
elif prediction.shape[-1] == 2:
|
| 46 |
+
predicted_class = int(np.argmax(prediction))
|
| 47 |
+
else:
|
| 48 |
+
st.error("⚠️ Model çıktısı beklenmeyen formatta.")
|
| 49 |
+
st.stop()
|
| 50 |
+
|
| 51 |
+
# SONUCU GÖSTER
|
| 52 |
+
st.success(f"🧪 Tahmin: **{class_names[predicted_class]}**")
|
| 53 |
+
|
| 54 |
+
# SKORLARI GÖSTER
|
| 55 |
+
st.subheader("📈 Sınıf Skorları:")
|
| 56 |
+
for i, score in enumerate(prediction[0]):
|
| 57 |
+
if i < len(class_names):
|
| 58 |
+
st.write(f"{class_names[i]}: {score:.4f}")
|
| 59 |
+
else:
|
| 60 |
+
st.write(f"Sınıf {i}: {score:.4f}")
|
| 61 |
+
|
| 62 |
+
except Exception as e:
|
| 63 |
+
st.error(f"🚫 Görsel işleme hatası: {e}")
|