itsanmolgupta commited on
Commit
8b240a6
·
verified ·
1 Parent(s): 6191631

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -16
app.py CHANGED
@@ -5,7 +5,7 @@ from PIL import Image
5
  import io
6
 
7
  # Load your pre-trained model
8
- model = tf.keras.models.load_model('model.keras')
9
 
10
  # Define the image preprocessing function
11
  # Define the image preprocessing function
@@ -27,17 +27,19 @@ class_labels = ['Atelectasis', 'Cardiomegaly', 'Consolidation', 'Edema', 'Effusi
27
  # class_labels = ["Class1", "Class2", "Class3", "Class4", "Class5"] # Update with actual class names
28
 
29
  # Streamlit app
30
- st.title("Image Classification with Grad-CAM")
31
-
32
- st.write("Upload an image to get predictions:")
33
 
34
  # Upload image
35
- uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
 
 
 
36
 
37
  if uploaded_file is not None:
38
  # Read and display the image
39
  image = Image.open(uploaded_file)
40
- st.image(image, caption='Uploaded Image', use_column_width=True)
 
41
 
42
  # Preprocess the image
43
  preprocessed_image = preprocess_image(image)
@@ -49,13 +51,13 @@ if uploaded_file is not None:
49
  top_predictions = [(label, prob) for label, prob in zip(class_labels, predictions) if prob > 0.5]
50
  top_predictions = sorted(top_predictions, key=lambda x: x[1], reverse=True)[:3]
51
 
52
- # Display results
53
- st.write("Predictions with probability greater than 0.5:")
54
- for label, prob in top_predictions:
55
- st.write(f"{label}: {prob*100:.2f}%")
56
- percentage = int(prob * 100)
57
- # st.progress(prob)
58
- st.progress(percentage)
59
-
60
- if not top_predictions:
61
- st.write("No predictions with probability greater than 0.5.")
 
5
  import io
6
 
7
  # Load your pre-trained model
8
+ model = tf.keras.models.load_model('model_2.keras')
9
 
10
  # Define the image preprocessing function
11
  # Define the image preprocessing function
 
27
  # class_labels = ["Class1", "Class2", "Class3", "Class4", "Class5"] # Update with actual class names
28
 
29
  # Streamlit app
30
+ st.title("Chest X-ray Classification")
 
 
31
 
32
  # Upload image
33
+ uploaded_file = st.file_uploader("Upload a Chest X-ray image...", type=["jpg", "jpeg", "png"])
34
+
35
+ # Create two columns
36
+ col1, col2 = st.columns(2)
37
 
38
  if uploaded_file is not None:
39
  # Read and display the image
40
  image = Image.open(uploaded_file)
41
+ with col1:
42
+ st.image(image, caption='Uploaded Image', use_column_width=True)
43
 
44
  # Preprocess the image
45
  preprocessed_image = preprocess_image(image)
 
51
  top_predictions = [(label, prob) for label, prob in zip(class_labels, predictions) if prob > 0.5]
52
  top_predictions = sorted(top_predictions, key=lambda x: x[1], reverse=True)[:3]
53
 
54
+ with col2:
55
+ # Display results
56
+ if not top_predictions:
57
+ st.write("No any diseases found with probability greater than 50%.")
58
+ else:
59
+ st.write("Predicted Disease(s):")
60
+ for label, prob in top_predictions:
61
+ st.write(f"{label}: {prob*100:.2f}%")
62
+ percentage = int(prob * 100)
63
+ st.progress(percentage)