pax-dare-lab commited on
Commit
764ea86
Β·
1 Parent(s): 71c93a1

First Commit

Browse files
Files changed (4) hide show
  1. app.py +45 -0
  2. model.h5 +3 -0
  3. requirements.txt +3 -0
  4. unknown_mnist.png +0 -0
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ import streamlit as st
4
+ from PIL import Image
5
+
6
+ from tensorflow.keras.models import load_model
7
+ from tensorflow.keras.preprocessing.image import load_img
8
+ from tensorflow.keras.preprocessing.image import img_to_array
9
+
10
+ # IMG_PATH = 'imgs'
11
+
12
+ def main():
13
+
14
+ st.title("AI MNIST")
15
+ file = st.file_uploader('画像ををップロードしてください.', type=['jpg', 'jpeg', 'png'])
16
+
17
+ if file:
18
+ st.markdown(f'{file.name} γ‚’γ‚’γƒƒγƒ—γƒ­γƒΌγƒ‰γ—γΎγ—γŸ.')
19
+
20
+ img_path = os.path.join(file.name)
21
+ # η”»εƒγ‚’δΏε­˜γ™γ‚‹
22
+ with open(img_path, 'wb') as f:
23
+ f.write(file.read())
24
+
25
+ # δΏε­˜γ—γŸη”»εƒγ‚’θ‘¨η€Ί
26
+ img = Image.open(img_path)
27
+ st.image(img)
28
+
29
+ # 画像をArray归式に倉換
30
+ img = load_img(img_path, target_size=(28, 28), color_mode = 'grayscale')
31
+ img_array = img_to_array(img)
32
+ img_array = img_array.reshape((1, 28, 28))
33
+ img_array = img_array/255
34
+
35
+ # δΏε­˜γ—γŸγƒ’γƒ‡γƒ«γ‚’ε‘Όγ³ε‡Ίγ—
36
+ model_path = os.path.join('model.h5')
37
+ model = load_model(model_path)
38
+ result = model.predict(img_array)
39
+
40
+ prediction = result.argmax()
41
+
42
+ st.text_area("γ“γ‚Œγ―:", prediction, height=20)
43
+
44
+ if __name__ == '__main__':
45
+ main()
model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:617a488b8aac62019e23187e53fb47d98378670336822e634ee6bff39ecc625f
3
+ size 331856
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ streamlit==1.34.0
2
+ tensorflow==2.12.0
3
+ Pillow==9.5.0
unknown_mnist.png ADDED