Spaces:
Sleeping
Sleeping
ariankhalfani
commited on
Commit
•
48dc356
1
Parent(s):
a9d5577
Update app.py
Browse files
app.py
CHANGED
@@ -50,15 +50,14 @@ def diagnose_image(image, model, input_shape):
|
|
50 |
result_text = f"Probability of glaucoma: {glaucoma_probability:.2%}"
|
51 |
|
52 |
img_display = np.array(image)
|
53 |
-
if img_display.shape[2] == 1: # Convert to RGB for display
|
54 |
-
img_display = cv2.cvtColor(img_display
|
55 |
image_pil = Image.fromarray(img_display)
|
56 |
draw = ImageDraw.Draw(image_pil)
|
57 |
font = ImageFont.load_default()
|
58 |
|
59 |
text = f"{glaucoma_probability:.2%}"
|
60 |
-
|
61 |
-
text_size = (text_bbox[2] - text_bbox[0], text_bbox[3] - text_bbox[1])
|
62 |
|
63 |
rect_width = 200
|
64 |
rect_height = 100
|
@@ -77,7 +76,7 @@ def diagnose_image(image, model, input_shape):
|
|
77 |
def main():
|
78 |
with gr.Blocks() as demo:
|
79 |
gr.Markdown("# Glaucoma Detection App")
|
80 |
-
gr.Markdown("Upload
|
81 |
|
82 |
with gr.Row():
|
83 |
model_file = gr.File(label="Upload Model (.h5 or .keras)")
|
@@ -98,7 +97,8 @@ def main():
|
|
98 |
input_shape = gr.State(None)
|
99 |
|
100 |
def diagnose_and_display(image, model, input_shape):
|
101 |
-
|
|
|
102 |
|
103 |
load_model_btn.click(fn=load_and_display_model_info, inputs=model_file, outputs=[model, model_info, input_shape])
|
104 |
submit_btn.click(fn=diagnose_and_display, inputs=[image, model, input_shape], outputs=[image, result])
|
|
|
50 |
result_text = f"Probability of glaucoma: {glaucoma_probability:.2%}"
|
51 |
|
52 |
img_display = np.array(image)
|
53 |
+
if len(img_display.shape) == 2 or img_display.shape[2] == 1: # Convert to RGB for display
|
54 |
+
img_display = cv2.cvtColor(img_display, cv2.COLOR_GRAY2RGB)
|
55 |
image_pil = Image.fromarray(img_display)
|
56 |
draw = ImageDraw.Draw(image_pil)
|
57 |
font = ImageFont.load_default()
|
58 |
|
59 |
text = f"{glaucoma_probability:.2%}"
|
60 |
+
text_size = draw.textsize(text, font=font)
|
|
|
61 |
|
62 |
rect_width = 200
|
63 |
rect_height = 100
|
|
|
76 |
def main():
|
77 |
with gr.Blocks() as demo:
|
78 |
gr.Markdown("# Glaucoma Detection App")
|
79 |
+
gr.Markdown("Upload a fundus eye image to detect the probability of glaucoma.")
|
80 |
|
81 |
with gr.Row():
|
82 |
model_file = gr.File(label="Upload Model (.h5 or .keras)")
|
|
|
97 |
input_shape = gr.State(None)
|
98 |
|
99 |
def diagnose_and_display(image, model, input_shape):
|
100 |
+
diagnosis_image, result_text = diagnose_image(image, model, input_shape)
|
101 |
+
return diagnosis_image, result_text
|
102 |
|
103 |
load_model_btn.click(fn=load_and_display_model_info, inputs=model_file, outputs=[model, model_info, input_shape])
|
104 |
submit_btn.click(fn=diagnose_and_display, inputs=[image, model, input_shape], outputs=[image, result])
|