bhanusAI commited on
Commit
28c7dea
·
verified ·
1 Parent(s): 7684557

Upload 4 files

Browse files
app.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import pickle
3
+ import numpy as np
4
+ import tensorflow as tf
5
+ from flask import Flask, render_template, request
6
+ from PIL import Image
7
+ import keras
8
+ from keras.applications.vgg16 import preprocess_input
9
+ from tensorflow.keras.applications.vgg16 import preprocess_input
10
+ import gradio as gr
11
+
12
+ def model(img):
13
+ model_dir = 'cataract'
14
+ class_names = ['Normal', 'Cataract'] # Cataract class labels
15
+ channel='RGB'
16
+ selected_model = 'cataract'
17
+
18
+ architecture_path = os.path.join('models',model_dir, f'model_architecture_{selected_model}.pkl')
19
+ weights_path = os.path.join('models',model_dir, f'model_weights_{selected_model}.pkl')
20
+
21
+ with open(architecture_path, 'rb') as f:
22
+ loaded_model_architecture = pickle.load(f)
23
+
24
+ with open(weights_path, 'rb') as f:
25
+ loaded_model_weights = pickle.load(f)
26
+
27
+ # Create the model using the loaded architecture
28
+ loaded_model = tf.keras.models.model_from_json(loaded_model_architecture)
29
+
30
+ # Set the loaded weights to the model
31
+ loaded_model.set_weights(loaded_model_weights)
32
+
33
+ # Load and preprocess the image
34
+ try:
35
+ image = Image.open(img).convert(channel).resize((256, 256))
36
+ except:
37
+ print("ERROR")
38
+ return "ERROR"
39
+ x = np.array(image)
40
+ x = np.expand_dims(x, axis=0)
41
+ x = preprocess_input(x)
42
+
43
+ # Make predictions
44
+ predictions = loaded_model.predict(x)
45
+ print(predictions)
46
+
47
+ predicted_class_index = 1 if (predictions[0]>0.5) else 0
48
+ print(predicted_class_index)
49
+
50
+ predicted_class_label = class_names[predicted_class_index]
51
+
52
+ return predicted_class_label
53
+
54
+ cataract_app = gr.Interface(model,gr.Image())
55
+
56
+ cataract_app.launch(share=True)
models/cataract/model_architecture_cataract.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fcfd80746e9a871e8198d36bd067c647449f7e914d382c5f37b287d14c783718
3
+ size 20468
models/cataract/model_weights_cataract.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4c7803f31bae8513825e98ac5a13dc10dd764b1c0e276fd73bde04fba9be4b86
3
+ size 80230146
requirements.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ tensorflow==2.16.1
2
+ keras==3.3.3
3
+ numpy==1.26.4
4
+ matplotlib==3.7.5
5
+ pillow==9.5.0
6
+ # glob
7
+ flask
8
+ # python==3.10
9
+ gradio