Harun01 commited on
Commit
c41d325
·
verified ·
1 Parent(s): 950ba35

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. 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
- model=load_model('my_cnn_model.h5')
 
7
 
 
 
 
 
8
  def process_image(img):
9
- img=img.resize((170,170)) #boyutunu 170 x 170 pixel yaptik
10
- img=np.array(img)
11
- img=img/255.0 #normalize ettik
12
- img=np.expand_dims(img,axis=0)
13
  return img
14
 
15
- st.title("Kanser Resmi Siniflandirma :cancer:")
16
- st.write("Resim sec ve model kanser olup olmadigini tahmin etsin")
 
 
17
 
18
- file=st.file_uploader('Bir Resim Sec',type=['jpg','jpeg','png'])
 
19
 
20
  if file is not None:
21
- img=Image.open(file)
22
- st.image(img,caption='yuklenen resim')
23
- image= process_image(img)
24
- prediction=model.predict(image)
25
- predicted_class=np.argmax(prediction)
26
-
27
- class_names=['Kanser Degil','Kanser']
28
- st.write(class_names[predicted_class])
 
 
 
 
 
 
 
 
 
 
 
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}")