Spaces:
Sleeping
Sleeping
Upload 6 files
Browse files- Dockerfile +24 -20
- README.md +45 -19
- requirements.txt +15 -3
- streamlit_app.py +63 -0
- test.json +0 -0
- train.json +0 -0
Dockerfile
CHANGED
|
@@ -1,20 +1,24 @@
|
|
| 1 |
-
FROM python:3.
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
COPY
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.11-slim
|
| 2 |
+
|
| 3 |
+
ENV PYTHONDONTWRITEBYTECODE=1
|
| 4 |
+
ENV PYTHONUNBUFFERED=1
|
| 5 |
+
|
| 6 |
+
WORKDIR /app
|
| 7 |
+
|
| 8 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 9 |
+
build-essential \
|
| 10 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 11 |
+
|
| 12 |
+
COPY docker/requirements.txt /app/requirements.txt
|
| 13 |
+
RUN pip install --no-cache-dir -r /app/requirements.txt
|
| 14 |
+
|
| 15 |
+
# Copy the Gradio folder that contains the model code, weights, and JSON files.
|
| 16 |
+
COPY gradio /app/gradio
|
| 17 |
+
|
| 18 |
+
# Copy the Streamlit entrypoint.
|
| 19 |
+
COPY docker/streamlit_app.py /app/streamlit_app.py
|
| 20 |
+
|
| 21 |
+
EXPOSE 8501
|
| 22 |
+
|
| 23 |
+
CMD ["streamlit", "run", "streamlit_app.py", "--server.address=0.0.0.0", "--server.port=8501"]
|
| 24 |
+
|
README.md
CHANGED
|
@@ -1,19 +1,45 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
#
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
## Streamlit Docker deployment for GAT (H_100X_C2)
|
| 2 |
+
|
| 3 |
+
This folder contains a Streamlit app and Docker configuration that reuse the
|
| 4 |
+
model and graph-construction logic from `gradio/app.py`.
|
| 5 |
+
|
| 6 |
+
### Folder layout
|
| 7 |
+
|
| 8 |
+
From the project root:
|
| 9 |
+
|
| 10 |
+
```text
|
| 11 |
+
gradio/
|
| 12 |
+
app.py # model + graph logic
|
| 13 |
+
train.json # H_100X_C2 train annotations (copied here)
|
| 14 |
+
test.json # H_100X_C2 test annotations (copied here)
|
| 15 |
+
gat_best.pt # trained GAT weights (in models/ or next to app.py, per app.py logic)
|
| 16 |
+
|
| 17 |
+
docker/
|
| 18 |
+
Dockerfile
|
| 19 |
+
requirements.txt
|
| 20 |
+
streamlit_app.py
|
| 21 |
+
```
|
| 22 |
+
|
| 23 |
+
The Docker image copies the entire `gradio/` folder into `/app/gradio`, so any
|
| 24 |
+
JSON files and model weights you have there will be available inside the
|
| 25 |
+
container.
|
| 26 |
+
|
| 27 |
+
### Build and run
|
| 28 |
+
|
| 29 |
+
From the **project root** (where `gradio/` and `docker/` live):
|
| 30 |
+
|
| 31 |
+
```bash
|
| 32 |
+
docker build -t gat-streamlit -f docker/Dockerfile .
|
| 33 |
+
docker run -p 8501:8501 gat-streamlit
|
| 34 |
+
```
|
| 35 |
+
|
| 36 |
+
Then open `http://localhost:8501` in your browser.
|
| 37 |
+
|
| 38 |
+
### Notes
|
| 39 |
+
|
| 40 |
+
- The Streamlit app imports `predict_aml` from `gradio.app`, so it uses the same
|
| 41 |
+
preprocessing and model as the Gradio version.
|
| 42 |
+
- The JSON annotation files (`train.json`, `test.json`) and `gat_best.pt` must
|
| 43 |
+
be present in the `gradio/` folder **before** building the image so they are
|
| 44 |
+
copied into the container.
|
| 45 |
+
|
requirements.txt
CHANGED
|
@@ -1,3 +1,15 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch
|
| 2 |
+
torchvision
|
| 3 |
+
torchaudio
|
| 4 |
+
torch-geometric
|
| 5 |
+
numpy
|
| 6 |
+
scikit-learn
|
| 7 |
+
networkx
|
| 8 |
+
matplotlib
|
| 9 |
+
gradio==5.27.0
|
| 10 |
+
gradio-client==1.9.0
|
| 11 |
+
huggingface_hub>=0.28.1
|
| 12 |
+
Pillow
|
| 13 |
+
opencv-python-headless
|
| 14 |
+
streamlit
|
| 15 |
+
|
streamlit_app.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import tempfile
|
| 3 |
+
|
| 4 |
+
import streamlit as st
|
| 5 |
+
from PIL import Image
|
| 6 |
+
|
| 7 |
+
from gradio.app import predict_aml
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
st.set_page_config(
|
| 11 |
+
page_title="AML vs non-AML GAT (H_100X_C2)",
|
| 12 |
+
layout="wide",
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
st.title("AML vs non-AML GAT (H_100X_C2) – Streamlit")
|
| 16 |
+
st.write(
|
| 17 |
+
"Upload a blood smear image from the H_100X_C2 dataset. "
|
| 18 |
+
"The app looks up its annotations, builds a graph, and runs the trained GAT model."
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
uploaded_file = st.file_uploader(
|
| 23 |
+
"Upload blood smear image (must be one of the H_100X_C2 images, e.g. `1_11_1000_ALL.png`)",
|
| 24 |
+
type=["png", "jpg", "jpeg"],
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def save_uploaded_with_original_name(uploaded) -> str:
|
| 29 |
+
"""
|
| 30 |
+
Save the uploaded file to a temporary directory, preserving its original
|
| 31 |
+
filename. The prediction pipeline only uses the basename to look up
|
| 32 |
+
annotations in train/test JSON.
|
| 33 |
+
"""
|
| 34 |
+
if uploaded is None:
|
| 35 |
+
return ""
|
| 36 |
+
|
| 37 |
+
original_name = os.path.basename(uploaded.name)
|
| 38 |
+
tmp_dir = tempfile.mkdtemp(prefix="aml_streamlit_")
|
| 39 |
+
dest_path = os.path.join(tmp_dir, original_name)
|
| 40 |
+
|
| 41 |
+
with open(dest_path, "wb") as f:
|
| 42 |
+
f.write(uploaded.read())
|
| 43 |
+
|
| 44 |
+
return dest_path
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
if uploaded_file is not None:
|
| 48 |
+
image_path = save_uploaded_with_original_name(uploaded_file)
|
| 49 |
+
|
| 50 |
+
if image_path:
|
| 51 |
+
col_img, col_pred = st.columns([2, 1])
|
| 52 |
+
|
| 53 |
+
with col_img:
|
| 54 |
+
st.subheader("Uploaded image")
|
| 55 |
+
st.image(Image.open(image_path), caption=os.path.basename(image_path), use_column_width=True)
|
| 56 |
+
|
| 57 |
+
with col_pred:
|
| 58 |
+
st.subheader("Prediction / Status")
|
| 59 |
+
status, confidence = predict_aml(image_path)
|
| 60 |
+
st.write(status)
|
| 61 |
+
st.subheader("Confidence")
|
| 62 |
+
st.write(confidence)
|
| 63 |
+
|
test.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
train.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|