Harun01 commited on
Commit
473a909
·
verified ·
1 Parent(s): 7ec83f2

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +22 -10
src/streamlit_app.py CHANGED
@@ -10,17 +10,30 @@ def main():
10
  st.title("📷 Hurma Resmi Sınıflandırma")
11
  st.write("Bir hurma resmi yükleyin ve hangi tür olduğunu tahmin edelim.")
12
 
13
- # Modeli yükle
14
- model = load_model("src/dates_classifier_model.h5")
15
-
16
- # Sınıf isimleri modelin çıktı sayısıyla birebir uyumlu olmalı
17
- class_names = ['Ajwa', 'Medjool', 'Sokari']
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
  file = st.file_uploader("Resim seç", type=["jpg", "jpeg", "png"])
20
- if file is not None:
21
  try:
22
  image = Image.open(io.BytesIO(file.read())).convert("RGB")
23
- st.image(image, caption="Yüklenen Resim", use_container_width=True)
24
 
25
  img = image.resize((224, 224))
26
  img = np.array(img) / 255.0
@@ -29,13 +42,12 @@ def main():
29
  prediction = model.predict(img)
30
  predicted_class = np.argmax(prediction)
31
 
32
- # Hatalı index durumuna karşı koruma
33
  if predicted_class < len(class_names):
34
  st.success(f"Tahmin: {class_names[predicted_class]}")
35
  else:
36
- st.error("⚠️ Tahmin edilen sınıf, sınıf isimleriyle eşleşmiyor. Lütfen modelinizi kontrol edin.")
37
  except Exception as e:
38
- st.error(f"⚠️ Hata oluştu: {str(e)}")
39
 
40
  if __name__ == "__main__":
41
  main()
 
10
  st.title("📷 Hurma Resmi Sınıflandırma")
11
  st.write("Bir hurma resmi yükleyin ve hangi tür olduğunu tahmin edelim.")
12
 
13
+ try:
14
+ model = load_model("src/dates_classifier_model.h5")
15
+ except Exception as e:
16
+ st.error("❌ Model yüklenemedi. Lütfen model dosyasının doğru yolda olduğundan emin olun.")
17
+ st.stop()
18
+
19
+ # ✅ 9 sınıf ismi
20
+ class_names = [
21
+ 'Rutab',
22
+ 'Meneifi',
23
+ 'Sokari',
24
+ 'Galaxy',
25
+ 'Shaishe',
26
+ 'Medjool',
27
+ 'Ajwa',
28
+ 'Nabtat Ali',
29
+ 'Sugaey'
30
+ ]
31
 
32
  file = st.file_uploader("Resim seç", type=["jpg", "jpeg", "png"])
33
+ if file:
34
  try:
35
  image = Image.open(io.BytesIO(file.read())).convert("RGB")
36
+ st.image(image, caption="Yüklenen Resim", use_column_width=True)
37
 
38
  img = image.resize((224, 224))
39
  img = np.array(img) / 255.0
 
42
  prediction = model.predict(img)
43
  predicted_class = np.argmax(prediction)
44
 
 
45
  if predicted_class < len(class_names):
46
  st.success(f"Tahmin: {class_names[predicted_class]}")
47
  else:
48
+ st.warning("⚠️ Tahmin edilen sınıf, sınıf isimleriyle eşleşmiyor. Lütfen modelinizi kontrol edin.")
49
  except Exception as e:
50
+ st.error(f" Hata oluştu: {str(e)}")
51
 
52
  if __name__ == "__main__":
53
  main()