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