Spaces:
Running
Running
import os | |
import streamlit as st | |
import matplotlib.pyplot as plt | |
# Function untuk menampilkan visualisasi jumlah data untuk setiap class | |
def visual_path(path): | |
labels = os.listdir(path) | |
label_names = [] | |
num_data = [] | |
for label in labels: | |
# Skip jika nama direktori dimulai dengan .DS_Store | |
if label.startswith('.DS_Store'): | |
continue | |
label_names.append(label) | |
num_data.append(len(os.listdir(os.path.join(path, label)))) | |
# Membuat plot bar | |
plt.figure(figsize=(10, 6)) | |
plt.bar(label_names, num_data, color='skyblue') | |
plt.xlabel('Label') | |
plt.ylabel('Number of Data') | |
plt.title(f'Number of Data for Each Label in {os.path.basename(path)} Set') | |
plt.xticks(rotation=45) | |
plt.tight_layout() | |
st.pyplot(plt) | |
# Main Streamlit app | |
def main(): | |
st.title('Dataset Visualization') | |
dataset_path = "Felidae/" | |
train_path = "train/" | |
test_path = "test/" | |
val_path = "val/" | |
# Visualize each path | |
if st.button('Visualize'): | |
if os.path.exists(dataset_path): | |
st.subheader('Dataset Path Visualization') | |
visual_path(dataset_path) | |
else: | |
st.error('Dataset path does not exist!') | |
if os.path.exists(train_path): | |
st.subheader('Train Path Visualization') | |
visual_path(train_path) | |
else: | |
st.error('Train path does not exist!') | |
if os.path.exists(test_path): | |
st.subheader('Test Path Visualization') | |
visual_path(test_path) | |
else: | |
st.error('Test path does not exist!') | |
if os.path.exists(val_path): | |
st.subheader('Validation Path Visualization') | |
visual_path(val_path) | |
else: | |
st.error('Validation path does not exist!') | |
if __name__ == '__main__': | |
main() | |