File size: 1,561 Bytes
c2f23e8
 
 
 
056b6e5
c2f23e8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
46
47
48
49
50
51
52
from keras.models import load_model
import cv2
from tensorflow.keras.preprocessing.image import ImageDataGenerator
import gradio as gr
import numpy as np

heart_model=load_model('Chicken_Heart_model.h5',compile=True)
class_name={0:'Dilation(eccentric)',1:'Hepatoma',2:'Hypertrophy(concentric)',3:'Hypertrophy(physiological)',4:'Infraction Damage',5:'Normal'}

def Heart_Disease_prediction(img):
  img = img.reshape((1, img.shape[0], img.shape[1], img.shape[2]))

  # Create the data generator with desired properties
  datagen = ImageDataGenerator(
    rotation_range=30,
    width_shift_range=0.1,
    height_shift_range=0.1,
    shear_range=0.1,
    zoom_range=0.1,
    horizontal_flip=True,
    fill_mode="nearest",
  )
  # Generate a batch of augmented images (contains only the single image) 
  augmented_images = datagen.flow(img, batch_size=1)
  # Get the first (and only) augmented image from the batch
  augmented_img = next(augmented_images)[0]
  img=cv2.resize(augmented_img.astype(np.uint8),(128,128))
  class_no=heart_model.predict(img.reshape(1,128,128,3)).argmax()
  name=class_name.get(class_no) 
  return name 


interface=gr.Interface(fn=Heart_Disease_prediction,inputs='image',outputs=[gr.components.Textbox(label='Disease Name')],
                      examples=[['Image1.PNG'],['Image2.PNG'],['Image3.PNG'],['Image4.PNG'],
                                ['Image5.PNG'],['Image6.PNG'],['Image7.PNG'],['Image8.PNG'],
                                ['Image9.PNG'],['Image10.PNG'],['Image11.PNG']])

interface.launch(debug=True)