Spaces:
Build error
Build error
import streamlit as st | |
import pandas as pd | |
from backend.utils import load_dataset, use_container_width_percentage | |
st.set_page_config(layout='wide') | |
st.title('ImageNet-1k') | |
st.markdown('This page shows the summary of 50,000 images in the validation set of [ImageNet-1k](https://huggingface.co/datasets/imagenet-1k)') | |
# SCREEN_WIDTH, SCREEN_HEIGHT = 2560, 1664 | |
with st.spinner("Loading dataset..."): | |
dataset_dict = {} | |
for data_index in range(5): | |
dataset_dict[data_index] = load_dataset(data_index) | |
imagenet_df = pd.read_csv('./data/ImageNet_metadata.csv') | |
class_labels = imagenet_df.ClassLabel.unique().tolist() | |
class_labels.sort() | |
selected_classes = st.multiselect('Class filter: ', options=['All'] + class_labels) | |
if not ('All' in selected_classes or len(selected_classes) == 0): | |
imagenet_df = imagenet_df[imagenet_df['ClassLabel'].isin(selected_classes)] | |
# st.write(class_labels) | |
col1, col2 = st.columns([2, 1]) | |
with col1: | |
st.dataframe(imagenet_df) | |
use_container_width_percentage(100) | |
with col2: | |
st.text_area('Type anything here to copy later :)') | |
image = None | |
with st.form("display image"): | |
img_index = st.text_input('Image ID to display') | |
submitted = st.form_submit_button('Display this image') | |
error_container = st.empty() | |
if submitted: | |
try: | |
img_index = int(img_index) | |
if img_index > 50000-1 or img_index < 0: | |
error_container.error('The Image ID must be in range from 0 to 49999', icon="π«") | |
else: | |
image = dataset_dict[img_index//10_000][img_index%10_000]['image'] | |
class_label = dataset_dict[img_index//10_000][img_index%10_000]['label'] | |
class_id = dataset_dict[img_index//10_000][img_index%10_000]['id'] | |
except ValueError: | |
error_container.error('Please enter an integer number for Image ID', icon = "π«") | |
if image != None: | |
st.image(image) | |
st.write('**Class label:** ', class_label) | |
st.write('\n**Class id:** ', str(class_id)) |