tensorflow_pract / streamlit.py
bracken576
updated streamlit and requirements
1f85d6b
#%%
import plotly.express as px
import numpy as np
import pandas as pd
import streamlit as st
import tensorflow as tf
from keras.preprocessing import image
#docker build -t streamlit
# docker compose up
image_file_prev = ""
model = tf.keras.models.load_model("cnnBoneFracRec.h5")
st.markdown("## Bone Fracture Recognition with TensorFlow")
image_file = st.file_uploader("Upload X-Ray Image", type=['png', 'jpg'])
if image_file_prev != image_file and image_file:
st.image(image_file, caption=None, width=None, use_column_width=None, clamp=False, channels="RGB", output_format="auto")
image_file_prev = image_file
target_names = ['Non-Fractured', 'Fractured']
temp_img = image.load_img(image_file, target_size=(100, 100))
x = image.img_to_array(temp_img)
x = np.expand_dims(x, axis=0)
images = np.vstack([x])
prediction = np.argmax(model.predict(images), axis=1)
prediction_str = target_names[prediction.item()]
if prediction_str:
st.markdown(f"##### Prediction : {prediction_str}")