File size: 4,523 Bytes
178b852
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
from keras.models import load_model
import cv2
from tensorflow.keras.preprocessing.image import ImageDataGenerator
import gradio as gr
import numpy as np


my_model=load_model('Liver_model.h5',compile=True)
heart_model=load_model('Chicken_Heart_model.h5',compile=True)
lu_model=load_model('Lungs_model.h5',compile=True)
auth_model=load_model('post_auth_model.h5',compile=True)
heart_class_name={0:'Dilation(eccentric)',1:'Hepatoma',2:'Hypertrophy(concentric)',3:'Hypertrophy(physiological)',4:'Infraction Damage',5:'Normal'}
heart_result={0:'Critical',1:'Critical',2:'Critical',3:'Critical',4:'Critical',5:'Normal'}
heart_recommend={0:'panadol',1:'peracetamol',2:'ponston',4:'brofon',5:'No Need'}

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="Heart Disease Class Name: "+""+heart_class_name.get(class_no) 
  result="Heart Disease result: "+""+heart_result.get(class_no)
  recommend="Heart Medicine Recommend: "+""+heart_recommend.get(class_no)
  return name,result,recommend

liver_class_num={0:'Healthy',1:'Un-Healthy'}
liver_result={0:'Normal',1:'Critical'}
liver_recommend={0:'No need Medicine',1:'Panadol'}
def Liver_Predict(Image):
  Image=cv2.resize(Image,(224,224))
  class_no=my_model.predict(Image.reshape(1,224,224,3)).argmax()
  class_name="Liver Class Name: "+""+liver_class_num.get(class_no)
  liver_class_result="Liver Class Result: "+""+liver_result.get(class_no)
  liver_class_recommend="Liver Class Recommend: "+""+liver_recommend.get(class_no)
  return class_name,liver_class_result,liver_class_recommend



lung_classes={0:'Lungs of infected chickens showing congestion, hemorrhage and consolidation with traces of fibrin at 24 hpi (hours post-infection)',
              1:'gradual paleness and reduction in size of lungs at 2 dpi (days post-infection)',
              2:'gradual paleness and reduction in size of lung at 3 dpi (days post-infection)',
              3:'severe congestion, hemorrhage, and gradual shrinking of lungs at 4 dpi (days post-infection)',
              4:'severe congestion, hemorrhage, and gradual shrinking of lungs at 5 dpi (days post-infection)'}
lung_result={0:'critical',1:'critical',2:'critical',3:'critical',4:'critical'}
lung_recommend={0:'panadol',1:'peracetamol',2:'ponston',4:'brofon'}

def Lungs_predict(image):
  image=cv2.resize(image,(224,224))
  lung_no=lu_model.predict(image.reshape(1,224,224,3)).argmax()
  lung_disease_name="Lung Disease Name: "+""+lung_classes.get(lung_no)
  lung_r="Lung result: "+""+lung_result.get(lung_no)
  lung_re="Lung recommendation: "+""+lung_recommend.get(lung_no)
  return lung_disease_name,lung_r,lung_re
  

def main(Image):
    img=cv2.resize(Image,(224,224))
    indx=auth_model.predict(img.reshape(1,224,224,3)).argmax()
    if indx==0:
        Name='Unkown'
        result='N/A'
        recommend='N/A'
        return Name,result,recommend,Name,result,recommend,Name,result,recommend
    else:
        heart_n,heart_r,heart_re=Heart_Disease_prediction(Image)
        liver_name,liver_r,liver_re=Liver_Predict(Image)
        lung_d,lung_r,lung_re=Lungs_predict(Image)
        return heart_n,heart_r,heart_re,liver_name,liver_r,liver_re,lung_d,lung_r,lung_re

interface=gr.Interface(fn=main,inputs='image',outputs=[gr.components.Textbox(label="Heart Disease Name"),gr.components.Textbox(label="Heart result Name"),gr.components.Textbox(label="Heart recommend"),
                                                         gr.components.Textbox(label="Liver Disease Name"),gr.components.Textbox(label="liver result Name"),gr.components.Textbox(label="Liver recommend"),
                                                         gr.components.Textbox(label="Lung Disease Name"),gr.components.Textbox(label="Lung result Name"),gr.components.Textbox(label="Lung recommend")],
                       title="Postmortem") 
interface.launch(debug=True)