CoolFace
Apppublic

Sebahadin1234/Facial_Expression_Recognition_Deep_Learning

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
dataset_viz.py50 linesDownload Raw Back to root
1import streamlit as st2import os3from PIL import Image4import random5 6# Dataset directory (update this path as needed)7DATASET_DIR = "Dataset_final/test"8 9# Mapping numeric folder names to emotion labels10emotion_labels = {11    "1": "Surprise",12    "2": "Disgust",13    "3": "Happiness",14    "4": "Sadness",15    "5": "Anger",16    "6": "Neutral"17}18 19def show_sample_images_page():20    st.title("Face Emotion Dataset Visualization")21 22    # Slider to control number of images per emotion23    num_images = st.slider("Number of images to display per emotion:", min_value=1, max_value=20, value=5)24 25    # Check dataset path26    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_labels30        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, caption=img_file)49                    except Exception as e:50                        st.error(f"Failed to load {img_path}: {e}")