|
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__) |
|
|
|
|
|
model = load_model('bone_fracture/bone_model.h5') |
|
|
|
|
|
class_labels = ['Not Fractured', 'Fractured'] |
|
|
|
@app.route('/', methods=['GET', 'POST']) |
|
def index(): |
|
if request.method == 'POST': |
|
|
|
file = request.files['file'] |
|
if file: |
|
|
|
temp_path = 'temp.jpg' |
|
file.save(temp_path) |
|
|
|
|
|
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 |
|
|
|
|
|
prediction = model.predict(img_array) |
|
predicted_class = int(np.round(prediction)[0][0]) |
|
predicted_label = class_labels[predicted_class] |
|
|
|
|
|
os.remove(temp_path) |
|
|
|
return render_template('result.html', prediction=predicted_label) |
|
|
|
return render_template('index.html') |
|
|
|
if __name__ == '__main__': |
|
app.run(debug=True) |
|
|