Spaces:
Sleeping
Sleeping
Commit
Β·
764ea86
1
Parent(s):
71c93a1
First Commit
Browse files- app.py +45 -0
- model.h5 +3 -0
- requirements.txt +3 -0
- 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
![]() |