Spaces:
Runtime error
Runtime error
Kota Takahashi
commited on
Commit
·
fbb261a
1
Parent(s):
c04eaa8
ファーストコミット
Browse files- .gitignore +37 -0
- app.py +44 -0
- model.h5 +3 -0
- requirements.txt +3 -0
.gitignore
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Byte-compiled / optimized / DLL files
|
2 |
+
__pycache__/
|
3 |
+
*.py[cod]
|
4 |
+
*$py.class
|
5 |
+
|
6 |
+
# Caches and logs
|
7 |
+
*.log
|
8 |
+
logs/
|
9 |
+
*.cache/
|
10 |
+
|
11 |
+
# Environment variables
|
12 |
+
.env
|
13 |
+
|
14 |
+
# Static files (usually collected by Django's collectstatic)
|
15 |
+
/static/
|
16 |
+
|
17 |
+
# Media files
|
18 |
+
/media/
|
19 |
+
|
20 |
+
# Database
|
21 |
+
*.sqlite3
|
22 |
+
|
23 |
+
# IDE specific files
|
24 |
+
.idea/
|
25 |
+
.vscode/
|
26 |
+
|
27 |
+
# Dependency directories
|
28 |
+
venv/
|
29 |
+
env/
|
30 |
+
|
31 |
+
# Compiled Python files
|
32 |
+
*.pyc
|
33 |
+
*.pyo
|
34 |
+
*.pyd
|
35 |
+
|
36 |
+
# macOS
|
37 |
+
.DS_Store
|
app.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
|
11 |
+
def main():
|
12 |
+
st.title("AI MNIST")
|
13 |
+
file = st.file_uploader('画像をアップロードしてください.', type=['jpg', 'jpeg', 'png'])
|
14 |
+
|
15 |
+
if file:
|
16 |
+
st.markdown(f'{file.name} をアップロードしました.')
|
17 |
+
|
18 |
+
img_path = os.path.join(file.name)
|
19 |
+
# 画像を保存する
|
20 |
+
with open(img_path, 'wb') as f:
|
21 |
+
f.write(file.read())
|
22 |
+
|
23 |
+
# 保存した画像を表示
|
24 |
+
img = Image.open(img_path)
|
25 |
+
st.image(img)
|
26 |
+
|
27 |
+
# 画像をArray形式に変換
|
28 |
+
img = load_img(img_path, target_size=(28, 28), color_mode='grayscale')
|
29 |
+
img_array = img_to_array(img)
|
30 |
+
img_array = img_array.reshape((1, 28, 28))
|
31 |
+
img_array = img_array / 255
|
32 |
+
|
33 |
+
# 保存したモデルを呼び出し
|
34 |
+
model_path = os.path.join('model.h5')
|
35 |
+
model = load_model(model_path)
|
36 |
+
result = model.predict(img_array)
|
37 |
+
|
38 |
+
prediction = result.argmax()
|
39 |
+
|
40 |
+
st.text_area("これは:", prediction, height=20)
|
41 |
+
|
42 |
+
|
43 |
+
if __name__ == '__main__':
|
44 |
+
main()
|
model.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a281565a6a469e127760f43b6a50ecc8a890f1a749a869e14fdee2fd9b2441bf
|
3 |
+
size 330824
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
streamlit==1.34.0
|
2 |
+
tensorflow==2.12.0
|
3 |
+
Pillow==9.5.0
|