tayawelba commited on
Commit
33d6a22
·
verified ·
1 Parent(s): 1235d0b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -37
app.py CHANGED
@@ -37,7 +37,7 @@ with tab1:
37
  components.html(
38
  """
39
  <div style="position: fixed; bottom: 0; left: 0; right: 0; text-align: center; font-size: 15px; color: gray;">
40
- Tous droits réservés © Décembre 2023 Tayawelba Dawaï Hesed
41
  </div>
42
  """,
43
  height=50
@@ -49,53 +49,41 @@ with tab2:
49
  st.header("Prédiction")
50
  #st.markdown("<h1 style='text-align: center;'>Prédiction</h1>", unsafe_allow_html=True)
51
  st.sidebar.header("Paramètre pour la prédiction")
52
- num_images = st.sidebar.number_input("Nombre d'images à prédire", min_value=1, max_value=10, value=1)
53
- upload_files = st.sidebar.file_uploader("Télécharger les fichiers", type=['jpg', 'jpeg', 'png'], accept_multiple_files=True, key="upload")
54
  generate_pred = st.sidebar.button("Predict")
55
 
56
  # Main
57
- if upload_files:
58
- # Check if the number of uploaded files matches the number input
59
- if len(upload_files) != num_images:
60
- st.error(f"Veuillez télécharger exactement {num_images} image(s).")
61
- else:
62
- # Display uploaded images
63
- st.header("Images téléchargées")
64
- cols = st.columns(num_images)
65
- for i, file in enumerate(upload_files):
66
- cols[i].image(file, caption=f"Image {i+1}", use_column_width=True)
67
-
68
- # Predict labels
69
- if generate_pred:
70
- # Preprocess images
71
- test_images = [image.load_img(file, target_size=(64, 64)) for file in upload_files]
72
- image_arrays = [img_to_array(img) for img in test_images]
73
- image_arrays = np.array(image_arrays)
74
-
75
- # Make predictions
76
- predictions = model.predict(image_arrays)
77
- classes = np.argmax(predictions, axis=1)
78
- labels = [key for key, value in covid_classes.items() if value in classes]
79
-
80
- # Display results in a table
81
- st.header("Résultats de la prédiction")
82
- table_data = []
83
- for i, (file, label) in enumerate(zip(upload_files, labels)):
84
- # Resize image for table display
85
- img = Image.open(file)
86
- img = img.resize((64, 64))
87
- table_data.append([f"Image {i+1}", label])
88
- st.table(table_data)
89
 
90
  components.html(
91
  """
92
  <div style="position: fixed; bottom: 0; left: 0; right: 0; text-align: center; font-size: 15px; color: gray;">
93
- Tous droits réservés © Décembre 2023 Tayawelba Dawaï Hesed
94
  </div>
95
  """,
96
  height=70
97
  )
98
 
 
99
  with tab3:
100
  # Définir les informations de contact
101
  name = "TAYAWELBA DAWAI Hesed"
@@ -121,7 +109,7 @@ with tab3:
121
  components.html(
122
  """
123
  <div style="position: fixed; bottom: 0; left: 0; right: 0; text-align: center; font-size: 15px; color: gray;">
124
- Tous droits réservés © Décembre 2023 Tayawelba Dawaï Hesed
125
  </div>
126
  """,
127
  height=20
 
37
  components.html(
38
  """
39
  <div style="position: fixed; bottom: 0; left: 0; right: 0; text-align: center; font-size: 15px; color: gray;">
40
+ Tous droits réservés © Février 2024 Tayawelba Dawaï Hesed
41
  </div>
42
  """,
43
  height=50
 
49
  st.header("Prédiction")
50
  #st.markdown("<h1 style='text-align: center;'>Prédiction</h1>", unsafe_allow_html=True)
51
  st.sidebar.header("Paramètre pour la prédiction")
52
+ upload_file = st.sidebar.file_uploader("Télécharger le fichier", type=['jpg', 'jpeg', 'png'], key="upload")
 
53
  generate_pred = st.sidebar.button("Predict")
54
 
55
  # Main
56
+ if upload_file:
57
+ # Display uploaded image
58
+ st.header("Image téléchargée")
59
+ st.image(upload_file, caption="Image", use_column_width=True)
60
+
61
+ # Predict label
62
+ if generate_pred:
63
+ # Preprocess image
64
+ test_image = image.load_img(upload_file, target_size=(64, 64))
65
+ image_array = img_to_array(test_image)
66
+ image_array = np.expand_dims(image_array, axis=0)
67
+
68
+ # Make prediction
69
+ prediction = model.predict(image_array)
70
+ classe = np.argmax(prediction, axis=1)
71
+ label = [key for key, value in covid_classes.items() if value == classe][0]
72
+
73
+ # Display result
74
+ st.header("Résultat de la prédiction")
75
+ st.write(f"L'image est classée comme {label}.")
 
 
 
 
 
 
 
 
 
 
 
 
76
 
77
  components.html(
78
  """
79
  <div style="position: fixed; bottom: 0; left: 0; right: 0; text-align: center; font-size: 15px; color: gray;">
80
+ Tous droits réservés © Février 2024 Tayawelba Dawaï Hesed
81
  </div>
82
  """,
83
  height=70
84
  )
85
 
86
+
87
  with tab3:
88
  # Définir les informations de contact
89
  name = "TAYAWELBA DAWAI Hesed"
 
109
  components.html(
110
  """
111
  <div style="position: fixed; bottom: 0; left: 0; right: 0; text-align: center; font-size: 15px; color: gray;">
112
+ Tous droits réservés © Février 2024 Tayawelba Dawaï Hesed
113
  </div>
114
  """,
115
  height=20