Date_Classification / src /streamlit_app.py
Harun01's picture
Update src/streamlit_app.py
b68ebd5 verified
import streamlit as st
from PIL import Image
import numpy as np
from tensorflow.keras.models import load_model
import io
def main():
st.set_page_config(page_title="Hurma Sınıflandırıcı")
st.title("📷 Hurma Resmi Sınıflandırma")
st.write("Bir hurma resmi yükleyin ve hangi tür olduğunu tahmin edelim.")
try:
model = load_model("src/dates_classifier_model.h5")
except Exception as e:
st.error("❌ Model yüklenemedi.")
st.stop()
class_names = [
'Rutab',
'Meneifi',
'Sokari',
'Galaxy',
'Shaishe',
'Medjool',
'Ajwa',
'Nabtat Ali',
'Sugaey'
]
file = st.file_uploader("Resim seç", type=["jpg", "jpeg", "png"])
if file:
try:
image = Image.open(io.BytesIO(file.read())).convert("RGB")
st.image(image, caption="Yüklenen Resim", use_container_width=True)
img = image.resize((224, 224))
img = np.array(img)
img = img / 255.0 # Bu adımı kaldırman gerekebilir, model eğitimine göre!
img = np.expand_dims(img, axis=0)
prediction = model.predict(img)
predicted_class = np.argmax(prediction)
st.success(f"Tahmin: {class_names[predicted_class]}")
# Debug için tahmin sonuçlarını göster
st.subheader("Tahmin Skorları (Softmax Çıkışı):")
for i, score in enumerate(prediction[0]):
st.write(f"{class_names[i]}: {score:.4f}")
except Exception as e:
st.error(f"Hata: {str(e)}")
if __name__ == "__main__":
main()