File size: 1,080 Bytes
4b2ef4b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ba0a099
4b2ef4b
 
 
 
 
 
049ab8e
 
4b2ef4b
 
 
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
import gradio as gr
from fastai.vision.all import load_learner
from fastai import *
import torch
import os
from PIL import Image

model_path = 'multi_target_resnet18.pkl'
model = load_learner(model_path)

def result(path):    
    pred,_,probability = model.predict(path)
    arr = ['Name','Status','Disease Name']
    vals = ['', '', '']

    names = ['Maple', 'Banana', 'Cucumber', 'Mango', 'Maple', 'Pepper', 'Rose', 'Tomato']
    status = ['diseased', 'no disease found']

    for x in pred:
      if x in names:
        vals[0] = x.capitalize()
      elif x in status:
        vals[1] = x.capitalize()
      elif x == 'healthy':
        vals[2] = 'None'
      else:
        vals[2] = x.capitalize()
      
    return f'{arr[0]}:\t{vals[0]}\n{arr[1]}:\t{vals[1]}\n{arr[2]}:\t{vals[2]}\n'

path = 'test-images/'

image_path = []

for i in os.listdir(path):
  image_path.append(path+i) 

image = gr.components.Image(shape =(300,300))
label = gr.components.Label()

iface = gr.Interface(fn=result, inputs=image, outputs='text', examples = image_path)
iface.launch(inline = False)