Update src/streamlit_app.py
Browse files- src/streamlit_app.py +18 -3
src/streamlit_app.py
CHANGED
|
@@ -12,17 +12,32 @@ def main():
|
|
| 12 |
|
| 13 |
model = load_model("src/dates_classifier_model.h5")
|
| 14 |
|
| 15 |
-
|
|
|
|
| 16 |
|
| 17 |
file = st.file_uploader("Resim seç", type=["jpg", "jpeg", "png"])
|
| 18 |
if file:
|
| 19 |
image = Image.open(io.BytesIO(file.read())).convert("RGB")
|
| 20 |
-
st.image(image, caption="Yüklenen Resim")
|
| 21 |
|
|
|
|
| 22 |
img = image.resize((224, 224))
|
| 23 |
img = np.array(img) / 255.0
|
| 24 |
img = np.expand_dims(img, axis=0)
|
| 25 |
|
|
|
|
| 26 |
prediction = model.predict(img)
|
| 27 |
predicted_class = np.argmax(prediction)
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
model = load_model("src/dates_classifier_model.h5")
|
| 14 |
|
| 15 |
+
# Sınıf isimleri — modelin çıkış sayısıyla birebir uyuşmalı
|
| 16 |
+
class_names = ['Ajwa', 'Medjool', 'Sokari']
|
| 17 |
|
| 18 |
file = st.file_uploader("Resim seç", type=["jpg", "jpeg", "png"])
|
| 19 |
if file:
|
| 20 |
image = Image.open(io.BytesIO(file.read())).convert("RGB")
|
| 21 |
+
st.image(image, caption="Yüklenen Resim", use_column_width=True)
|
| 22 |
|
| 23 |
+
# Görseli modele uygun boyutlandır
|
| 24 |
img = image.resize((224, 224))
|
| 25 |
img = np.array(img) / 255.0
|
| 26 |
img = np.expand_dims(img, axis=0)
|
| 27 |
|
| 28 |
+
# Tahmin yap
|
| 29 |
prediction = model.predict(img)
|
| 30 |
predicted_class = np.argmax(prediction)
|
| 31 |
+
|
| 32 |
+
# Debug için detayları yazdır
|
| 33 |
+
st.write("Model çıkışı (ham tahminler):", prediction.tolist())
|
| 34 |
+
st.write("Tahmin edilen index:", predicted_class)
|
| 35 |
+
|
| 36 |
+
# Hatalı index kontrolü
|
| 37 |
+
if predicted_class < len(class_names):
|
| 38 |
+
st.success(f"Tahmin: {class_names[predicted_class]}")
|
| 39 |
+
else:
|
| 40 |
+
st.error("Tahmin edilen sınıf geçersiz. Lütfen modelin çıktısıyla class_names listesini kontrol et.")
|
| 41 |
+
|
| 42 |
+
if __name__ == "__main__":
|
| 43 |
+
main()
|