Download src/app.py from streamlit/streamlit-template-space: direct link, hf CLI and curl.
- Browser
- Download file 1.17 kB
-
https://huggingface.co/spaces/streamlit/streamlit-template-space/resolve/refs%2Fpr%2F7/src/app.py
- Command line
-
hf download hf://spaces/streamlit/streamlit-template-space@refs/pr/7/src/app.py
-
curl -L -o app.py https://huggingface.co/spaces/streamlit/streamlit-template-space/resolve/refs%2Fpr%2F7/src/app.py
1.17 kB
| import streamlit as st | |
| from tensorflow.keras.models import load_model | |
| from PIL import Image | |
| import numpy as np | |
| # Modeli yükle | |
| model = load_model('malaria_model.keras') | |
| 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]) |