HarunDemircioglu11 commited on
Commit
3c27efc
·
verified ·
1 Parent(s): 12754e8

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +46 -28
src/streamlit_app.py CHANGED
@@ -1,45 +1,63 @@
1
  import streamlit as st
2
- import numpy as np
3
  from PIL import Image
 
4
  from tensorflow.keras.models import load_model
5
 
6
- # Modeli yükle
 
 
 
 
 
7
  try:
8
- model = load_model("src/saved_model_format.keras", compile=False)
9
- st.success("✅ Model yüklendi.")
10
  except Exception as e:
11
  st.error(f"❌ Model yüklenemedi: {e}")
12
  st.stop()
13
 
14
- class_names = ["Sıtma Yok", "Sıtma Var"]
15
-
16
- def process_image(img):
17
- img = img.resize((170, 170))
18
- img = np.array(img).astype("float32") / 255.0
19
- img = np.expand_dims(img, axis=0)
20
- return img
21
-
22
- st.title("🧫 Sıtma Tespiti Uygulaması")
23
- st.write("Hücre görüntüsünü yükleyin, model sıtma olup olmadığını tahmin etsin.")
24
 
25
- file = st.file_uploader("Bir Resim Seç", type=['jpg', 'jpeg', 'png'])
 
26
 
27
- if file is not None:
 
28
  try:
29
  image = Image.open(file).convert("RGB")
30
- st.image(image, caption="Yüklenen Görsel", use_container_width=True)
31
-
32
- img = process_image(image)
33
- st.write("✅ Görsel hazır, tahmin yapılıyor...")
34
-
 
 
35
  prediction = model.predict(img)
36
- predicted_class = np.argmax(prediction)
37
- confidence = prediction[0][predicted_class]
38
 
39
- if predicted_class == 1:
40
- st.error(f"⚠️ Sıtma Tespit Edildi ({confidence:.2%} eminlik)")
 
 
 
 
 
 
 
41
  else:
42
- st.success(f" Sıtma Bulunamadı ({confidence:.2%} eminlik)")
43
-
 
 
 
 
 
 
 
 
 
 
 
 
44
  except Exception as e:
45
- st.error(f"⚠️ Görsel yüklenirken hata: {e}")
 
1
  import streamlit as st
 
2
  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:
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}")