Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -101,3 +101,56 @@ with tab1:
|
|
101 |
file_name=f"Diabetic_Retinopathy_Report_{patient_name.replace(' ', '_')}.pdf",
|
102 |
mime='application/octet-stream'
|
103 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
file_name=f"Diabetic_Retinopathy_Report_{patient_name.replace(' ', '_')}.pdf",
|
102 |
mime='application/octet-stream'
|
103 |
)
|
104 |
+
|
105 |
+
with tab2:
|
106 |
+
st.write("### Capture an image using your camera")
|
107 |
+
|
108 |
+
# Capture image from camera
|
109 |
+
camera_image = st.camera_input("Take a picture")
|
110 |
+
|
111 |
+
if camera_image is not None:
|
112 |
+
# Open and display the captured image
|
113 |
+
image = Image.open(camera_image)
|
114 |
+
|
115 |
+
# Preprocess the image
|
116 |
+
img_array = preprocess_image(image)
|
117 |
+
|
118 |
+
# Prepare inputs for model
|
119 |
+
img_array_pair = [img_array, img_array] # Model expects two inputs
|
120 |
+
|
121 |
+
# Make prediction
|
122 |
+
predictions = model.predict(img_array_pair)[0]
|
123 |
+
|
124 |
+
# Convert predictions to percentages
|
125 |
+
prediction_percentages = predictions * 100
|
126 |
+
|
127 |
+
# Find the class with the highest probability
|
128 |
+
highest_index = np.argmax(prediction_percentages)
|
129 |
+
predicted_class = class_labels[highest_index]
|
130 |
+
|
131 |
+
# Display the image and predictions
|
132 |
+
col1, col2 = st.columns([1, 2]) # Set the width ratio between columns
|
133 |
+
|
134 |
+
# Display image in the first column
|
135 |
+
with col1:
|
136 |
+
st.image(image, caption='Captured Image', width=150)
|
137 |
+
|
138 |
+
# Display the predictions in the second column
|
139 |
+
with col2:
|
140 |
+
st.write(f"### Predicted Level: **{predicted_class}**")
|
141 |
+
|
142 |
+
st.write("### Prediction Results")
|
143 |
+
for i, label in enumerate(class_labels):
|
144 |
+
st.progress(int(prediction_percentages[i]))
|
145 |
+
st.write(f"{label}: {prediction_percentages[i]:.2f}%")
|
146 |
+
|
147 |
+
# Create and download PDF report
|
148 |
+
pdf_output = create_pdf(patient_name, patient_age, predicted_class, prediction_percentages)
|
149 |
+
|
150 |
+
# Button to download the PDF
|
151 |
+
st.download_button(
|
152 |
+
label="Download Report",
|
153 |
+
data=pdf_output,
|
154 |
+
file_name=f"Diabetic_Retinopathy_Report_{patient_name.replace(' ', '_')}.pdf",
|
155 |
+
mime='application/octet-stream'
|
156 |
+
)
|