import streamlit as st
from tensorflow.keras.models import load_model
from PIL import Image
import numpy as np
# Modeli yükleme
model = load_model('my_skin_cancer_model.h5')
def process_img(img):
img = img.resize((170, 170), Image.LANCZOS) # 170x170 piksel boyutuna dönüştürme, LANCZOS filtresi kullanılıyor
img = np.array(img) / 255.0 # Normalize etme
img = np.expand_dims(img, axis=0) # Resme boyut ekleme
return img
# Sayfa başlığı ve stili
st.markdown("""
""", unsafe_allow_html=True)
st.markdown('
Cilt Kanseri Resmini Sınıflandırılması
', unsafe_allow_html=True)
st.markdown('Resim seç ve modelimiz kanser olup olmadığını kontrol etsin.
Upload an image and the model will predict if your image shows cancer or not.
', unsafe_allow_html=True)
file = st.file_uploader("Resim Yükle & Upload Image", type=['png', 'jpg', 'jpeg'])
if file is not None: # Resim boş değilse
img = Image.open(file) # Resmi açma
st.image(img, caption="Yüklenen Resim", use_column_width=True) # Seçilen resmi gösterme
result = process_img(img) # Fonksiyonla resim işleme, yani boyut değişecek ve işlenebilir hale getirilecek
prediction = model.predict(result)
prediction_class = np.argmax(prediction) # 0 veya 1 olarak tahmin edilen sınıf
class_names = ['Kanser Değil', 'Kanser!']
st.markdown(f'Sonuç: {class_names[prediction_class]}
', unsafe_allow_html=True)
else:
st.info("Lütfen bir resim yükleyin. / Please upload an image.")