Upload folder using huggingface_hub
Browse files- .gitattributes +1 -0
- Dockerfile +23 -0
- app.py +72 -0
- brain_tumor_vgg16_model.keras +3 -0
- requirements.txt +5 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
brain_tumor_vgg16_model.keras filter=lfs diff=lfs merge=lfs -text
|
Dockerfile
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use a minimal base image with Python 3.9 installed
|
| 2 |
+
FROM python:3.9
|
| 3 |
+
|
| 4 |
+
# Set the working directory inside the container to /app
|
| 5 |
+
WORKDIR /app
|
| 6 |
+
|
| 7 |
+
# Copy all files from the current directory on the host to the container's /app directory
|
| 8 |
+
COPY . .
|
| 9 |
+
|
| 10 |
+
# Install Python dependencies listed in requirements.txt
|
| 11 |
+
RUN pip3 install -r requirements.txt
|
| 12 |
+
|
| 13 |
+
RUN useradd -m -u 1000 user
|
| 14 |
+
USER user
|
| 15 |
+
ENV HOME=/home/user \
|
| 16 |
+
PATH=/home/user/.local/bin:$PATH
|
| 17 |
+
|
| 18 |
+
WORKDIR $HOME/app
|
| 19 |
+
|
| 20 |
+
COPY --chown=user . $HOME/app
|
| 21 |
+
|
| 22 |
+
# Define the command to run the Streamlit app on port "7860" and make it accessible externally
|
| 23 |
+
CMD ["streamlit", "run", "app.py", "--server.port=7860", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"]
|
app.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import numpy as np
|
| 3 |
+
from PIL import Image
|
| 4 |
+
from tensorflow.keras.models import load_model
|
| 5 |
+
import os
|
| 6 |
+
import time
|
| 7 |
+
import requests
|
| 8 |
+
from io import BytesIO
|
| 9 |
+
|
| 10 |
+
# Function to load the model (cached for efficiency)
|
| 11 |
+
@st.cache_resource
|
| 12 |
+
def load_vgg_model():
|
| 13 |
+
return load_model("brain_tumor_vgg16_model.keras")
|
| 14 |
+
|
| 15 |
+
# Function to run the prediction and show progress
|
| 16 |
+
def run_prediction(image_path, model, img_size):
|
| 17 |
+
# Create a progress bar and status text
|
| 18 |
+
progress_bar = st.progress(0)
|
| 19 |
+
status_text = st.empty()
|
| 20 |
+
|
| 21 |
+
for i in range(100):
|
| 22 |
+
progress_bar.progress(i + 1)
|
| 23 |
+
status_text.text(f"Processing... {i+1}%")
|
| 24 |
+
time.sleep(0.01)
|
| 25 |
+
|
| 26 |
+
# Process and predict
|
| 27 |
+
try:
|
| 28 |
+
# Check if the input is a file-like object or a string path
|
| 29 |
+
if isinstance(image_path, str):
|
| 30 |
+
image = Image.open(image_path).convert("RGB")
|
| 31 |
+
else:
|
| 32 |
+
image = Image.open(image_path).convert("RGB")
|
| 33 |
+
|
| 34 |
+
img_array = np.array(image.resize((img_size, img_size)))
|
| 35 |
+
img_array = np.expand_dims(img_array, axis=0)
|
| 36 |
+
img_array = img_array / 255.0
|
| 37 |
+
|
| 38 |
+
prediction = model.predict(img_array)
|
| 39 |
+
class_predicted = (prediction > 0.5).astype("int32")[0][0]
|
| 40 |
+
|
| 41 |
+
# Display the result
|
| 42 |
+
if class_predicted == 1:
|
| 43 |
+
st.error(f"Prediction: Tumor Detected (Probability: {100*prediction[0][0]:.2f}%)")
|
| 44 |
+
else:
|
| 45 |
+
st.success(f"Prediction: No Tumor Detected (Probability: {100*(1 - prediction[0][0]):.2f}%)")
|
| 46 |
+
except Exception as e:
|
| 47 |
+
st.error(f"An error occurred during classification: {e}")
|
| 48 |
+
|
| 49 |
+
# Clear the progress bar
|
| 50 |
+
progress_bar.empty()
|
| 51 |
+
status_text.empty()
|
| 52 |
+
|
| 53 |
+
# Streamlit UI
|
| 54 |
+
st.title("Brain Tumor MRI Classification App")
|
| 55 |
+
st.write("Upload your own image to get a prediction.")
|
| 56 |
+
|
| 57 |
+
# Load the model
|
| 58 |
+
model = load_vgg_model()
|
| 59 |
+
|
| 60 |
+
# Define image size (must match the model's input size)
|
| 61 |
+
img_size = 150
|
| 62 |
+
|
| 63 |
+
# --- UI for user image upload ---
|
| 64 |
+
st.subheader("Upload Your Own Image")
|
| 65 |
+
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
| 66 |
+
|
| 67 |
+
if uploaded_file is not None:
|
| 68 |
+
st.image(uploaded_file, caption='Uploaded MRI Scan', use_container_width=True)
|
| 69 |
+
|
| 70 |
+
# Use a button to trigger the classification explicitly
|
| 71 |
+
if st.button("Check for Brain Tumor"):
|
| 72 |
+
run_prediction(uploaded_file, model, img_size)
|
brain_tumor_vgg16_model.keras
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:bd437d9296b98e0061c857e29407a19f08404a926f9a15c952e1a86b27bd8673
|
| 3 |
+
size 84226863
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
numpy==2.0.2
|
| 2 |
+
tensorflow==2.20.0
|
| 3 |
+
streamlit==1.49.1
|
| 4 |
+
pillow==11.3.0
|
| 5 |
+
requests==2.32.5
|