Harun01 commited on
Commit
f59b0ba
·
verified ·
1 Parent(s): b816ac3

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +32 -16
src/streamlit_app.py CHANGED
@@ -3,31 +3,47 @@ from tensorflow.keras.models import load_model
3
  from PIL import Image
4
  import streamlit as st
5
 
6
- # Modeli yükle (src klasörünün içindeyse)
7
  model = load_model('src/dates_classifier_model.h5')
8
 
 
9
  def process_image(img):
10
- img = img.resize((224, 224))
11
- img = np.array(img) / 255.0
12
  img = np.expand_dims(img, axis=0)
13
  return img
14
 
 
15
  st.title('Hurma Resmi Sınıflandırma')
16
  st.write('Bir hurma resmi yükleyin, hangi tür olduğunu tahmin edelim.')
17
 
 
18
  file = st.file_uploader('Bir Resim Seçin', type=['jpg', 'jpeg', 'png'])
19
 
20
  if file is not None:
21
- img = Image.open(file)
22
- st.image(img, caption='Yüklenen Resim', use_column_width=True)
23
-
24
- processed_image = process_image(img)
25
- prediction = model.predict(processed_image)
26
- predicted_class = np.argmax(prediction)
27
-
28
- class_names = [
29
- 'Rutab', 'Meneifi', 'Sokari', 'Galaxy', 'Shaishe',
30
- 'Medjool', 'Ajwa', 'Nabtat Ali', 'Sugaey'
31
- ]
32
-
33
- st.write(f'Tahmin Edilen Sınıf: **{class_names[predicted_class]}**')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  from PIL import Image
4
  import streamlit as st
5
 
6
+ # Modeli yükle
7
  model = load_model('src/dates_classifier_model.h5')
8
 
9
+ # Görsel işleme fonksiyonu
10
  def process_image(img):
11
+ img = img.resize((224, 224)) # Modelin beklediği boyut
12
+ img = np.array(img) / 255.0 # Normalizasyon
13
  img = np.expand_dims(img, axis=0)
14
  return img
15
 
16
+ # Arayüz başlığı
17
  st.title('Hurma Resmi Sınıflandırma')
18
  st.write('Bir hurma resmi yükleyin, hangi tür olduğunu tahmin edelim.')
19
 
20
+ # Görsel yükleme alanı
21
  file = st.file_uploader('Bir Resim Seçin', type=['jpg', 'jpeg', 'png'])
22
 
23
  if file is not None:
24
+ try:
25
+ img = Image.open(file).convert('RGB') # Bazı görseller RGBA olabilir
26
+ st.image(img, caption='Yüklenen Resim', use_column_width=True)
27
+
28
+ # Tahmin işlemi
29
+ processed_image = process_image(img)
30
+ prediction = model.predict(processed_image)
31
+ predicted_class = np.argmax(prediction)
32
+
33
+ # Sınıf etiketleri
34
+ class_names = [
35
+ 'Rutab',
36
+ 'Meneifi',
37
+ 'Sokari',
38
+ 'Galaxy',
39
+ 'Shaishe',
40
+ 'Medjool',
41
+ 'Ajwa',
42
+ 'Nabtat Ali',
43
+ 'Sugaey'
44
+ ]
45
+
46
+ st.write(f'Tahmin Edilen Sınıf: **{class_names[predicted_class]}**')
47
+
48
+ except Exception as e:
49
+ st.error(f"Bir hata oluştu: {e}")