Spaces:
Sleeping
Sleeping
File size: 2,043 Bytes
c9b050b 6198aa8 c9b050b 6198aa8 c9b050b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | import os
import sys
import tempfile
import streamlit as st
from PIL import Image
# Ensure we can import the local `gradio/app.py` module (model + graph logic).
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
GRADIO_DIR = os.path.join(BASE_DIR, "gradio")
if GRADIO_DIR not in sys.path:
sys.path.append(GRADIO_DIR)
from app import predict_aml # type: ignore
st.set_page_config(
page_title="AML vs non-AML GAT (H_100X_C2)",
layout="wide",
)
st.title("AML vs non-AML GAT (H_100X_C2) – Streamlit")
st.write(
"Upload a blood smear image from the H_100X_C2 dataset. "
"The app looks up its annotations, builds a graph, and runs the trained GAT model."
)
uploaded_file = st.file_uploader(
"Upload blood smear image (must be one of the H_100X_C2 images, e.g. `1_11_1000_ALL.png`)",
type=["png", "jpg", "jpeg"],
)
def save_uploaded_with_original_name(uploaded) -> str:
"""
Save the uploaded file to a temporary directory, preserving its original
filename. The prediction pipeline only uses the basename to look up
annotations in train/test JSON.
"""
if uploaded is None:
return ""
original_name = os.path.basename(uploaded.name)
tmp_dir = tempfile.mkdtemp(prefix="aml_streamlit_")
dest_path = os.path.join(tmp_dir, original_name)
with open(dest_path, "wb") as f:
f.write(uploaded.read())
return dest_path
if uploaded_file is not None:
image_path = save_uploaded_with_original_name(uploaded_file)
if image_path:
col_img, col_pred = st.columns([2, 1])
with col_img:
st.subheader("Uploaded image")
st.image(Image.open(image_path), caption=os.path.basename(image_path), use_column_width=True)
with col_pred:
st.subheader("Prediction / Status")
status, confidence = predict_aml(image_path)
st.write(status)
st.subheader("Confidence")
st.write(confidence)
|