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

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +26 -28
src/streamlit_app.py CHANGED
@@ -3,14 +3,12 @@ from PIL import Image
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)
@@ -19,49 +17,49 @@ 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:
50
  predicted_class = int(np.argmax(prediction))
 
 
 
 
51
  else:
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):
62
- st.write(f"{class_names[i]}: {score:.4f}")
63
- else:
64
- st.write(f"Sınıf {i}: {score:.4f}")
65
-
66
  except Exception as e:
67
- st.error(f"🚫 Görsel işleme hatası: {e}")
 
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ÜKLEME
12
  model_path = "src/myn_cnn_model.h5"
13
  try:
14
  model = load_model(model_path, compile=False)
 
17
  st.error(f"❌ Model yüklenemedi: {e}")
18
  st.stop()
19
 
20
+ # SINIF ADLARI (Senin sıralamana göre değiştir)
21
+ class_names = ["Sıtma", "Sıtma Değil"] # Eğer model ters sıralıysa değiştir
22
 
23
+ # RESİM YÜKLEYİCİ
24
  file = st.file_uploader("📷 Mikroskop Görüntüsü Seçin", type=["jpg", "jpeg", "png"])
25
 
 
26
  if file:
27
  try:
28
  image = Image.open(file).convert("RGB")
29
  st.image(image, caption="Yüklenen Görsel", use_container_width=True)
30
 
31
+ # MODELİN INPUT BOYUTUNU AL
32
+ input_shape = model.input_shape[1:3] # Örneğin (170, 170)
33
+ st.write(f"Modelin beklediği görsel boyutu: {input_shape}")
34
+
35
+ # GÖRSELİ AYARLA
36
+ img = image.resize(input_shape)
37
+ img = np.array(img)
38
+
39
+ if img.shape != (*input_shape, 3):
40
+ st.error(f"Görsel boyutu beklenmeyen formatta: {img.shape}")
41
+ st.stop()
42
+
43
+ img = img / 255.0
44
  img = np.expand_dims(img, axis=0)
45
 
46
+ # TAHMİN ET
47
  prediction = model.predict(img)
48
 
49
+ # MODELİN SOFTMAX Mİ SİGMOID Mİ OLDUĞUNU ANLA
 
 
 
 
50
  if prediction.shape[-1] == 1:
51
  predicted_class = int(prediction[0][0] > 0.5)
52
+ st.success(f"🧪 Tahmin: **{class_names[predicted_class]}**")
53
+ st.write(f"Sıtma olasılığı: {prediction[0][0]:.4f}")
54
  elif prediction.shape[-1] == 2:
55
  predicted_class = int(np.argmax(prediction))
56
+ st.success(f"🧪 Tahmin: **{class_names[predicted_class]}**")
57
+ st.subheader("📈 Sınıf Skorları:")
58
+ for i, score in enumerate(prediction[0]):
59
+ st.write(f"{class_names[i]}: {score:.4f}")
60
  else:
61
  st.error("⚠️ Model çıktısı beklenmeyen formatta.")
62
  st.stop()
63
 
 
 
 
 
 
 
 
 
 
 
 
64
  except Exception as e:
65
+ st.error(f"🚫 Görsel işleme veya tahmin hatası: {e}")