MuahammadHamza commited on
Commit
c9b050b
·
verified ·
1 Parent(s): f653f0a

Upload 6 files

Browse files
Files changed (6) hide show
  1. Dockerfile +24 -20
  2. README.md +45 -19
  3. requirements.txt +15 -3
  4. streamlit_app.py +63 -0
  5. test.json +0 -0
  6. train.json +0 -0
Dockerfile CHANGED
@@ -1,20 +1,24 @@
1
- FROM python:3.13.5-slim
2
-
3
- WORKDIR /app
4
-
5
- RUN apt-get update && apt-get install -y \
6
- build-essential \
7
- curl \
8
- git \
9
- && rm -rf /var/lib/apt/lists/*
10
-
11
- COPY requirements.txt ./
12
- COPY src/ ./src/
13
-
14
- RUN pip3 install -r requirements.txt
15
-
16
- EXPOSE 8501
17
-
18
- HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
19
-
20
- ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]
 
 
 
 
 
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
- title: Lab 5
3
- emoji: 🚀
4
- colorFrom: red
5
- colorTo: red
6
- sdk: docker
7
- app_port: 8501
8
- tags:
9
- - streamlit
10
- pinned: false
11
- short_description: Streamlit template space
12
- ---
13
-
14
- # Welcome to Streamlit!
15
-
16
- Edit `/src/streamlit_app.py` to customize this app to your heart's desire. :heart:
17
-
18
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
19
- forums](https://discuss.streamlit.io).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
- altair
2
- pandas
3
- streamlit
 
 
 
 
 
 
 
 
 
 
 
 
 
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