File size: 1,418 Bytes
59b0f06
 
a2954e9
59b0f06
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import keras
from keras.models import load_model
import gradio as gr
import cv2

my_model = load_model('Final_Chicken_disease_model.h5', compile=True)
auth_model = load_model('auth_model.h5', compile=True)
name_disease = {0: 'Coccidiosis', 1: 'Healthy', 2: 'New Castle Disease', 3: 'Salmonella'}
result = {0: 'Critical', 1: 'No issue', 2: 'Critical', 3: 'Critical'}
recommend = {0: 'Panadol', 1: 'You have no need of Medicine', 2: 'Percetamol', 3: 'Ponston'}


def predict(image):
    image_check = cv2.resize(image, (224, 224))
    indx = auth_model.predict(image_check.reshape(1, 224, 224, 3)).argmax()
    if indx == 0:
        image = cv2.resize(image, (224, 224))
        indx = my_model.predict(image.reshape(1, 224, 224, 3)).argmax()
        name = name_disease.get(indx)
        status = result.get(indx)
        recom = recommend.get(indx)
        return name, status, recom
    else:
        name = 'Unknown Image'
        status = 'N/A'
        recom = 'N/A'
        return name, status, recom


interface = gr.Interface(fn=predict, inputs=[gr.Image(label='upload Image')],
                         outputs=[gr.components.Textbox(label="Disease Name"),
                                  gr.components.Textbox(label="result"),
                                  gr.components.Textbox(label='Medicine Recommend')],
                         examples=[['disease.jpg'], ['ncd.jpg']])
interface.launch(debug=True)