Update app.py
Browse files
app.py
CHANGED
@@ -17,25 +17,18 @@ def load_model():
|
|
17 |
|
18 |
model = load_model()
|
19 |
|
20 |
-
def enhance_image(img):
|
21 |
-
img_array = np.array(img)
|
22 |
-
gray = cv2.cvtColor(img_array, cv2.COLOR_RGB2GRAY)
|
23 |
-
clahe = cv2.createCLAHE(clipLimit=3.0, tileGridSize=(8,8))
|
24 |
-
enhanced = clahe.apply(gray)
|
25 |
-
return cv2.cvtColor(enhanced, cv2.COLOR_GRAY2RGB)
|
26 |
-
|
27 |
uploaded_file = st.file_uploader("Téléchargez une image radiographique", type=["jpg", "jpeg", "png"])
|
28 |
|
29 |
if uploaded_file:
|
|
|
30 |
image = Image.open(uploaded_file).convert('RGB')
|
31 |
if image.size[0] > 800:
|
32 |
ratio = 800.0 / image.size[0]
|
33 |
size = (800, int(image.size[1] * ratio))
|
34 |
image = image.resize(size, Image.Resampling.LANCZOS)
|
35 |
|
36 |
-
|
37 |
-
|
38 |
-
predictions = model(enhanced_image)
|
39 |
|
40 |
col1, col2 = st.columns(2)
|
41 |
|
@@ -43,26 +36,20 @@ if uploaded_file:
|
|
43 |
st.image(image, caption="Image originale", use_container_width=True)
|
44 |
|
45 |
with col2:
|
46 |
-
|
47 |
for pred in predictions:
|
48 |
box = pred['box']
|
49 |
score = pred['score']
|
50 |
-
|
51 |
x1, y1, x2, y2 = [int(i) for i in [box['xmin'], box['ymin'], box['xmax'], box['ymax']]]
|
52 |
-
cv2.rectangle(
|
53 |
-
|
54 |
text = f"Fracture: {score:.2f}"
|
55 |
-
cv2.putText(
|
56 |
-
cv2.FONT_HERSHEY_SIMPLEX, 0.7, (255, 0, 0), 2)
|
57 |
|
58 |
-
st.image(
|
59 |
|
60 |
-
st.subheader("Résultats")
|
61 |
if predictions:
|
|
|
62 |
for idx, pred in enumerate(predictions, 1):
|
63 |
-
st.warning(f"
|
64 |
else:
|
65 |
-
st.warning("⚠️ Aucune fracture
|
66 |
-
|
67 |
-
else:
|
68 |
-
st.info("Veuillez télécharger une image radiographique pour l'analyse.")
|
|
|
17 |
|
18 |
model = load_model()
|
19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
uploaded_file = st.file_uploader("Téléchargez une image radiographique", type=["jpg", "jpeg", "png"])
|
21 |
|
22 |
if uploaded_file:
|
23 |
+
# Convert uploaded file to PIL Image
|
24 |
image = Image.open(uploaded_file).convert('RGB')
|
25 |
if image.size[0] > 800:
|
26 |
ratio = 800.0 / image.size[0]
|
27 |
size = (800, int(image.size[1] * ratio))
|
28 |
image = image.resize(size, Image.Resampling.LANCZOS)
|
29 |
|
30 |
+
# Pass PIL Image directly to model
|
31 |
+
predictions = model(image)
|
|
|
32 |
|
33 |
col1, col2 = st.columns(2)
|
34 |
|
|
|
36 |
st.image(image, caption="Image originale", use_container_width=True)
|
37 |
|
38 |
with col2:
|
39 |
+
img_array = np.array(image)
|
40 |
for pred in predictions:
|
41 |
box = pred['box']
|
42 |
score = pred['score']
|
|
|
43 |
x1, y1, x2, y2 = [int(i) for i in [box['xmin'], box['ymin'], box['xmax'], box['ymax']]]
|
44 |
+
cv2.rectangle(img_array, (x1, y1), (x2, y2), (255, 0, 0), 3)
|
|
|
45 |
text = f"Fracture: {score:.2f}"
|
46 |
+
cv2.putText(img_array, text, (x1, y1-10), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (255, 0, 0), 2)
|
|
|
47 |
|
48 |
+
st.image(img_array, caption="Détection des fractures", use_container_width=True)
|
49 |
|
|
|
50 |
if predictions:
|
51 |
+
st.subheader(f"🚨 {len(predictions)} fractures détectées:")
|
52 |
for idx, pred in enumerate(predictions, 1):
|
53 |
+
st.warning(f"Fracture {idx}: Confiance {pred['score']*100:.1f}%")
|
54 |
else:
|
55 |
+
st.warning("⚠️ Aucune fracture détectée")
|
|
|
|
|
|