Malik Sahab commited on
Commit
626eea0
1 Parent(s): 23d4f4b

GUI Finalized

Browse files
Files changed (1) hide show
  1. app.py +22 -10
app.py CHANGED
@@ -23,7 +23,7 @@ def predict_single_image(image_path, model, target_size=(128, 128)):
23
  # display(probabilities)
24
 
25
  # Determine the predicted class label
26
- predicted_class = "positive" if probabilities[0][0] > 0.5 else "negative"
27
 
28
  return predicted_class, probabilities[0][0]
29
 
@@ -38,23 +38,35 @@ def classify_lung_cancer(img):
38
  # Print the prediction
39
  # print('Predicted Label:', predicted_label)
40
  # print('Confidence:', confidence)
41
- return f"Prediction: {predicted_label}\n(Confidence: {confidence:.2f})"
 
 
42
 
43
 
44
  # Streamlit app
45
  st.title("Lung Cancer Classification")
46
  st.write(
47
- "Upload an image and the model will classify it as positive or negative for lung cancer."
48
  )
49
 
 
50
  uploaded_image = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
51
 
52
- if uploaded_image is not None:
53
- # Display the uploaded image
54
- st.image(uploaded_image, caption="Uploaded Image.", use_column_width=True)
55
-
56
- # Classify the uploaded image
57
- if st.button("Classify"):
58
  predicted_label, confidence = classify_lung_cancer(uploaded_image)
59
- st.write(f"Prediction: {predicted_label}")
 
 
 
 
 
 
 
 
 
 
60
  st.write(f"Confidence: {confidence:.2f}")
 
 
 
23
  # display(probabilities)
24
 
25
  # Determine the predicted class label
26
+ predicted_class = "POSITIVE" if probabilities[0][0] > 0.5 else "NEGATIVE"
27
 
28
  return predicted_class, probabilities[0][0]
29
 
 
38
  # Print the prediction
39
  # print('Predicted Label:', predicted_label)
40
  # print('Confidence:', confidence)
41
+ if confidence < 0.5:
42
+ confidence = abs(1 - confidence)
43
+ return (predicted_label, confidence)
44
 
45
 
46
  # Streamlit app
47
  st.title("Lung Cancer Classification")
48
  st.write(
49
+ "Upload an image and click 'Classify' to predict if it's positive or negative for lung cancer."
50
  )
51
 
52
+ # Display the uploaded image
53
  uploaded_image = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
54
 
55
+ # Classify the uploaded image
56
+ if st.button("Classify"):
57
+ if uploaded_image is not None:
 
 
 
58
  predicted_label, confidence = classify_lung_cancer(uploaded_image)
59
+
60
+ # Style the prediction text
61
+ if predicted_label == "POSITIVE":
62
+ prediction_style = "color: red; font-size: 24px; text-transform: uppercase; border: 2px solid red;"
63
+ else:
64
+ prediction_style = "color: green; font-size: 24px; text-transform: uppercase; border: 2px solid green;"
65
+
66
+ st.markdown(
67
+ f"<p style='{prediction_style}'>Prediction: {predicted_label}</p>",
68
+ unsafe_allow_html=True,
69
+ )
70
  st.write(f"Confidence: {confidence:.2f}")
71
+ st.progress(int(confidence * 100))
72
+ st.image(uploaded_image, caption="Uploaded Image.", use_column_width=True)