Spaces:
Sleeping
Sleeping
Download src/streamlit_app.py from ferides/skincancer: direct link, hf CLI and curl.
- Browser
- Download file 1.27 kB
-
https://huggingface.co/spaces/ferides/skincancer/resolve/main/src/streamlit_app.py
- Command line
-
hf download hf://spaces/ferides/skincancer/src/streamlit_app.py
-
curl -L -o streamlit_app.py https://huggingface.co/spaces/ferides/skincancer/resolve/main/src/streamlit_app.py
1.27 kB
| import streamlit as st | |
| from tensorflow import keras | |
| from PIL import Image | |
| import numpy as np | |
| from pathlib import Path | |
| # Model dosyası ana klasörde olduğu için: | |
| # /app/skin_cancer_model.keras | |
| MODEL_PATH = Path(__file__).resolve().parent.parent / "skin_cancer_model.keras" | |
| def load_skin_model(): | |
| return keras.models.load_model(str(MODEL_PATH), compile=False) | |
| model = load_skin_model() | |
| def process_image(img): | |
| img = img.convert("RGB") | |
| img = img.resize((170, 170)) | |
| img = np.array(img) | |
| img = img / 255.0 | |
| img = np.expand_dims(img, axis=0) | |
| return img | |
| st.title("Deri Kanser Resmi Sınıflandırma") | |
| st.write("Resim seç, model kanser olup olmadığını tahmin etsin.") | |
| file = st.file_uploader( | |
| "Bir resim yükle", | |
| type=["jpg", "jpeg", "png", "JPG", "JPEG", "PNG"] | |
| ) | |
| if file is not None: | |
| img = Image.open(file) | |
| st.image(img, caption="Yüklenen Resim", use_container_width=True) | |
| image = process_image(img) | |
| prediction = model.predict(image) | |
| probability = float(prediction[0][0]) | |
| predicted_class = 1 if probability > 0.5 else 0 | |
| class_names = ["Kanser değil", "Kanser"] | |
| st.write("Tahmin:", class_names[predicted_class]) | |
| st.write("Olasılık:", round(probability, 4)) |