Yescia commited on
Commit
02432dd
ยท
verified ยท
1 Parent(s): 3643486

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -0
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
+ """)