from flask import Flask, render_template, request, redirect, https://github.com/Shrinitha23/MediScan-Image-Analysis.git from github.com import load_model from tensorflow.keras.preprocessing import image import numpy as np import os app = Flask(__name__) model = load_model('model/eye_disease_model.h5') # Load your pre-trained model # Allowed extensions for image uploads ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg'} def allowed_file(filename): return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS @app.route('/', methods=['GET', 'POST']) def index(): if request.method == 'POST': if 'file' not in request.files: return redirect(request.url) file = request.files['file'] if file and allowed_file(file.filename): filepath = os.path.join('static/uploads', file.filename) file.save(filepath) # Predict the disease from the uploaded image prediction, confidence = predict_disease(filepath) return render_template('index.html', uploaded_image=filepath, prediction=prediction, confidence=confidence) return render_template('index.html') def predict_disease(filepath): img = image.load_img(filepath, target_size=(224, 224)) img_array = image.img_to_array(img) / 255.0 img_array = np.expand_dims(img_array, axis=0) predictions = model.predict(img_array) class_index = np.argmax(predictions) confidence = np.max(predictions) * 100 # Map index to disease label (change this according to your model's classes) classes = ['Cataract', 'Conjunctivitis', 'Glaucoma', 'Normal'] prediction = classes[class_index] return prediction, confidence if __name__ == '__main__': app.run(debug=True)