omm7 commited on
Commit
362d662
·
verified ·
1 Parent(s): 109ec9c

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. Dockerfile +7 -15
  2. app.py +22 -61
Dockerfile CHANGED
@@ -1,22 +1,14 @@
 
1
  FROM python:3.9-slim
2
 
3
- # Create a non-root user
4
- RUN adduser --disabled-password --gecos '' streamlit-user
5
-
6
  WORKDIR /app
7
 
 
8
  COPY . .
9
 
10
- # Set Streamlit's config directory to the current working directory
11
- ENV STREAMLIT_SERVER_CONFIG_FILE=/app/.streamlit/config.toml
12
-
13
- # Add the user's local bin directory to the PATH
14
- ENV PATH="/home/streamlit-user/.local/bin:$PATH"
15
-
16
- # Install dependencies as the non-root user
17
- USER streamlit-user
18
- RUN pip3 install --no-cache-dir -r requirements.txt
19
-
20
- EXPOSE 8080
21
 
22
- CMD ["streamlit", "run", "app.py", "--server.port=8080", "--server.address=0.0.0.0"]
 
 
1
+ # Use a minimal base image with Python
2
  FROM python:3.9-slim
3
 
4
+ # Set the working directory
 
 
5
  WORKDIR /app
6
 
7
+ # Copy all files from the local directory to the container
8
  COPY . .
9
 
10
+ # Install dependencies
11
+ RUN pip install --no-cache-dir -r requirements.txt
 
 
 
 
 
 
 
 
 
12
 
13
+ # Run the Streamlit app
14
+ CMD ["streamlit", "run", "app.py"]
app.py CHANGED
@@ -2,12 +2,8 @@ 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 sys
7
- import platform
8
- import subprocess
9
 
10
- # Add a function to load the model
11
  @st.cache_resource
12
  def load_vgg_model():
13
  return load_model("brain_tumor_vgg16_model.keras")
@@ -16,63 +12,28 @@ def load_vgg_model():
16
  st.title("Brain Tumor MRI Classification App")
17
  st.write("Upload a brain MRI scan to check if it contains a tumor.")
18
 
19
- # --- DEBUGGING INFORMATION ---
20
- st.header("Debugging Information")
21
 
22
- # Check current working directory
23
- st.write(f"Current working directory: {os.getcwd()}")
24
 
25
- # List files in the directory
26
- st.write("Files in /app:")
27
- for file in os.listdir("."):
28
- st.write(f"- {file}")
29
 
30
- # Display Python and library versions
31
- st.write("Python version:", sys.version)
32
- st.write("Numpy version:", np.__version__)
33
- st.write("TensorFlow version:", tf.__version__)
34
- st.write("Pillow version:", Image.__version__)
35
-
36
- # Display environment variables
37
- st.write("Environment Variables:")
38
- for key, value in os.environ.items():
39
- st.write(f"- {key}: {value}")
40
-
41
- # --- END DEBUGGING INFORMATION ---
42
-
43
- # Try to load the model and display success/failure
44
- try:
45
- with st.spinner('Loading model...'):
46
- model = load_vgg_model()
47
- st.success("Model loaded successfully.")
48
-
49
- # Define image size (must match the model's input size)
50
  img_size = 150
51
-
52
- # UI for image upload
53
- uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
54
-
55
- if uploaded_file is not None:
56
- # Display the uploaded image
57
- image = Image.open(uploaded_file).convert("RGB")
58
- st.image(image, caption='Uploaded MRI Scan', use_column_width=True)
59
- st.write("")
60
- st.write("Classifying...")
61
-
62
- # Preprocess the image for the model
63
- img_array = np.array(image.resize((img_size, img_size)))
64
- img_array = np.expand_dims(img_array, axis=0)
65
- img_array = img_array / 255.0
66
-
67
- # Make prediction
68
- prediction = model.predict(img_array)
69
- class_predicted = (prediction > 0.5).astype("int32")[0][0]
70
-
71
- # Display the result
72
- if class_predicted == 1:
73
- st.error("Prediction: Tumor Detected")
74
- else:
75
- st.success("Prediction: No Tumor Detected")
76
-
77
- except Exception as e:
78
- st.error(f"Failed to load or use the model. Error: {e}")
 
2
  import numpy as np
3
  from PIL import Image
4
  from tensorflow.keras.models import load_model
 
 
 
 
5
 
6
+ # Load the trained VGG16 model
7
  @st.cache_resource
8
  def load_vgg_model():
9
  return load_model("brain_tumor_vgg16_model.keras")
 
12
  st.title("Brain Tumor MRI Classification App")
13
  st.write("Upload a brain MRI scan to check if it contains a tumor.")
14
 
15
+ # Load the model outside the prediction block to prevent reloading on every interaction
16
+ model = load_vgg_model()
17
 
18
+ uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
 
19
 
20
+ if uploaded_file is not None:
21
+ # Display the uploaded image
22
+ image = Image.open(uploaded_file).convert("RGB")
23
+ st.image(image, caption='Uploaded MRI Scan', use_column_width=True)
24
 
25
+ # Preprocess the image for the model
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  img_size = 150
27
+ img_array = np.array(image.resize((img_size, img_size)))
28
+ img_array = np.expand_dims(img_array, axis=0)
29
+ img_array = img_array / 255.0
30
+
31
+ # Make prediction
32
+ prediction = model.predict(img_array)
33
+ class_predicted = (prediction > 0.5).astype("int32")[0][0]
34
+
35
+ # Display the result
36
+ if class_predicted == 1:
37
+ st.error("Prediction: Tumor Detected")
38
+ else:
39
+ st.success("Prediction: No Tumor Detected")