Spaces:
Runtime error
Runtime error
| import os | |
| import streamlit as st | |
| from PIL import Image | |
| from tensorflow.keras.models import load_model | |
| from tensorflow.keras.preprocessing.image import load_img | |
| from tensorflow.keras.preprocessing.image import img_to_array | |
| # IMG_PATH = 'imgs' | |
| def main(): | |
| st.title("AI MNIST") | |
| file = st.file_uploader('η»εγγ’γγγγΌγγγ¦γγ γγ.', type=['jpg', 'jpeg', 'png']) | |
| if file: | |
| st.markdown(f'{file.name} γγ’γγγγΌγγγΎγγ.') | |
| img_path = os.path.join(file.name) | |
| # η»εγδΏεγγ | |
| with open(img_path, 'wb') as f: | |
| f.write(file.read()) | |
| # δΏεγγη»εγ葨瀺 | |
| img = Image.open(img_path) | |
| st.image(img) | |
| # η»εγArrayε½’εΌγ«ε€ζ | |
| img = load_img(img_path, target_size=(28, 28), color_mode = 'grayscale') | |
| img_array = img_to_array(img) | |
| img_array = img_array.reshape((1, 28, 28)) | |
| img_array = img_array/255 | |
| # δΏεγγγ’γγ«γεΌγ³εΊγ | |
| model_path = os.path.join('model.h5') | |
| model = load_model(model_path) | |
| result = model.predict(img_array) | |
| prediction = result.argmax() | |
| st.text_area("γγγ―:", prediction, height=20) | |
| if __name__ == '__main__': | |
| main() |