HarunDemircioglu11 commited on
Commit
9db6eb4
·
verified ·
1 Parent(s): 7400fc9

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +28 -51
src/streamlit_app.py CHANGED
@@ -1,63 +1,40 @@
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}")
 
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
+ model = load_model("src/saved_model_format.keras")
 
 
 
 
 
 
 
 
 
 
8
 
9
+ # Görseli işle
10
+ def process_image(img):
11
+ img = img.resize((170, 170)) # Modelin beklediği boyut
12
+ img = np.array(img) / 255.0 # Normalize et
13
+ img = np.expand_dims(img, axis=0) # (1, 170, 170, 3)
14
+ return img
15
 
16
+ # Streamlit başlık
17
+ st.title("Sıtma Tespiti Uygulaması")
18
+ st.write("Bir hücre resmi yükleyin. Model, sıtma olup olmadığını tahmin etsin.")
19
 
20
+ # Görsel yükleme
21
+ uploaded_file = st.file_uploader("Bir resim seçin", type=["jpg", "jpeg", "png"])
 
 
 
22
 
23
+ if uploaded_file is not None:
24
+ image = Image.open(uploaded_file).convert("RGB")
25
+ st.image(image, caption="Yüklenen Resim", use_column_width=True)
26
 
27
+ # Tahmin butonu
28
+ if st.button("Tahmin Et"):
29
+ img = process_image(image)
30
+ prediction = model.predict(img) # shape: (1, 2) — softmax çıktısı
31
 
32
+ class_names = ["Sıtma Yok", "Sıtma Var"]
33
+ predicted_class = np.argmax(prediction, axis=1)[0]
34
+ confidence = prediction[0][predicted_class]
35
 
36
+ # Sonucu göster
37
+ if predicted_class == 1:
38
+ st.error(f"Sonuç: {class_names[predicted_class]} ⚠️ ({confidence:.2%} emin)")
 
 
39
  else:
40
+ st.success(f"Sonuç: {class_names[predicted_class]} ({confidence:.2%} emin)")