| import streamlit as st | |
| import tensorflow as tf | |
| import numpy as np | |
| from PIL import Image | |
| st.title("Cat vs Dog Image Classification") | |
| st.write("Bu uygulama yüklenen görselin kedi mi yoksa köpek mi olduğunu tahmin eder.") | |
| model = tf.keras.models.load_model("src/cat_dog_cnn_model.h5") | |
| uploaded_file = st.file_uploader( | |
| "Bir kedi veya köpek görseli yükleyin", | |
| type=["jpg", "jpeg", "png"] | |
| ) | |
| if uploaded_file is not None: | |
| image = Image.open(uploaded_file).convert("RGB") | |
| st.image(image, caption="Yüklenen Görsel", use_container_width=True) | |
| image = image.resize((128, 128)) | |
| img_array = np.array(image) | |
| img_array = np.expand_dims(img_array, axis=0) | |
| prediction = model.predict(img_array) | |
| if prediction[0][0] > 0.5: | |
| result = "Dog" | |
| else: | |
| result = "Cat" | |
| st.subheader("Tahmin Sonucu") | |
| st.write(result) | |
| score = float(prediction[0][0]) | |
| if result == "Dog": | |
| confidence = score * 100 | |
| else: | |
| confidence = (1 - score) * 100 | |
| st.write(f"Güven Oranı: %{confidence:.2f}") |