Update app.py
Browse files
app.py
CHANGED
@@ -1,43 +1,59 @@
|
|
1 |
import streamlit as st
|
2 |
-
from transformers import
|
3 |
from PIL import Image
|
4 |
-
import
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
from PIL import Image
|
4 |
+
import torch
|
5 |
+
|
6 |
+
st.set_page_config(page_title="Aide au diagnostic radiologique", layout="wide")
|
7 |
+
|
8 |
+
def load_models():
|
9 |
+
models = {
|
10 |
+
'Fracture': "kathleen/vit-base-fracture-detection",
|
11 |
+
'Pneumothorax': "nickmuchi/pneumothorax-detection-vit",
|
12 |
+
'Pneumonie': "nickmuchi/chest-xray-pneumonia-detection"
|
13 |
+
}
|
14 |
+
|
15 |
+
loaded_models = {}
|
16 |
+
for name, model_id in models.items():
|
17 |
+
loaded_models[name] = pipeline("image-classification", model=model_id)
|
18 |
+
return loaded_models
|
19 |
+
|
20 |
+
@st.cache_resource
|
21 |
+
def get_models():
|
22 |
+
return load_models()
|
23 |
+
|
24 |
+
def main():
|
25 |
+
st.title("Assistant de diagnostic radiologique")
|
26 |
+
|
27 |
+
models = get_models()
|
28 |
+
|
29 |
+
uploaded_file = st.file_uploader("Télécharger une image radiologique", type=["jpg", "jpeg", "png"])
|
30 |
+
|
31 |
+
if uploaded_file:
|
32 |
+
image = Image.open(uploaded_file)
|
33 |
+
st.image(image, caption="Image téléchargée", use_column_width=True)
|
34 |
+
|
35 |
+
col1, col2, col3 = st.columns(3)
|
36 |
+
|
37 |
+
with col1:
|
38 |
+
if st.button("Détecter Fracture"):
|
39 |
+
with st.spinner("Analyse en cours..."):
|
40 |
+
result = models['Fracture'](image)
|
41 |
+
st.write(f"Résultat: {result[0]['label']}")
|
42 |
+
st.write(f"Confiance: {result[0]['score']:.2%}")
|
43 |
+
|
44 |
+
with col2:
|
45 |
+
if st.button("Détecter Pneumothorax"):
|
46 |
+
with st.spinner("Analyse en cours..."):
|
47 |
+
result = models['Pneumothorax'](image)
|
48 |
+
st.write(f"Résultat: {result[0]['label']}")
|
49 |
+
st.write(f"Confiance: {result[0]['score']:.2%}")
|
50 |
+
|
51 |
+
with col3:
|
52 |
+
if st.button("Détecter Pneumonie"):
|
53 |
+
with st.spinner("Analyse en cours..."):
|
54 |
+
result = models['Pneumonie'](image)
|
55 |
+
st.write(f"Résultat: {result[0]['label']}")
|
56 |
+
st.write(f"Confiance: {result[0]['score']:.2%}")
|
57 |
+
|
58 |
+
if __name__ == "__main__":
|
59 |
+
main()
|