Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| from tensorflow.keras.models import load_model | |
| from PIL import Image | |
| import numpy as np | |
| import os | |
| from tensorflow.keras.models import load_model | |
| # Kodun olduğu klasörün yolunu alıyoruz (/app/src) | |
| current_dir = os.path.dirname(os.path.abspath(__file__)) | |
| # Model tam olarak bu kodun yanında olduğu için direkt ismini birleştiriyoruz | |
| model_path = os.path.join(current_dir, 'malaria_model.keras') | |
| # Modeli yüklüyoruz | |
| model = load_model(model_path) | |
| def process_image(img): | |
| # Resmi RGB formatına zorla (PNG'lerdeki şeffaflık kanalı hatasını önler) | |
| img = img.convert('RGB') | |
| img = img.resize((64, 64)) | |
| img = np.array(img) | |
| img = img / 255.0 | |
| img = np.expand_dims(img, axis=0) | |
| return img | |
| st.title('Sıtma Resmi Sınıflandırma :microscope:') | |
| st.write('Bir resim yükleyin, modelin sıtma olup olmadığını tahmin etmesini sağlayın!') | |
| file = st.file_uploader('Bir resim yükle', type=['jpg', 'jpeg', 'png']) | |
| if file is not None: | |
| img = Image.open(file) | |
| st.image(img, caption='Yüklenen Resim', use_column_width=True) | |
| image = process_image(img) | |
| prediction = model.predict(image)[0][0] | |
| # Ekrana modelin güven oranını yazdıralım (Hata çözmeye çok yardımcı olur) | |
| st.write(f"Modelin Sıtma Olma Olasılığı: %{prediction * 100:.2f}") | |
| predicted_class = 1 if prediction > 0.5 else 0 | |
| class_names = ['Sıtma Yok', 'Sıtma Var'] | |
| st.write(class_names[predicted_class]) |