HarunDemircioglu11 commited on
Commit
80cbd93
·
verified ·
1 Parent(s): 8ec26eb

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +19 -15
src/streamlit_app.py CHANGED
@@ -3,43 +3,47 @@ from PIL import Image
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:
@@ -48,10 +52,10 @@ if file:
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):
 
3
  import numpy as np
4
  from tensorflow.keras.models import load_model
5
 
6
+ # 🌟 Sayfa ayarları
7
  st.set_page_config(page_title="Sıtma Sınıflandırıcı", page_icon="🦟")
8
 
9
+ # 🧪 Başlık
10
  st.title("🦟 Sıtma Resmi Sınıflandırma")
11
  st.write("Bir mikroskop görüntüsü yükleyin, sıtma olup olmadığını tahmin edelim.")
12
 
13
+ # 🔍 MODELİ YÜKLE
14
+ model_path = "src/myn_cnn_model.h5"
15
  try:
16
+ model = load_model(model_path, compile=False)
17
+ st.success(f"✅ Model yüklendi: `{model_path}`")
18
  except Exception as e:
19
  st.error(f"❌ Model yüklenemedi: {e}")
20
  st.stop()
21
 
22
+ # 🏷️ Sınıf adları
23
  class_names = ["Sıtma Değil", "Sıtma"]
24
 
25
+ # 📂 Dosya yükleyici
26
  file = st.file_uploader("📷 Mikroskop Görüntüsü Seçin", type=["jpg", "jpeg", "png"])
27
 
28
+ # 🔮 Tahmin işlemi
29
  if file:
30
  try:
31
  image = Image.open(file).convert("RGB")
32
+ st.image(image, caption="Yüklenen Görsel", use_container_width=True)
33
 
34
+ # 📏 MODELE UYUMLU ŞEKİLDE GÖRSELİ HAZIRLA
35
+ img = image.resize((170, 170)) # ✅ MODELİN GEREKTİRDİĞİ BOYUT
36
  img = np.array(img) / 255.0
37
  img = np.expand_dims(img, axis=0)
38
 
39
+ # 📊 Tahmin
40
  prediction = model.predict(img)
41
 
42
+ # RAW sonuçlar
43
+ st.subheader("📊 Model Çıktısı:")
44
+ st.write(prediction)
45
 
46
+ # 🔎 Tahmini yorumla
47
  if prediction.shape[-1] == 1:
48
  predicted_class = int(prediction[0][0] > 0.5)
49
  elif prediction.shape[-1] == 2:
 
52
  st.error("⚠️ Model çıktısı beklenmeyen formatta.")
53
  st.stop()
54
 
55
+ # 🎯 Sonuç
56
  st.success(f"🧪 Tahmin: **{class_names[predicted_class]}**")
57
 
58
+ # 🔢 Skorlar
59
  st.subheader("📈 Sınıf Skorları:")
60
  for i, score in enumerate(prediction[0]):
61
  if i < len(class_names):