Amanuel-Ni commited on
Commit
5997262
·
verified ·
1 Parent(s): 93e1494

Upload dataset_viz.py

Browse files
Files changed (1) hide show
  1. dataset_viz.py +50 -0
dataset_viz.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import os
3
+ from PIL import Image
4
+ import random
5
+
6
+ # Dataset directory (update this path as needed)
7
+ DATASET_DIR = "Dataset_final/test"
8
+
9
+ # Mapping numeric folder names to emotion labels
10
+ emotion_labels = {
11
+ "1": "Surprise",
12
+ "2": "Disgust",
13
+ "3": "Happiness",
14
+ "4": "Sadness",
15
+ "5": "Anger",
16
+ "6": "Neutral"
17
+ }
18
+
19
+ def show_sample_images_page():
20
+ st.title("Face Emotion Dataset Visualization")
21
+
22
+ # Slider to control number of images per emotion
23
+ num_images = st.slider("Number of images to display per emotion:", min_value=1, max_value=20, value=5)
24
+
25
+ # Check dataset path
26
+ if not os.path.isdir(DATASET_DIR):
27
+ st.error(f"Dataset path '{DATASET_DIR}' not found.")
28
+ else:
29
+ # Only process folders that are in the defined emotion_labels
30
+ valid_folders = [f for f in os.listdir(DATASET_DIR) if f in emotion_labels]
31
+
32
+ if not valid_folders:
33
+ st.warning("No valid emotion folders (1–6) found in the dataset directory.")
34
+ else:
35
+ for folder in sorted(valid_folders):
36
+ emotion_name = emotion_labels[folder]
37
+ emotion_path = os.path.join(DATASET_DIR, folder)
38
+ image_files = [f for f in os.listdir(emotion_path) if f.lower().endswith(('.png', '.jpg', '.jpeg'))]
39
+
40
+ st.subheader(f"{emotion_name} ({len(image_files)} images)")
41
+ selected_images = random.sample(image_files, min(num_images, len(image_files)))
42
+
43
+ cols = st.columns(min(5, len(selected_images)))
44
+ for i, img_file in enumerate(selected_images):
45
+ img_path = os.path.join(emotion_path, img_file)
46
+ try:
47
+ image = Image.open(img_path)
48
+ cols[i % len(cols)].image(image, use_container_width = True, caption=img_file)
49
+ except Exception as e:
50
+ st.error(f"Failed to load {img_path}: {e}")