Harun01 commited on
Commit
90474d4
·
verified ·
1 Parent(s): 423c6e2

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +28 -16
src/streamlit_app.py CHANGED
@@ -1,28 +1,40 @@
1
- import streamlit as st
2
  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])
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
  from tensorflow.keras.models import load_model
3
  from PIL import Image
4
  import numpy as np
5
 
6
+ # Modeli yükle
7
+ try:
8
+ model = load_model('my_cnn_model.h5')
9
+ except Exception as e:
10
+ st.error(f"Model yüklenirken bir hata oluştu: {e}")
11
 
12
  def process_image(img):
13
+ img = img.resize((170, 170)) # Boyutunu 170 x 170 pixel yaptık
14
+ img = np.array(img)
15
+ img = img / 255.0 # Normalize ettik
16
+ img = np.expand_dims(img, axis=0)
17
  return img
18
 
19
+ st.title("Kanser Resmi Sınıflandırma :cancer:")
20
+ st.write("Resim seç ve model kanser olup olmadığını tahmin etsin.")
21
 
22
+ file = st.file_uploader('Bir Resim Seç', type=['jpg', 'jpeg', 'png'])
23
 
24
  if file is not None:
25
+ img = Image.open(file)
26
+ st.image(img, caption='Yüklenen Resim', use_column_width=True)
 
 
 
27
 
28
+ # Resmi işle
29
+ image = process_image(img)
30
+
31
+ # Tahmin yap
32
+ try:
33
+ prediction = model.predict(image)
34
+ predicted_class = np.argmax(prediction)
35
+
36
+ class_names = ['Kanser Değil', 'Kanser']
37
+ st.write(class_names[predicted_class])
38
+ except Exception as e:
39
+ st.error(f"Tahmin yaparken bir hata oluştu: {e}")
40
+