yassonee commited on
Commit
07f59cf
·
verified ·
1 Parent(s): a5a28e8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -48
app.py CHANGED
@@ -1,65 +1,33 @@
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': pipeline("image-classification", model="stanfordaimi/fracture-detection-vit"),
11
- 'Pneumothorax': pipeline("image-classification", model="ahmedos/pneumothorax-detection"),
12
- 'Pneumonie': pipeline("image-classification", model="ahmedos/pneumonia-detection")
13
- }
14
- return models
15
 
16
  @st.cache_resource
17
- def get_models():
18
- return load_models()
19
 
20
  def main():
21
- st.title("Assistant de diagnostic radiologique")
22
 
23
- with st.spinner("Chargement des modèles..."):
24
- models = get_models()
25
 
26
- uploaded_file = st.file_uploader("Télécharger une image radiologique", type=["jpg", "jpeg", "png"])
27
 
28
  if uploaded_file:
29
  image = Image.open(uploaded_file)
30
- st.image(image, caption="Image téléchargée", use_column_width=True)
31
-
32
- col1, col2, col3 = st.columns(3)
33
-
34
- with col1:
35
- if st.button("Détecter Fracture"):
36
- with st.spinner("Analyse en cours..."):
37
- try:
38
- result = models['Fracture'](image)
39
- st.write(f"Résultat: {result[0]['label']}")
40
- st.write(f"Confiance: {result[0]['score']:.2%}")
41
- except Exception as e:
42
- st.error(f"Erreur: {str(e)}")
43
-
44
- with col2:
45
- if st.button("Détecter Pneumothorax"):
46
- with st.spinner("Analyse en cours..."):
47
- try:
48
- result = models['Pneumothorax'](image)
49
- st.write(f"Résultat: {result[0]['label']}")
50
- st.write(f"Confiance: {result[0]['score']:.2%}")
51
- except Exception as e:
52
- st.error(f"Erreur: {str(e)}")
53
 
54
- with col3:
55
- if st.button("Détecter Pneumonie"):
56
- with st.spinner("Analyse en cours..."):
57
- try:
58
- result = models['Pneumonie'](image)
59
- st.write(f"Résultat: {result[0]['label']}")
60
- st.write(f"Confiance: {result[0]['score']:.2%}")
61
- except Exception as e:
62
- st.error(f"Erreur: {str(e)}")
63
 
64
  if __name__ == "__main__":
65
  main()
 
1
  import streamlit as st
2
+ from transformers import AutoImageProcessor, AutoModelForImageClassification, pipeline
3
  from PIL import Image
4
  import torch
5
 
6
+ st.set_page_config(page_title="Détection de fractures", layout="wide")
 
 
 
 
 
 
 
 
7
 
8
  @st.cache_resource
9
+ def load_model():
10
+ return pipeline("image-classification", model="Heem2/bone-fracture-detection-using-xray")
11
 
12
  def main():
13
+ st.title("Détection de fractures osseuses")
14
 
15
+ model = load_model()
 
16
 
17
+ uploaded_file = st.file_uploader("Télécharger une radiographie", type=["jpg", "jpeg", "png"])
18
 
19
  if uploaded_file:
20
  image = Image.open(uploaded_file)
21
+ st.image(image, caption="Radiographie", use_column_width=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
+ if st.button("Analyser"):
24
+ with st.spinner("Analyse en cours..."):
25
+ try:
26
+ result = model(image)
27
+ st.write(f"Résultat: {result[0]['label']}")
28
+ st.write(f"Confiance: {result[0]['score']:.2%}")
29
+ except Exception as e:
30
+ st.error(f"Erreur: {str(e)}")
 
31
 
32
  if __name__ == "__main__":
33
  main()