Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from keras.models import load_model
|
| 2 |
+
import cv2
|
| 3 |
+
from tensorflow.keras.preprocessing.image import ImageDataGenerator
|
| 4 |
+
import gradio as gr
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
heart_model=load_model('Chicken_Heart_model.h5',compile=True)
|
| 8 |
+
class_name={0:'Dilation(eccentric)',1:'Hepatoma',2:'Hypertrophy(concentric)',3:'Hypertrophy(physiological)',4:'Infraction Damage',5:'Normal'}
|
| 9 |
+
|
| 10 |
+
def Heart_Disease_prediction(img):
|
| 11 |
+
img = img.reshape((1, img.shape[0], img.shape[1], img.shape[2]))
|
| 12 |
+
|
| 13 |
+
# Create the data generator with desired properties
|
| 14 |
+
datagen = ImageDataGenerator(
|
| 15 |
+
rotation_range=30,
|
| 16 |
+
width_shift_range=0.1,
|
| 17 |
+
height_shift_range=0.1,
|
| 18 |
+
shear_range=0.1,
|
| 19 |
+
zoom_range=0.1,
|
| 20 |
+
horizontal_flip=True,
|
| 21 |
+
fill_mode="nearest",
|
| 22 |
+
)
|
| 23 |
+
# Generate a batch of augmented images (contains only the single image)
|
| 24 |
+
augmented_images = datagen.flow(img, batch_size=1)
|
| 25 |
+
# Get the first (and only) augmented image from the batch
|
| 26 |
+
augmented_img = next(augmented_images)[0]
|
| 27 |
+
img=cv2.resize(augmented_img.astype(np.uint8),(128,128))
|
| 28 |
+
class_no=heart_model.predict(img.reshape(1,128,128,3)).argmax()
|
| 29 |
+
name=class_name.get(class_no)
|
| 30 |
+
return name
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
interface=gr.Interface(fn=Heart_Disease_prediction,inputs='image',outputs=[gr.components.Textbox(label='Disease Name')],
|
| 34 |
+
examples=[['Image1.PNG'],['Image2.PNG'],['Image3.PNG'],['Image4.PNG'],
|
| 35 |
+
['Image5.PNG'],['Image6.PNG'],['Image7.PNG'],['Image8.PNG'],
|
| 36 |
+
['Image9.PNG'],['Image10.PNG'],['Image11.PNG']])
|
| 37 |
+
|
| 38 |
+
interface.launch(debug=True)
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
|