Spaces:
Sleeping
Sleeping
Delete streamlit_app.py
Browse files- streamlit_app.py +0 -67
streamlit_app.py
DELETED
|
@@ -1,67 +0,0 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
import tensorflow as tf
|
| 3 |
-
import numpy as np
|
| 4 |
-
from PIL import Image
|
| 5 |
-
from tensorflow.keras.applications.resnet50 import preprocess_input
|
| 6 |
-
|
| 7 |
-
# =========================
|
| 8 |
-
# LOAD MODEL
|
| 9 |
-
# =========================
|
| 10 |
-
@st.cache_resource
|
| 11 |
-
def load_model():
|
| 12 |
-
return tf.keras.models.load_model("cnn_kfold_best_model.h5", compile=False)
|
| 13 |
-
|
| 14 |
-
model = load_model()
|
| 15 |
-
class_names = ["normal", "buried"]
|
| 16 |
-
|
| 17 |
-
# =========================
|
| 18 |
-
# PREPROCESSING
|
| 19 |
-
# =========================
|
| 20 |
-
def prepare_image(img):
|
| 21 |
-
img = img.convert("RGB")
|
| 22 |
-
img = img.resize((224, 224))
|
| 23 |
-
img_array = np.array(img)
|
| 24 |
-
img_array = np.expand_dims(img_array, axis=0)
|
| 25 |
-
img_array = preprocess_input(img_array)
|
| 26 |
-
return img_array
|
| 27 |
-
|
| 28 |
-
# =========================
|
| 29 |
-
# UI
|
| 30 |
-
# =========================
|
| 31 |
-
st.set_page_config(
|
| 32 |
-
page_title="Ashoka Hipospadia Classifier",
|
| 33 |
-
layout="centered"
|
| 34 |
-
)
|
| 35 |
-
|
| 36 |
-
st.title("🧠 Ashoka Hipospadia Classifier")
|
| 37 |
-
st.write("Upload gambar untuk klasifikasi **Normal** atau **Buried**")
|
| 38 |
-
|
| 39 |
-
uploaded_file = st.file_uploader(
|
| 40 |
-
"Upload gambar (JPG / PNG)",
|
| 41 |
-
type=["jpg", "jpeg", "png"]
|
| 42 |
-
)
|
| 43 |
-
|
| 44 |
-
if uploaded_file is not None:
|
| 45 |
-
image = Image.open(uploaded_file)
|
| 46 |
-
|
| 47 |
-
st.image(image, caption="Gambar Input", use_container_width=True)
|
| 48 |
-
|
| 49 |
-
if st.button("🔍 Predict"):
|
| 50 |
-
with st.spinner("Melakukan prediksi..."):
|
| 51 |
-
processed_image = prepare_image(image)
|
| 52 |
-
prediction = model.predict(processed_image)[0][0]
|
| 53 |
-
|
| 54 |
-
prob_normal = (1 - prediction) * 100
|
| 55 |
-
prob_buried = prediction * 100
|
| 56 |
-
|
| 57 |
-
predicted_class = "buried" if prediction > 0.5 else "normal"
|
| 58 |
-
confidence = max(prob_normal, prob_buried)
|
| 59 |
-
|
| 60 |
-
st.success(f"### 🏷️ Prediksi: **{predicted_class.upper()}**")
|
| 61 |
-
st.write(f"**Confidence:** {confidence:.2f}%")
|
| 62 |
-
|
| 63 |
-
st.progress(int(confidence))
|
| 64 |
-
|
| 65 |
-
st.subheader("📊 Probabilitas")
|
| 66 |
-
st.write(f"- Normal: **{prob_normal:.2f}%**")
|
| 67 |
-
st.write(f"- Buried: **{prob_buried:.2f}%**")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|