Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import numpy as np
|
3 |
+
import matplotlib.pyplot as plt
|
4 |
+
from PIL import Image
|
5 |
+
import io
|
6 |
+
|
7 |
+
st.set_page_config(page_title="MNIST Pixel Visualizer", layout="wide")
|
8 |
+
st.title("๐งฎ MNIST ํฝ์
๊ฐ ์๊ฐํ ๋ฐ๋ชจ")
|
9 |
+
|
10 |
+
st.markdown("""
|
11 |
+
์ฌ์ฉ์๊ฐ ์
๋ก๋ํ ํ๋ฐฑ ์ด๋ฏธ์ง๋ฅผ ํฝ์
๊ฐ์ผ๋ก ์๊ฐํํฉ๋๋ค.
|
12 |
+
|
13 |
+
- ํฝ์
๊ฐ์ 0~255 ๋ฒ์์ด๋ฉฐ, ๋ฐ๊ธฐ์ ๋ฐ๋ผ ํฐ์(255), ๊ฒ์์(0)์ผ๋ก ํ์๋ฉ๋๋ค.
|
14 |
+
- ํฝ์
๊ฐ๋ ์ด๋ฏธ์ง ์์ ์ซ์๋ก ํ์๋ฉ๋๋ค.
|
15 |
+
|
16 |
+
์์ MNIST ์ด๋ฏธ์ง๋ ํจ๊ป ์ ๊ณตํฉ๋๋ค.
|
17 |
+
""")
|
18 |
+
|
19 |
+
# ์์ ์ด๋ฏธ์ง ๋ก๋ (MNIST)
|
20 |
+
from tensorflow.keras.datasets import mnist
|
21 |
+
(x_train, y_train), _ = mnist.load_data()
|
22 |
+
|
23 |
+
example_index = st.selectbox("์์ ์ด๋ฏธ์ง ์ ํ (MNIST)", list(range(10)), format_func=lambda x: f"Label: {y_train[x]}")
|
24 |
+
example_image = x_train[example_index]
|
25 |
+
|
26 |
+
col1, col2 = st.columns(2)
|
27 |
+
|
28 |
+
with col1:
|
29 |
+
st.subheader("1. ์ด๋ฏธ์ง ์
๋ก๋ or ์์ ์ด๋ฏธ์ง ์ฌ์ฉ")
|
30 |
+
uploaded_file = st.file_uploader("ํ๋ฐฑ ์ด๋ฏธ์ง ํ์ผ ์
๋ก๋ (28x28 ๋๋ ๋ ํฐ ์ด๋ฏธ์ง)", type=["png", "jpg", "jpeg"])
|
31 |
+
|
32 |
+
if uploaded_file is not None:
|
33 |
+
image = Image.open(uploaded_file).convert('L') # ํ๋ฐฑ์ผ๋ก ๋ณํ
|
34 |
+
image = np.array(image)
|
35 |
+
st.image(image, caption="์
๋ก๋๋ ์ด๋ฏธ์ง", use_column_width=True)
|
36 |
+
else:
|
37 |
+
image = example_image
|
38 |
+
st.image(image, caption=f"์์ ์ด๋ฏธ์ง (Label: {y_train[example_index]})", use_column_width=True)
|
39 |
+
|
40 |
+
with col2:
|
41 |
+
st.subheader("2. ํฝ์
๊ฐ ์๊ฐํ ๊ฒฐ๊ณผ")
|
42 |
+
fig, ax = plt.subplots(figsize=(6, 6))
|
43 |
+
ax.imshow(image, cmap='gray', vmin=0, vmax=255)
|
44 |
+
ax.set_xticks([])
|
45 |
+
ax.set_yticks([])
|
46 |
+
|
47 |
+
h, w = image.shape
|
48 |
+
for i in range(h):
|
49 |
+
for j in range(w):
|
50 |
+
val = image[i, j]
|
51 |
+
color = 'white' if val < 128 else 'black'
|
52 |
+
ax.text(j, i, str(val), ha='center', va='center', fontsize=6, color=color)
|
53 |
+
|
54 |
+
st.pyplot(fig)
|
55 |
+
|
56 |
+
st.markdown("""
|
57 |
+
---
|
58 |
+
๐จโ๐ป ๋ง๋ ์ฌ๋: ์ ์ํ | Upstage AI Edu
|
59 |
+
๐ก ๋ฐ๋ชจ ๋ชฉ์ : ํฝ์
๋จ์๋ก ์ด๋ฏธ์ง ๋ฐ์ดํฐ๋ฅผ ์ดํดํ๊ณ ์๊ฐํํ๋ ๊ฒฝํ์ ์ ๊ณตํฉ๋๋ค.
|
60 |
+
""")
|