xtlyxt commited on
Commit
8aa40c0
·
verified ·
1 Parent(s): c2824a3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -11
app.py CHANGED
@@ -16,25 +16,21 @@ st.title("Emotion Recognition with vit-face-expression")
16
  # Upload images
17
  uploaded_images = st.file_uploader("Upload images", type=["jpg", "png"], accept_multiple_files=True)
18
 
 
 
 
19
  # Display thumbnail images alongside file names and sizes in the sidebar
20
  selected_images = []
21
-
22
  if uploaded_images:
23
-
24
- # Add a "Select All" checkbox in the sidebar
25
- #select_all = st.sidebar.checkbox("Select All", False)
26
-
27
  for idx, img in enumerate(uploaded_images):
28
  image = Image.open(img)
29
  checkbox_key = f"{img.name}_checkbox_{idx}" # Unique key for each checkbox
30
  # Display thumbnail image and checkbox in sidebar
31
  st.sidebar.image(image, caption=f"{img.name} {img.size / 1024.0:.1f} KB", width=40)
32
  selected = st.sidebar.checkbox(f"Select {img.name}", value=False, key=checkbox_key)
33
- # If "Select All" is checked, all individual checkboxes are selected
34
- #selected = st.sidebar.checkbox(f"Select {img.name}", value=select_all, key=checkbox_key)
35
-
36
  if selected:
37
  selected_images.append(image)
 
38
 
39
  if st.button("Predict Emotions") and selected_images:
40
  emotions = []
@@ -52,7 +48,7 @@ if st.button("Predict Emotions") and selected_images:
52
  col.image(selected_images[i], caption=f"Predicted emotion: {predicted_emotion}", use_column_width=True)
53
  col.write(f"Emotion Scores: {predicted_emotion}: {results[i][0]['score']:.4f}")
54
  # Use the index to get the corresponding filename
55
- col.write(f"Original File Name: {uploaded_images[i].name}")
56
 
57
  # Display the keys and values of all results
58
  st.write("Keys and Values of all results:")
@@ -77,7 +73,7 @@ if st.button("Predict Emotions") and selected_images:
77
  st.write(f"Emotion Scores for #{i+1} Image")
78
  st.write(f"{predicted_emotion}: {result[0]['score']:.4f}")
79
  # Use the index to get the corresponding filename
80
- st.write(f"Original File Name: {uploaded_images[i].name if i < len(uploaded_images) else 'Unknown'}")
81
 
82
  # Calculate emotion statistics
83
  emotion_counts = pd.Series(emotions).value_counts()
@@ -121,4 +117,4 @@ if st.button("Predict Emotions") and selected_images:
121
  # Add total faces to the title
122
  ax_bar.set_title(f"Emotion Distribution - Total Faces Analyzed: {total_faces}")
123
  ax_bar.yaxis.set_major_locator(plt.MaxNLocator(integer=True)) # Ensure integer ticks on Y-axis
124
- st.pyplot(fig_bar)
 
16
  # Upload images
17
  uploaded_images = st.file_uploader("Upload images", type=["jpg", "png"], accept_multiple_files=True)
18
 
19
+ # Store selected file names
20
+ selected_file_names = []
21
+
22
  # Display thumbnail images alongside file names and sizes in the sidebar
23
  selected_images = []
 
24
  if uploaded_images:
 
 
 
 
25
  for idx, img in enumerate(uploaded_images):
26
  image = Image.open(img)
27
  checkbox_key = f"{img.name}_checkbox_{idx}" # Unique key for each checkbox
28
  # Display thumbnail image and checkbox in sidebar
29
  st.sidebar.image(image, caption=f"{img.name} {img.size / 1024.0:.1f} KB", width=40)
30
  selected = st.sidebar.checkbox(f"Select {img.name}", value=False, key=checkbox_key)
 
 
 
31
  if selected:
32
  selected_images.append(image)
33
+ selected_file_names.append(img.name)
34
 
35
  if st.button("Predict Emotions") and selected_images:
36
  emotions = []
 
48
  col.image(selected_images[i], caption=f"Predicted emotion: {predicted_emotion}", use_column_width=True)
49
  col.write(f"Emotion Scores: {predicted_emotion}: {results[i][0]['score']:.4f}")
50
  # Use the index to get the corresponding filename
51
+ col.write(f"Original File Name: {selected_file_names[i]}")
52
 
53
  # Display the keys and values of all results
54
  st.write("Keys and Values of all results:")
 
73
  st.write(f"Emotion Scores for #{i+1} Image")
74
  st.write(f"{predicted_emotion}: {result[0]['score']:.4f}")
75
  # Use the index to get the corresponding filename
76
+ st.write(f"Original File Name: {selected_file_names[i] if i < len(selected_file_names) else 'Unknown'}")
77
 
78
  # Calculate emotion statistics
79
  emotion_counts = pd.Series(emotions).value_counts()
 
117
  # Add total faces to the title
118
  ax_bar.set_title(f"Emotion Distribution - Total Faces Analyzed: {total_faces}")
119
  ax_bar.yaxis.set_major_locator(plt.MaxNLocator(integer=True)) # Ensure integer ticks on Y-axis
120
+ st.pyplot(fig_bar)