import os from flask import Flask, request, render_template from tensorflow.keras.models import load_model from tensorflow.keras.preprocessing import image import numpy as np app = Flask(__name__) # Load the trained model model = load_model('bone_fracture/bone_model.h5') # Update with your model's file path # Define class labels class_labels = ['Not Fractured', 'Fractured'] @app.route('/', methods=['GET', 'POST']) def index(): if request.method == 'POST': # Get the uploaded file from the form file = request.files['file'] if file: # Save the file temporarily temp_path = 'temp.jpg' file.save(temp_path) # Load and preprocess the image img = image.load_img(temp_path, 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 a prediction prediction = model.predict(img_array) predicted_class = int(np.round(prediction)[0][0]) predicted_label = class_labels[predicted_class] # Delete the temporary file os.remove(temp_path) return render_template('result.html', prediction=predicted_label) return render_template('index.html') if __name__ == '__main__': app.run(debug=True)