Update src/streamlit_app.py
Browse files- src/streamlit_app.py +33 -16
src/streamlit_app.py
CHANGED
|
@@ -3,26 +3,43 @@ from tensorflow.keras.models import load_model
|
|
| 3 |
from PIL import Image
|
| 4 |
import numpy as np
|
| 5 |
|
| 6 |
-
|
|
|
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
def process_image(img):
|
| 9 |
-
img=img.resize((170,170))
|
| 10 |
-
img=np.array(img)
|
| 11 |
-
img=img
|
| 12 |
-
img=np.expand_dims(img,axis=0)
|
| 13 |
return img
|
| 14 |
|
| 15 |
-
|
| 16 |
-
st.
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
|
|
|
|
| 19 |
|
| 20 |
if file is not None:
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
from PIL import Image
|
| 4 |
import numpy as np
|
| 5 |
|
| 6 |
+
# ✅ Modeli doğru yoldan yükle (gerekirse "src/my_cnn_model.h5" yap)
|
| 7 |
+
model = load_model('my_cnn_model.h5')
|
| 8 |
|
| 9 |
+
# ✅ Sınıf isimleri (Binary Classification)
|
| 10 |
+
class_names = ['Kanser Değil', 'Kanser']
|
| 11 |
+
|
| 12 |
+
# ✅ Resim ön işleme fonksiyonu
|
| 13 |
def process_image(img):
|
| 14 |
+
img = img.resize((170, 170)) # modelin beklediği input boyutu
|
| 15 |
+
img = np.array(img) / 255.0 # normalizasyon
|
| 16 |
+
img = np.expand_dims(img, axis=0) # modelin beklediği 4D tensor
|
|
|
|
| 17 |
return img
|
| 18 |
|
| 19 |
+
# ✅ Uygulama başlığı ve açıklama
|
| 20 |
+
st.set_page_config(page_title="Cilt Kanseri Sınıflandırıcı")
|
| 21 |
+
st.title("🔬 Cilt Kanseri Sınıflandırma")
|
| 22 |
+
st.write("Bir cilt görseli yükleyin, model kanser olup olmadığını tahmin etsin.")
|
| 23 |
|
| 24 |
+
# ✅ Kullanıcıdan dosya al
|
| 25 |
+
file = st.file_uploader('📷 Resim Seç', type=['jpg', 'jpeg', 'png'])
|
| 26 |
|
| 27 |
if file is not None:
|
| 28 |
+
try:
|
| 29 |
+
img = Image.open(file).convert("RGB")
|
| 30 |
+
st.image(img, caption='Yüklenen Resim', use_container_width=True)
|
| 31 |
+
|
| 32 |
+
# İşleme ve tahmin
|
| 33 |
+
processed = process_image(img)
|
| 34 |
+
prediction = model.predict(processed)
|
| 35 |
+
predicted_class = int(np.argmax(prediction))
|
| 36 |
+
|
| 37 |
+
# Tahmini yazdır
|
| 38 |
+
if predicted_class < len(class_names):
|
| 39 |
+
st.success(f"Tahmin: **{class_names[predicted_class]}**")
|
| 40 |
+
else:
|
| 41 |
+
st.warning("⚠️ Tahmin edilen sınıf geçersiz. Model veya sınıf isimleri uyuşmuyor.")
|
| 42 |
+
except Exception as e:
|
| 43 |
+
st.error(f"Bir hata oluştu: {e}")
|
| 44 |
+
confidence = float(np.max(prediction)) * 100
|
| 45 |
+
st.write(f"🧠 Güven: %{confidence:.2f}")
|