Spaces:
Runtime error
Runtime error
| import streamlit as st | |
| import tensorflow as tf | |
| from tensorflow.keras.preprocessing import image | |
| import numpy as np | |
| # Load the pre-trained model | |
| model = tf.keras.models.load_model('model.h5') | |
| # Define class labels | |
| class_labels = ['Fractured', ' Not Fractured'] | |
| # Streamlit app | |
| st.title('Bone Fracture Detection App') | |
| # Upload an image for prediction | |
| uploaded_image = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"]) | |
| if uploaded_image is not None: | |
| # Display the uploaded image | |
| st.image(uploaded_image, caption='Uploaded Image', use_column_width=True) | |
| # Preprocess the image for model prediction | |
| img = image.load_img(uploaded_image, target_size=(224, 224)) | |
| img_array = image.img_to_array(img) | |
| img_array = np.expand_dims(img_array, axis=0) | |
| img_array /= 255.0 | |
| # Make prediction | |
| prediction = model.predict(img_array) | |
| predicted_class = int(np.round(prediction)[0][0]) | |
| # Display the prediction result | |
| st.write(f"Predicted class: {class_labels[predicted_class]}") | |
| st.write(f"Confidence: {prediction[0][0] * 100:.2f}%") | |