Update src/streamlit_app.py
Browse files- src/streamlit_app.py +13 -30
src/streamlit_app.py
CHANGED
|
@@ -3,43 +3,26 @@ from tensorflow.keras.models import load_model
|
|
| 3 |
from PIL import Image
|
| 4 |
import numpy as np
|
| 5 |
|
| 6 |
-
# ✅
|
| 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,
|
| 15 |
-
img = np.array(img) / 255.0
|
| 16 |
-
img = np.expand_dims(img, axis=0)
|
| 17 |
return img
|
| 18 |
|
| 19 |
-
|
| 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 |
-
|
| 25 |
-
file = st.file_uploader('📷 Resim Seç', type=['jpg', 'jpeg', 'png'])
|
| 26 |
|
| 27 |
if file is not None:
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 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}")
|
|
|
|
| 3 |
from PIL import Image
|
| 4 |
import numpy as np
|
| 5 |
|
| 6 |
+
# ✅ Doğru dosya yolu
|
| 7 |
+
model = load_model('src/my_cnn_model.h5')
|
| 8 |
|
|
|
|
| 9 |
class_names = ['Kanser Değil', 'Kanser']
|
| 10 |
|
|
|
|
| 11 |
def process_image(img):
|
| 12 |
+
img = img.resize((170,170))
|
| 13 |
+
img = np.array(img) / 255.0
|
| 14 |
+
img = np.expand_dims(img, axis=0)
|
| 15 |
return img
|
| 16 |
|
| 17 |
+
st.title("🧬 Cilt Kanseri Sınıflandırıcı")
|
|
|
|
|
|
|
| 18 |
st.write("Bir cilt görseli yükleyin, model kanser olup olmadığını tahmin etsin.")
|
| 19 |
|
| 20 |
+
file = st.file_uploader('Bir resim seç', type=['jpg','jpeg','png'])
|
|
|
|
| 21 |
|
| 22 |
if file is not None:
|
| 23 |
+
img = Image.open(file).convert("RGB")
|
| 24 |
+
st.image(img, caption='Yüklenen Resim', use_container_width=True)
|
| 25 |
+
image = process_image(img)
|
| 26 |
+
prediction = model.predict(image)
|
| 27 |
+
predicted_class = np.argmax(prediction)
|
| 28 |
+
st.success(f"Tahmin: {class_names[predicted_class]}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|