Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import os
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
from PIL import Image
|
| 5 |
+
|
| 6 |
+
# Define the main dataset directory
|
| 7 |
+
DATASET_PATH = "Test dat" # Update to your actual folder path
|
| 8 |
+
|
| 9 |
+
# Function to get subfolders (digit categories 0-9)
|
| 10 |
+
def get_subfolders(path):
|
| 11 |
+
return sorted([f.name for f in Path(path).iterdir() if f.is_dir()])
|
| 12 |
+
|
| 13 |
+
# Function to get images from a selected subfolder
|
| 14 |
+
def get_images_from_folder(folder_path):
|
| 15 |
+
return sorted([f for f in Path(folder_path).glob("*.png")]) # Fixed glob pattern
|
| 16 |
+
|
| 17 |
+
# Streamlit UI
|
| 18 |
+
st.title("MNIST Image Viewer")
|
| 19 |
+
|
| 20 |
+
# Select a digit category (0-9)
|
| 21 |
+
subfolders = get_subfolders(DATASET_PATH)
|
| 22 |
+
selected_folder = st.selectbox("Select a digit:", subfolders)
|
| 23 |
+
|
| 24 |
+
# Get images from selected digit folder
|
| 25 |
+
image_files = get_images_from_folder(Path(DATASET_PATH) / selected_folder)
|
| 26 |
+
|
| 27 |
+
# Show images
|
| 28 |
+
if image_files:
|
| 29 |
+
st.write(f"Showing images from digit {selected_folder}")
|
| 30 |
+
selected_image = st.selectbox("Choose an image:", image_files)
|
| 31 |
+
|
| 32 |
+
# Convert Path object to string for opening the image
|
| 33 |
+
image = Image.open(str(selected_image))
|
| 34 |
+
st.image(image, caption=f"Digit: {selected_folder}", use_container_width=True)
|
| 35 |
+
else:
|
| 36 |
+
st.warning("No images found in this folder.")
|