File size: 1,431 Bytes
378363a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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)