import streamlit as st import numpy as np import matplotlib.pyplot as plt from PIL import Image import io st.set_page_config(page_title="MNIST Pixel Visualizer", layout="wide") st.title("🧮 MNIST í”Ŋ녀氒 ė‹œę°í™” 데ëǍ") st.markdown(""" ė‚ŦėšŠėžę°€ ė—…ëĄœë“œí•œ 흑백 ė´ë¯¸ė§€ëĨŧ í”Ŋ녀氒ėœŧ로 ė‹œę°í™”í•Šë‹ˆë‹¤. - í”Ŋė…€ę°’ė€ 0~255 ë˛”ėœ„ė´ëŠ°, ë°ę¸°ė— 따ëŧ í°ėƒ‰(255), ę˛€ė€ėƒ‰(0)ėœŧ로 í‘œė‹œëŠë‹ˆë‹¤. - í”Ŋė…€ę°’ë„ ė´ë¯¸ė§€ ėœ„ė— ėˆĢėžëĄœ í‘œė‹œëŠë‹ˆë‹¤. ė˜ˆė‹œ MNIST ė´ë¯¸ė§€ë„ 함ęģ˜ ė œęŗĩ합니다. """) # ė˜ˆė‹œ ė´ë¯¸ė§€ 로드 (MNIST) from tensorflow.keras.datasets import mnist (x_train, y_train), _ = mnist.load_data() example_index = st.selectbox("ė˜ˆė‹œ ė´ë¯¸ė§€ ė„ íƒ (MNIST)", list(range(10)), format_func=lambda x: f"Label: {y_train[x]}") example_image = x_train[example_index] col1, col2 = st.columns(2) with col1: st.subheader("1. ė´ë¯¸ė§€ ė—…ëĄœë“œ or ė˜ˆė‹œ ė´ë¯¸ė§€ ė‚ŦėšŠ") uploaded_file = st.file_uploader("흑백 ė´ë¯¸ė§€ 파ėŧ ė—…ëĄœë“œ (28x28 또는 더 큰 ė´ë¯¸ė§€)", type=["png", "jpg", "jpeg"]) if uploaded_file is not None: image = Image.open(uploaded_file).convert('L') # 흑백ėœŧ로 ëŗ€í™˜ image = np.array(image) st.image(image, caption="ė—…ëĄœë“œëœ ė´ë¯¸ė§€", use_container_width=True) else: image = example_image st.image(image, caption=f"ė˜ˆė‹œ ė´ë¯¸ė§€ (Label: {y_train[example_index]})", use_container_width=True) with col2: st.subheader("2. í”Ŋ녀氒 ė‹œę°í™” 결ęŗŧ") fig, ax = plt.subplots(figsize=(6, 6)) ax.imshow(image, cmap='gray', vmin=0, vmax=255) ax.set_xticks([]) ax.set_yticks([]) h, w = image.shape for i in range(h): for j in range(w): val = image[i, j] color = 'white' if val < 128 else 'black' ax.text(j, i, str(val), ha='center', va='center', fontsize=6, color=color) st.pyplot(fig) st.markdown(""" --- 👨‍đŸ’ģ 만든 ė‚Ŧ람: ė „ė˜í›ˆ | Upstage | AI Edu """)